Beispiel #1
0
        public void ByTelescope_WithNotExistingTelescopeId_ShouldReturnView()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            Mock <ITelescopeService>   telescopeService   = new Mock <ITelescopeService>();

            ListPublicationsByTelescopeViewModel       listModel    = this.GetListPublicationsByTelescopeViewModel();
            IEnumerable <ListPublicationsServiceModel> publications = null;

            publicationService
            .Setup(p => p.TotalByTelescope(It.IsAny <int>()))
            .Returns(20);

            publicationService
            .Setup(p => p.AllByTelescope(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(publications);

            telescopeService
            .Setup(j => j.GetName(It.IsAny <int>()))
            .Returns("Test Name");

            PublicationsController publicationsController =
                new PublicationsController(null, null, telescopeService.Object, publicationService.Object, null);

            // Act
            IActionResult result = publicationsController.ByTelescope(1, 2);

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
Beispiel #2
0
        public void ByTelescope_ShouldReturnView()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            Mock <ITelescopeService>   telescopeService   = new Mock <ITelescopeService>();

            ListPublicationsByTelescopeViewModel listModel = this.GetListPublicationsByTelescopeViewModel();

            publicationService
            .Setup(p => p.TotalByTelescope(It.IsAny <int>()))
            .Returns(20);

            publicationService
            .Setup(p => p.AllByTelescope(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(this.GetPublications());

            telescopeService
            .Setup(j => j.GetName(It.IsAny <int>()))
            .Returns("Journal Name");

            PublicationsController publicationsController =
                new PublicationsController(null, null, telescopeService.Object, publicationService.Object, null);

            // Act
            IActionResult result = publicationsController.ByTelescope(1, 2);

            // Assert

            Assert.IsType <ViewResult>(result);
            object model = (result as ViewResult).Model;

            Assert.IsType <ListPublicationsByTelescopeViewModel>(model);
            ListPublicationsByTelescopeViewModel returnModel = model as ListPublicationsByTelescopeViewModel;

            this.AssertPages(listModel, returnModel);
            this.AssertListPublicationsByTelescopeViewModel(listModel, returnModel);
        }