Example #1
0
        public async Task GetNewsFromCollection_ShouldFetchCollectionNews()
        {
            // Arrange
            var feeds = Create.Many(Create.RSSFeed).Cast <Feed>().Take(2).ToArray();

            FeedlerContext.Feeds.AddRange(feeds);

            var collection = Create.Collection(feeds);

            FeedlerContext.Collections.Add(collection);

            await FeedlerContext.SaveChangesAsync();

            var itemsByFeed = new Dictionary <Feed, Item[]>();

            foreach (var feed in feeds)
            {
                itemsByFeed[feed] = Create.Many(Create.Item).Take(3).ToArray();
                FeedLoader.LoadItemsAsync(feed).Returns(itemsByFeed[feed]);
            }

            // Act
            var response = await Client.GetAsync($"collections/{collection.Id}/news");

            // Assert: response
            await HttpAssert.IsSuccessResponseAsync(response);

            var responseJson = await response.Content.ReadAsAsync <JArray>();

            Assert.Equal(
                expected: itemsByFeed.Values.Flatten().Select(i => new { Title = i.Title }).ToHashSet(),
                actual: responseJson.Select(j => new { Title = j.String("title") }).ToHashSet()
                );
        }
Example #2
0
        public async Task GetNewsFromCollection_ShouldLoadNewsFromCache_IfRequestIsCached()
        {
            // Arrange
            var feed = Create.RSSFeed();

            FeedlerContext.Feeds.Add(feed);

            var collection = Create.Collection(feed);

            FeedlerContext.Collections.Add(collection);

            await FeedlerContext.SaveChangesAsync();

            var items = Create.Many(Create.Item).Take(5).ToArray();

            FeedLoader.LoadItemsAsync(feed).Returns(items);

            // Act
            var response1 = await Client.GetAsync($"collections/{collection.Id}/news");

            await HttpAssert.IsSuccessResponseAsync(response1);

            FeedLoader.ClearReceivedCalls();

            var response2 = await Client.GetAsync($"collections/{collection.Id}/news");

            await HttpAssert.IsSuccessResponseAsync(response2);

            // Assert: calls
            await FeedLoader.DidNotReceive().LoadItemsAsync(feed);
        }