public void Status_Can_Send_Pagination() { // Arrange Mock <ILogger <StatusesController> > mockLogger = new Mock <ILogger <StatusesController> >(); Mock <IStatusRepository> mockStatusRepository = new Mock <IStatusRepository>(); mockStatusRepository.Setup(m => m.GetStatuses).Returns((new Status[] { new Status { StatusId = 1, Name = "S1" }, new Status { StatusId = 2, Name = "S2" }, new Status { StatusId = 3, Name = "S3" }, new Status { StatusId = 4, Name = "S4" }, new Status { StatusId = 5, Name = "S5" } }).AsQueryable <Status>()); StatusesController controller = new StatusesController(mockLogger.Object, mockStatusRepository.Object); controller.PageSize = 3; // Act StatusesListViewModel result = controller.List(2).ViewData.Model as StatusesListViewModel; // Assert PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(2, pageInfo.CurrentPage); Assert.AreEqual(3, pageInfo.ItemsPerPage); Assert.AreEqual(5, pageInfo.TotalItems); Assert.AreEqual(2, pageInfo.TotalPages); }
public void Status_Can_Paginate() { // Arrange Mock <ILogger <StatusesController> > mockLogger = new Mock <ILogger <StatusesController> >(); Mock <IStatusRepository> mockStatusRepository = new Mock <IStatusRepository>(); mockStatusRepository.Setup(m => m.GetStatuses).Returns((new Status[] { new Status { StatusId = 1, Name = "S1" }, new Status { StatusId = 2, Name = "S2" }, new Status { StatusId = 3, Name = "S3" }, new Status { StatusId = 4, Name = "S4" }, new Status { StatusId = 5, Name = "S5" } }).AsQueryable <Status>()); StatusesController controller = new StatusesController(mockLogger.Object, mockStatusRepository.Object); controller.PageSize = 3; // Act StatusesListViewModel result = controller.List(2).ViewData.Model as StatusesListViewModel; // Assert Status[] statusArray = result.Statuses.ToArray(); Assert.IsTrue(statusArray.Length == 2); Assert.AreEqual("S4", statusArray[0].Name); Assert.AreEqual("S5", statusArray[1].Name); }