public void Authenticate_ValidUser_Success()
        {
            //Act
            var result = controllerToTest.Authenticate(expectedlogin, expectedpassword) as RedirectToRouteResult;

            //Assert
            Assert.AreEqual("Index", result.RouteValues["action"]);
            Assert.AreEqual("Home", result.RouteValues["controller"]); //Assert.AreEqual("Student", result.RouteValues["controller"]);
        }
Пример #2
0
        public void Authenticate_WithCorrectInput_ReturnsOk()
        {
            IMicroserviceSettings microserviceSettings = new MicroserviceSettings
            {
                JwtIssuer = $"{Guid.NewGuid()}",
                JwtKey    = $"{Guid.NewGuid()}"
            };

            var dto = new ApiCredentialsDto
            {
                ApiKey    = $"{Guid.NewGuid()}",
                ApiSecret = $"{Guid.NewGuid()}"
            };

            var controller   = new AuthenticateController(microserviceSettings);
            var actionResult = controller.Authenticate(dto);

            Assert.NotNull(actionResult);

            var okObjectResult = Assert.IsAssignableFrom <OkObjectResult>(actionResult);
            var response       = Assert.IsAssignableFrom <AuthenticateResponseDto>(okObjectResult?.Value);

            Assert.NotNull(response);
            Assert.NotNull(response.Token);
        }
Пример #3
0
        public void ShouldReturnFalse4()
        {
            var controller = new AuthenticateController();
            var user       = new Users()
            {
                UserEmail = "*****@*****.**"
            };
            var result = controller.Authenticate(user);

            Assert.AreEqual(false, result);
        }
Пример #4
0
        public void ShouldReturnFalse3()
        {
            var controller = new AuthenticateController();
            var user       = new Users()
            {
                UserPassword = "******"
            };
            var result = controller.Authenticate(user);

            Assert.AreEqual(false, result);
        }
Пример #5
0
        public void ShouldReturnTrue1()
        {
            var controller = new AuthenticateController();
            var user       = new Users()
            {
                UserEmail = "*****@*****.**", UserPassword = "******"
            };
            var result = controller.Authenticate(user);

            Assert.AreEqual(true, result);
        }
Пример #6
0
        public void Authenticate_WithIncorrectInput_ReturnsBadRequest()
        {
            IMicroserviceSettings microserviceSettings = new MicroserviceSettings
            {
                JwtIssuer = $"{Guid.NewGuid()}",
                JwtKey    = $"{Guid.NewGuid()}"
            };

            var controller   = new AuthenticateController(microserviceSettings);
            var actionResult = controller.Authenticate(null);

            Assert.NotNull(actionResult);

            Assert.IsAssignableFrom <BadRequestResult>(actionResult);
        }
Пример #7
0
        public void Should_Call_Authenticate_With_Post_And_Receive_Ok_False()
        {
            var authenticationParameters = new AuthenticationParameters()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };

            var controller = new AuthenticateController(credentialsRepository);
            IHttpActionResult actionResult = controller.Authenticate(authenticationParameters);
            var contentResult = actionResult as OkNegotiatedContentResult <bool>;

            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);
            Assert.AreEqual(false, contentResult.Content);
        }
Пример #8
0
        public void ShouldNotAuthenticateWhenUserIsInvalid()
        {
            var invalidLogin = _authFixture.getInvalidUserLogin();
            var authService  = new Mock <IAuthenticationService>();

            authService
            .Setup(auth => auth.AuthenticateBy(invalidLogin.Email, invalidLogin.Password))
            .Returns((AuthenticatedUser)null);
            var tokenService       = new Mock <ITokenService>();
            var expectedStatusCode = (int)HttpStatusCode.BadRequest;
            var authController     = new AuthenticateController(authService.Object, tokenService.Object);

            var response = authController.Authenticate(invalidLogin);

            response.As <BadRequestObjectResult>().StatusCode.Should().Be(expectedStatusCode);
        }
Пример #9
0
        private void ShouldAuthenticateValidUser()
        {
            var userLogin         = _authFixture.getValidUserLogin();
            var authenticatedUser = _authFixture.getAuthenticatedUser();
            var authService       = new Mock <IAuthenticationService>();

            authService
            .Setup(auth => auth.AuthenticateBy(userLogin.Email, userLogin.Password))
            .Returns(authenticatedUser);
            var tokenService       = new Mock <ITokenService>();
            var expectedStatusCode = (int)HttpStatusCode.OK;
            var authController     = new AuthenticateController(authService.Object, tokenService.Object);

            var response = authController.Authenticate(userLogin);

            var result = response.As <OkObjectResult>();

            result.StatusCode.Should().Be(expectedStatusCode);
        }
Пример #10
0
        public void Authenticate_WithMissingApiKey_ReturnsUnauthorized()
        {
            IMicroserviceSettings microserviceSettings = new MicroserviceSettings
            {
                JwtIssuer = $"{Guid.NewGuid()}",
                JwtKey    = $"{Guid.NewGuid()}"
            };

            var dto = new ApiCredentialsDto
            {
                ApiKey    = string.Empty,
                ApiSecret = $"{Guid.NewGuid()}"
            };

            var controller   = new AuthenticateController(microserviceSettings);
            var actionResult = controller.Authenticate(dto);

            Assert.NotNull(actionResult);

            Assert.IsAssignableFrom <UnauthorizedResult>(actionResult);
        }
Пример #11
0
        public void AccountController_LoginGet_ViewCreate()
        {
            ViewResult resultat = (ViewResult)controllerToTest.Authenticate();

            Assert.AreEqual("", resultat.ViewName);
        }