Example #1
0
        public void GetAuthTokenSuccessTest()
        {
            // Arrange
            AuthenticateUserResource resource = new AuthenticateUserResource();
            User user = new User();

            mapper.Map <AuthenticateUserResource, User>(Arg.Any <AuthenticateUserResource>()).Returns(user);
            IAuthenticateService authenticateService = Substitute.For <IAuthenticateService>();
            string token;

            authenticateService.IsAuthenticated(user, out token)
            .Returns(x => {
                x[1] = "token";
                return(true);
            });
            AuthenticateController controller = new AuthenticateController(authenticateService, mapper);

            // Act
            IActionResult result = controller.GetAuthToken(resource);

            // Assert
            result.Should().BeOfType <OkObjectResult>();
            OkObjectResult okResult = result as OkObjectResult;

            okResult.Value.Should().Be("token");
        }
Example #2
0
        public void GetAuthTokenFailureTest()
        {
            // Arrange
            AuthenticateUserResource resource = new AuthenticateUserResource();
            User user = new User();

            mapper.Map <AuthenticateUserResource, User>(Arg.Any <AuthenticateUserResource>()).Returns(user);
            IAuthenticateService authenticateService = Substitute.For <IAuthenticateService>();
            string token;

            authenticateService.IsAuthenticated(user, out token).Returns(false);
            AuthenticateController controller = new AuthenticateController(authenticateService, mapper);

            // Act
            IActionResult result = controller.GetAuthToken(resource);

            // Assert
            result.Should().BeOfType <BadRequestObjectResult>();
            BadRequestObjectResult badRequestResult = result as BadRequestObjectResult;

            badRequestResult.Value.Should().Be("Invalid authentication request.");
        }