Example #1
0
        public void All_ShouldReturnView()
        {
            // Arrange
            Mock <IPublicationService> publicationService = new Mock <IPublicationService>();
            ListPublicationsViewModel  listModel          = this.GetListPublicationsViewModel();

            publicationService
            .Setup(p => p.Total())
            .Returns(20);

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

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

            // Act
            IActionResult result = publicationsController.All(2);

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

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

            this.AssertPages(listModel, returnModel);
            this.AssertListPublicationsViewModel(listModel, returnModel);
        }
        public IActionResult All(int page)
        {
            if (page <= 0)
            {
                page = 1;
            }

            int totalEntries = this.publicationService.Total();

            ListPublicationsViewModel model = new ListPublicationsViewModel
            {
                CurrentPage    = page,
                TotalEntries   = totalEntries,
                EntriesPerPage = PublicationsPerPage,
                Publications   = this.publicationService.All(page, PublicationsPerPage)
            };

            return(View(model));
        }
Example #3
0
 private void AssertListPublicationsViewModel(ListPublicationsViewModel expected, ListPublicationsViewModel actual)
 {
     this.AssertPublicationListServiceModel(expected.Publications.First(), actual.Publications.First());
     this.AssertPublicationListServiceModel(expected.Publications.Last(), actual.Publications.Last());
 }