public void SignInMustReturnBadRequestWhenSignInModelStateIsInvalid()
        {
            CreateUserControllerMocks();
            var signInDto = new SignInDto { Email = string.Empty, Password = "******" };
            _usersController.ModelState.AddModelError("Email", "Email is required");

            var actionResult = _usersController.SignIn(signInDto) as ObjectResult;

            Assert.NotNull(actionResult);
            Assert.Equal(400, actionResult.StatusCode);
            Assert.NotNull(actionResult.Value);
            dynamic data = actionResult.Value;
            Assert.Equal("Error in sign in data model", data.Message);
            Assert.Equal("Email", data.ModelErrors[0].FieldName);
        }
        public void SignInMustReturnFailureMessageAfterNotSuccessfullSignIn()
        {
            CreateUserControllerMocks();
            var signInDto = new SignInDto { Email = "*****@*****.**", Password = "******" };

            var actionResult = _usersController.SignIn(signInDto) as JsonResult;

            Assert.NotNull(actionResult);
            dynamic data = actionResult.Value;
            Assert.Equal("Email or password are incorrect", data.Message);
            Assert.Equal(false, data.IsSuccess);
        }
        public void SignInMustReturnAccessTokenAfterSuccessfullSignIn()
        {
            CreateUserControllerMocks();
            var user = new User { Id = 1, FirstName = "John", LastName = "Smith" };
            var userSession = new UserSession { AccessToken = Guid.Parse("09d7ab22-a936-4ac9-8fb8-4ba7dc95815e"), User = user, IsActive = true };
            _userService.Setup(x => x.FindByCredentials(It.IsAny<string>(), It.IsAny<string>())).Returns((string email, string password) => user);
            _userSessionService.Setup(x => x.CreateUserSession(It.IsAny<User>(), It.IsAny<string>())).Returns((User userData, string host) => userSession);
            var signInDto = new SignInDto { Email = "*****@*****.**", Password = "******" };

            var actionResult = _usersController.SignIn(signInDto) as JsonResult;

            Assert.NotNull(actionResult);
            dynamic data = actionResult.Value;
            Assert.Equal("09d7ab22-a936-4ac9-8fb8-4ba7dc95815e", data.AccessToken);
            Assert.Equal(true, data.IsSuccess);
        }