public void Can_Get_Stations_By_Route() { //Setup Mock<IStationRepository> mock = new Mock<IStationRepository>(); mock.Setup(m => m.Stations).Returns(new Station[] { new Station{Id= "1",Name="S1", Route="Troncal"}, new Station{Id= "2",Name="S2", Route="Troncal"}, new Station{Id= "3",Name="S3", Route="Troncal"}, new Station{Id= "4",Name="S4", Route="Different"}, new Station{Id= "5",Name="S5", Route="Different"} }.AsQueryable()); StationsController stationController = new StationsController(mock.Object); stationController.PageSize = 5; //Act StationListViewModel result = (StationListViewModel)stationController.ByRoute("Troncal").Model; //Assert Station[] stationArray = result.Stations.ToArray(); Assert.IsTrue(stationArray.Length == 3); Assert.AreEqual(stationArray[0].Name, "S1"); Assert.AreEqual(stationArray[1].Name, "S2"); }
public void Can_Send_Pagination_View_Model() { Mock<IStationRepository> mock = new Mock<IStationRepository>(); mock.Setup(m => m.Stations).Returns(new Station[] { new Station{Id= "1",Name="S1"}, new Station{Id= "2",Name="S2"}, new Station{Id= "3",Name="S3"}, new Station{Id= "4",Name="S4"}, new Station{Id= "5",Name="S5"} }.AsQueryable()); StationsController stationController = new StationsController(mock.Object); stationController.PageSize = 3; StationListViewModel result = (StationListViewModel)stationController.Index(2).Model; PagingInfo pagingInfo = result.PagingInfo; Assert.AreEqual(pagingInfo.CurrentPage, 2); Assert.AreEqual(pagingInfo.ItemsPerPage, 3); Assert.AreEqual(pagingInfo.TotalItems, 5); Assert.AreEqual(pagingInfo.TotalPages, 2); }