Ejemplo n.º 1
0
        public async Task Create_WhenAuthenticatedRequestReceivedWithInvalidModelState_ThenRedirectToCreateViewActionReturned()
        {
            var employee = EmployeeProvider.GetOnePreCreationTestEmployee();

            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(true);
            _mockRepository
            .Setup(r => r.AddAsync(employee))
            .ReturnsAsync(EmployeeProvider.GetOnePostCreationTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _user
                }
            };

            controller.ModelState.AddModelError("Forename", "Forename maximum length reached");
            var actual = await controller.Create(employee) as ViewResult;

            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <ViewResult>(actual);
            Assert.That("Create", Is.EqualTo(actual.ViewName));
        }
Ejemplo n.º 2
0
        public async Task Create_WhenAuthenticatedRequestReceived_ThenRedirectToReadViewActionReturned()
        {
            var employee = EmployeeProvider.GetOnePreCreationTestEmployee();

            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(true);
            _mockRepository
            .Setup(r => r.AddAsync(employee))
            .ReturnsAsync(EmployeeProvider.GetOnePostCreationTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            controller.ControllerContext = new ControllerContext()
            {
                HttpContext = new DefaultHttpContext()
                {
                    User = _user
                }
            };

            var actual = await controller.Create(employee) as RedirectToActionResult;

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.ActionName == "Read");
            Assert.IsTrue(actual.ControllerName == "Employee");
        }
Ejemplo n.º 3
0
        public async Task Create_WhenUnAuthenticatedRequestReceived_ThenRedirectToSignInViewActionReturned()
        {
            var employee = EmployeeProvider.GetOnePreCreationTestEmployee();

            _mockAuthService
            .Setup(a => a.IsAuthenticated(_user))
            .Returns(false);
            _mockRepository
            .Setup(r => r.AddAsync(employee))
            .ReturnsAsync(EmployeeProvider.GetOnePostCreationTestEmployee());

            var controller = new EmployeeController(_mockAuthService.Object, _mockRepository.Object, _mockService.Object);

            var actual = await controller.Create(employee) as RedirectToActionResult;

            Assert.IsNotNull(actual);
            Assert.IsTrue(actual.ActionName == "SignIn");
            Assert.IsTrue(actual.ControllerName == "Authentication");
        }