YesSql.Tests.CoreTests.AlteringDocumentShouldUpdateReducedIndex C# (CSharp) Method

AlteringDocumentShouldUpdateReducedIndex() private method

private AlteringDocumentShouldUpdateReducedIndex ( ) : Task
return Task
        public async Task AlteringDocumentShouldUpdateReducedIndex()
        {
            _store.RegisterIndexes<ArticleIndexProvider>();

            using (var session = _store.CreateSession())
            {
                var dates = new[]
                {
                    new DateTime(2011, 11, 1),
                    new DateTime(2011, 11, 2),
                    new DateTime(2011, 11, 2),
                };

                var articles = dates.Select(x => new Article
                {
                    PublishedUtc = x
                });

                foreach (var article in articles)
                {
                    session.Save(article);
                }

            }

            using (var session = _store.CreateSession())
            {
                // There should be 3 articles
                Assert.Equal(3, await session.QueryAsync().For<Article>().Count());

                // There should be 2 groups
                Assert.Equal(2, await session.QueryIndexAsync<ArticlesByDay>().Count());
            }

            // Deleting a document which was the only one in the reduced group
            using (var session = _store.CreateSession())
            {
                var article = await session.QueryAsync<Article, ArticlesByDay>()
                    .Where(b => b.DayOfYear == new DateTime(2011, 11, 1).DayOfYear)
                    .FirstOrDefault();

                Assert.NotNull(article);
                session.Delete(article);
            }

            // Ensure the document and its index have been deleted
            using (var session = _store.CreateSession())
            {
                // There should be 1 article
                Assert.Equal(2, await session.QueryAsync<Article>().Count());

                // There should be 1 group
                Assert.Equal(1, await session.QueryIndexAsync<ArticlesByDay>().Count());
            }
        }
CoreTests