示例#1
0
        public void All_ShouldReturnView()
        {
            // Arrange
            Mock <IJournalService> journalService = new Mock <IJournalService>();
            ListJournalsViewModel  listModel      = this.GetListJournalsViewModel();

            journalService
            .Setup(t => t.Total())
            .Returns(20);

            journalService
            .Setup(t => t.All(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(this.GetListJournalsServiceModel());

            JournalsController journalsController = new JournalsController(journalService.Object);

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

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

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

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

            int totalJournals = this.journalService.Total();

            ListJournalsViewModel model = new ListJournalsViewModel
            {
                CurrentPage    = page,
                TotalEntries   = totalJournals,
                EntriesPerPage = JournalsPerPage,
                Journals       = this.journalService.All(page, JournalsPerPage)
            };

            return(View(model));
        }
示例#3
0
 private void AssertJournals(ListJournalsViewModel expected, ListJournalsViewModel actual)
 {
     this.AssertJournals(expected.Journals.First(), actual.Journals.First());
     this.AssertJournals(expected.Journals.Last(), actual.Journals.Last());
 }