public void GetStoriesCache_Stories_ReturnsStories()
        {
            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://stackoverflow.com"
            };

            var stories = new List<Item> { story_1, story_2 };
            _ = _storyCacheService.AddStoriesToCache(stories);

            var result = _storyCacheService.GetStoriesCache();
            Assert.That(result, Has.Exactly(2).Items);

            var cachedStory_1 = result.GetValueOrDefault(story_1.Id);
            Assert.That(cachedStory_1, Is.EqualTo(story_1));

            var cachedStory_2 = result.GetValueOrDefault(story_2.Id);
            Assert.That(cachedStory_2, Is.EqualTo(story_2));
        }
Example #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);
            }
        }