Ejemplo n.º 1
0
        public void CreateTest()
        {
            var controller = new RoutesController();
            var result     = controller.Create() as ViewResult;

            Assert.IsNotNull(result.Model);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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();
        }