public void GetStoriesNotContained_AllCached_ReturnsEmpty()
        {
            var story_1 = new Item
            {
                Id = 1,
                Title = "Test",
                Type = ItemType.Story,
                Url = "https://www.google.com"
            };

            var story_2 = new Item
            {
                Id = 2,
                Title = "Test 2",
                Type = ItemType.Story,
                Url = "https://www.google.com"
            };

            var stories = new List<Item> { story_1, story_2 };

            _ = _storyCacheService.AddStoriesToCache(stories);
            var notCached = _storyCacheService.GetStoriesNotContained(new List<int> { 1, 2 });
            Assert.That(notCached, Has.Exactly(0).Items);
        }
예제 #2
0
        public async Task <SortedList <int, Item> > GetNewStories(IEnumerable <int> storyIds)
        {
            var idsNotCached = _cache.GetStoriesNotContained(storyIds);
            IEnumerable <Item> items;

            if (idsNotCached.Any())
            {
                items = await _storyService.GetItems(idsNotCached).ConfigureAwait(false);

                var stories = _cache.AddStoriesToCache(items);
                return(stories);
            }
            else
            {
                var stories = _cache.GetStoriesCache();
                if (stories == null)
                {
                    items = await _storyService.GetItems(storyIds).ConfigureAwait(false);

                    stories = _cache.AddStoriesToCache(items);
                }
                return(stories);
            }
        }