public void CreateTest() { var controller = new RoutesController(); var result = controller.Create() as ViewResult; Assert.IsNotNull(result.Model); }
public async Task CreatePost_ReturnsAViewResult_WithRoute_WhenModelStateIsInvalid() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); var mockPointsRepo = new Mock <IPointsRepository>(); mockPointsRepo.Setup(repo => repo.GetPoints()).Returns(Task.FromResult(GetTestPoints())); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); controller.ModelState.AddModelError("Name", "Required"); var newRoute = new Route() { OriginId = 1, DestinationId = 1 }; // Act var result = await controller.Create(newRoute); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.NotNull(viewResult.ViewData); Assert.Equal(2, viewResult.ViewData.Count); var model = Assert.IsAssignableFrom <Route>( viewResult.ViewData.Model); Assert.Equal(newRoute, model); }
public void CreateTest1() { var controller = new RoutesController(); Route route = new Route(); route.Id = 5; route.RouteName = "Route - 5"; var result = controller.Create(route); Assert.IsTrue(_db.Routes.Contains(route)); }
public async Task CreateGet_ReturnsAnEmptyViewResult() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); var mockPointsRepo = new Mock <IPointsRepository>(); mockPointsRepo.Setup(repo => repo.GetPoints()).Returns(Task.FromResult(GetTestPoints())); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); // Act var result = await controller.Create(); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.NotNull(viewResult.ViewData); Assert.Equal(2, viewResult.ViewData.Count); }
public async Task CreatePost_ReturnsARedirectToActionResult_WhenModelStateIsValid() { // Arrange var mockRoutesRepo = new Mock <IRoutesRepository>(); mockRoutesRepo.Setup(repo => repo.InsertRoute(It.IsAny <Route>())).Verifiable(); mockRoutesRepo.Setup(repo => repo.Save()).Returns(Task.CompletedTask); var mockPointsRepo = new Mock <IPointsRepository>(); var controller = new RoutesController(mockRoutesRepo.Object, mockPointsRepo.Object); var newRoute = GetTestRoutes()[0]; // Act var result = await controller.Create(newRoute); // Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal("Index", redirectToActionResult.ActionName); mockRoutesRepo.Verify(); }