public void TestGetIndex() { // Arrange var controller = new RoutesController(new RouteLogic(new RouteRepositoryStub()), new StationLogic(new StationRepositoryStub())); var RouteList = new List <Route> { new Route { RouteID = 1, RouteName = "R1" }, new Route { RouteID = 2, RouteName = "R2" }, }; // ACt var result = (ViewResult)controller.Index(); var resultList = (List <Route>)result.Model; // Assert Assert.AreEqual("", result.ViewName); for (int i = 0; i < resultList.Count(); i++) { Assert.AreEqual(RouteList[i].RouteID, resultList[i].RouteID); Assert.AreEqual(RouteList[i].RouteName, resultList[i].RouteName); } }
public async Task Index_ReturnsAViewResult_WithAListOfRoutes() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.GetRoutes()).Returns(Task.FromResult(GetTestRoutes())); var mockPointsRepo = new Mock <IPointsRepository>(); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await controller.Index(); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <Route> >(viewResult.ViewData.Model); Assert.Equal(GetTestRoutes().Count, model.Count()); }