public void CanSendPaginationViewModel() { //Arrange Mock<ICommodityRepositiry> mock = new Mock<ICommodityRepositiry>(); mock.Setup(m => m.Commodities).Returns(new List<Commodity> { new Commodity {Article=1, Name="Name1" }, new Commodity {Article=2, Name="Name2" }, new Commodity {Article=3, Name="Name3" }, new Commodity {Article=4, Name="Name4" }, new Commodity {Article=5, Name="Name5" } }); CommodityController controller = new CommodityController(mock.Object); controller.pageSize = 3; //Act CommoditiesListViewModel result = (CommoditiesListViewModel)controller.List(2).Model; //Assert PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(pageInfo.CurrentPage, 2); Assert.AreEqual(pageInfo.ItemPerPage, 3); Assert.AreEqual(pageInfo.TotalItems, 5); Assert.AreEqual(pageInfo.TotalPages, 2); }
public void CanPaginate() { //Arrange Mock<ICommodityRepositiry> mock = new Mock<ICommodityRepositiry>(); mock.Setup(m => m.Commodities).Returns(new List<Commodity> { new Commodity {Article=1, Name="Green tea"}, new Commodity {Article=2, Name="Black tea"}, new Commodity {Article=3, Name="Green coffee"}, new Commodity {Article=4, Name="Coffee Arabica"}, new Commodity {Article=5, Name="Coffee without coffein" } }); CommodityController controller = new CommodityController(mock.Object); controller.pageSize = 3; //Act CommoditiesListViewModel result = (CommoditiesListViewModel)controller.List(2).Model; //Assert List<Commodity> commodity = result.Commodities.ToList(); Assert.IsTrue(commodity.Count == 2); Assert.AreEqual(commodity[0].Name, "Coffee Arabica"); Assert.AreEqual(commodity[1].Name, "Coffee without coffein"); }