public async Task GetNewStoryIds_WithNoCache_ReturnsIdsFromService() { var result = await _storyProvider.GetNewStoryIds(); Assert.That(result, Has.Exactly(3).Items); _mockStoryService.Verify(x => x.GetNewStories(), Times.Once); }
public async Task <IActionResult> NewStories([FromQuery] ApiQueryModel query) { var newStoryIds = await _storyProvider.GetNewStoryIds(); if (newStoryIds == null) { return(BadRequest("Error loading new story list")); } var pageOffset = (query.Page - 1) * query.PageSize; if (pageOffset >= newStoryIds.Count()) { return(BadRequest("Invalid requested range")); } var pageList = newStoryIds.Skip(pageOffset).Take(query.PageSize); var stories = await _storyProvider.GetNewStories(pageList); if (stories == null) { return(BadRequest("Error pulling new stories")); } var paginatedResult = pageList.Select(id => stories.GetValueOrDefault(id)); var currentPage = query.Page; var lastPage = (int)Math.Ceiling((double)newStoryIds.Count() / query.PageSize); var result = new ApiPagedList <Item>( paginatedResult, currentPage, lastPage ); return(Ok(result)); }