Ejemplo n.º 1
0
        public async Task GetLatestRelease_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.GetLatestRelease("publication-a");

            Assert.IsType <NotFoundResult>(result.Result);
        }
Ejemplo n.º 2
0
        public async Task GetLatestRelease()
        {
            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/latest-release.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.GetLatestRelease("publication-a");

            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);
        }