Beispiel #1
0
        public async Task AuthenticateWithoutLoginShouldReturnBadRequest()
        {
            // Arrange
            var request = new AuthenticateRequest()
            {
                Login    = "",
                Password = "******"
            };

            var controller = new SessionController(_mockISessionService.Object, _mockIJwtBearerGenerator.Object);

            // Act
            var result = await controller.Authenticate(request);

            // Assert
            result.Should()
            .BeOfType <BadRequestObjectResult>()
            .Which.Value.Should()
            .BeSameAs("Login obrigatório");
        }
Beispiel #2
0
        public async Task AuthenticateShouldReturnJwtBearerToken()
        {
            // Arrange
            var request = new AuthenticateRequest()
            {
                Login    = "******",
                Password = "******"
            };

            var userLogin = new UserLogin()
            {
                UserId   = Guid.NewGuid(),
                Login    = "******",
                Password = "******"
            };

            var jwt = new JwtBearerToken()
            {
                AccessToken = "your_token",
                Created     = DateTime.Now.ToString(),
                Expiration  = DateTime.Now.ToString(),
            };

            _mockISessionService.Setup(it => it.GetByLoginAsync(It.IsAny <string>())).
            ReturnsAsync(userLogin);
            _mockISessionService.Setup(it => it.ValidateCredentialsAsync(It.IsAny <UserLogin>(), It.IsAny <string>())).
            ReturnsAsync(true);
            _mockIJwtBearerGenerator.Setup(it => it.GenerateToken(It.IsAny <UserLogin>(), It.IsAny <string>())).
            Returns(jwt);

            var controller = new SessionController(_mockISessionService.Object, _mockIJwtBearerGenerator.Object);

            // Act
            var result = await controller.Authenticate(request);

            // Assert
            result.Should()
            .BeOfType <OkObjectResult>()
            .Which.Value.Should()
            .BeOfType <JwtBearerToken>();
        }