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"]); }
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); }
public void ShouldReturnFalse4() { var controller = new AuthenticateController(); var user = new Users() { UserEmail = "*****@*****.**" }; var result = controller.Authenticate(user); Assert.AreEqual(false, result); }
public void ShouldReturnFalse3() { var controller = new AuthenticateController(); var user = new Users() { UserPassword = "******" }; var result = controller.Authenticate(user); Assert.AreEqual(false, result); }
public void ShouldReturnTrue1() { var controller = new AuthenticateController(); var user = new Users() { UserEmail = "*****@*****.**", UserPassword = "******" }; var result = controller.Authenticate(user); Assert.AreEqual(true, result); }
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); }
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); }
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); }
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); }
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); }
public void AccountController_LoginGet_ViewCreate() { ViewResult resultat = (ViewResult)controllerToTest.Authenticate(); Assert.AreEqual("", resultat.ViewName); }