public async Task GetRelease_NotFound() { var fileStorageService = new Mock <IFileStorageService>(); fileStorageService .Setup(s => s.GetDeserialized <CachedReleaseViewModel>(It.IsAny <string>())) .ReturnsAsync(new NotFoundResult()); var controller = new ReleaseController(fileStorageService.Object); var result = await controller.GetRelease("publication-a", "2000"); Assert.IsType <NotFoundResult>(result.Result); }
public void TestGetReleaseByID() { var releaseService = new Mock <IReleaseBusinessLayer>(); releaseService.Setup(x => x.GetReleaseByID(1)).Returns(testrelease); var controller = new ReleaseController(releaseService.Object); IHttpActionResult actionResult = controller.GetRelease(1); var contentResult = actionResult as OkNegotiatedContentResult <Release>; Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(1, contentResult.Content.ReleaseID); }
public async Task GetRelease() { var publicationId = Guid.NewGuid(); var releaseId = Guid.NewGuid(); var fileStorageService = new Mock <IFileStorageService>(); fileStorageService.Setup( s => s.GetDeserialized <CachedPublicationViewModel>( "publications/publication-a/publication.json" ) ) .ReturnsAsync(new CachedPublicationViewModel { Id = publicationId, LatestReleaseId = releaseId, Releases = new List <ReleaseTitleViewModel> { new ReleaseTitleViewModel { Id = releaseId } } }); fileStorageService.Setup( s => s.GetDeserialized <CachedReleaseViewModel>( "publications/publication-a/releases/2016.json" ) ) .ReturnsAsync(new CachedReleaseViewModel { Id = releaseId, Content = new List <ContentSectionViewModel> { new ContentSectionViewModel { Content = new List <IContentBlockViewModel> { new HtmlBlockViewModel() } } } }); var controller = new ReleaseController(fileStorageService.Object); var result = await controller.GetRelease("publication-a", "2016"); var releaseViewModel = result.Value; Assert.IsType <ReleaseViewModel>(releaseViewModel); Assert.True(releaseViewModel.LatestRelease); Assert.Single(releaseViewModel.Content); var contentSection = releaseViewModel.Content.First(); Assert.Single(contentSection.Content); Assert.IsType <HtmlBlockViewModel>(contentSection.Content.First()); var publication = releaseViewModel.Publication; Assert.Equal(publicationId, publication.Id); }