public void TestGetDetails() { // Arrange var controller = new RoutesController(new RouteLogic(new RouteRepositoryStub()), new StationLogic(new StationRepositoryStub())); var RouteStations = new List <Station> { new Station { StationID = 1, StationName = "Oslo S", StationNumber = 1 }, new Station { StationID = 2, StationName = "Nationaltheatret", StationNumber = 2 }, new Station { StationID = 3, StationName = "Lysaker", StationNumber = 3 } }; var OneRoute = new Route { RouteID = 1, RouteName = "R1", RouteStations = RouteStations }; // ACt var result = (ViewResult)controller.Details(1); var resultRoute = (Route)result.Model; // Assert Assert.AreEqual("", result.ViewName); Assert.AreEqual(OneRoute.RouteID, resultRoute.RouteID); Assert.AreEqual(OneRoute.RouteName, resultRoute.RouteName); for (int i = 0; i < OneRoute.RouteStations.Count(); i++) { Assert.AreEqual(OneRoute.RouteStations[i].StationID, resultRoute.RouteStations[i].StationID); Assert.AreEqual(OneRoute.RouteStations[i].StationName, resultRoute.RouteStations[i].StationName); Assert.AreEqual(OneRoute.RouteStations[i].StationNumber, resultRoute.RouteStations[i].StationNumber); } }
public void DetailsTest() { var controller = new RoutesController(); var result = controller.Details(1) as PartialViewResult; var route = result.Model as Route; Assert.IsTrue(route.RouteName == "Route - 1"); }
public async Task DetailsGet_ReturnsNotFound_WhenIdIsNull() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); var mockPointsRepo = new Mock <IPointsRepository>(); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await controller.Details(null); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task DetailsGet_ReturnsNotFound_WhenRouteReturnedIsNull() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.GetRouteByID(1)).Returns(Task.FromResult((Route)null)); var mockPointsRepo = new Mock <IPointsRepository>(); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await controller.Details(1); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task DetailsGet_ReturnsAViewResult_WithRoute() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.GetRouteByID(1)).Returns(Task.FromResult(GetTestRoutes()[0])); var mockPointsRepo = new Mock <IPointsRepository>(); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await controller.Details(1); // Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <Route>(viewResult.ViewData.Model); Assert.Equal(GetTestRoutes()[0], model); }