private async Task <BlogVm> GetBlogVm(string id) { // TODO: Refactor this into services w/ unit test. Seems like a good example! var entries = await _mediator.Send(new GetActiveBlogEntriesQuery()); var entry = new GitHubBlogEntry(); if (String.IsNullOrWhiteSpace(id)) { entry = entries.LastOrDefault(); } else { entry = entries.FirstOrDefault(x => x.GitHubBlogEntryMetaData.Date.ToString("yyyyMMdd") == id); } var index = entries.IndexOf(entry); var previousId = String.Empty; var nextId = string.Empty; if (index > 0) { previousId = entries[index - 1].GitHubBlogEntryMetaData.Date.ToString("yyyyMMdd"); } if (index < entries.Count - 1) { nextId = entries[index + 1].GitHubBlogEntryMetaData.Date.ToString("yyyyMMdd"); } return(new BlogVm(entry.Content, previousId, nextId)); }
public void HandleReturnsEmptyListSuccess() { var logger = new Mock <ILogger <GetActiveBlogEntriesHandler> >(); var cachedGitHubEntryProvider = new Mock <ICachedGitHubEntryProvider>(); var handler = new GetActiveBlogEntriesHandler(logger.Object, cachedGitHubEntryProvider.Object); var request = new GetActiveBlogEntriesQuery(); var cancelationToken = new System.Threading.CancellationToken(); var gitHubEntry = new GitHubBlogEntry(); gitHubEntry.SetContent(notActiveContent); var expected = new List <GitHubBlogEntry>(); cachedGitHubEntryProvider.Setup(x => x.GetEntries()).ReturnsAsync(new List <GitHubBlogEntry> { gitHubEntry }); var actual = handler.Handle(request, cancelationToken).Result; Assert.Equal(expected, actual); }
public async Task <string> DownloadContent(GitHubBlogEntry entry) { return(await _gitHubClient.DownloadContent(entry.DownloadUrl)); }