コード例 #1
0
        public void ByJournal_WithNotExistingJournalId_ShouldReturnBadRequest()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            Mock <IJournalService>     journalService     = new Mock <IJournalService>();

            ListPublicationsByJournalViewModel         listModel    = this.GetListPublicationsByJournalViewModel();
            IEnumerable <ListPublicationsServiceModel> publications = null;

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

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

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

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

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

            // Assert
            Assert.IsType <BadRequestResult>(result);
        }
コード例 #2
0
        public void ByJournal_ShouldReturnView()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            Mock <IJournalService>     journalService     = new Mock <IJournalService>();

            ListPublicationsByJournalViewModel listModel = this.GetListPublicationsByJournalViewModel();

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

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

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

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

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

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

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

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