Example #1
0
        public async Task GetUserAsync_UserExists_ShouldReturnTheUser()
        {
            // Arrange
            login.Email    = expectedUser.Email;
            login.Password = expectedUser.Password;
            context.Add(expectedUser);
            context.SaveChanges();

            //Act
            var actualUser = await repository.GetUserAsync(login);

            //Assert
            Assert.AreEqual(expectedUser, actualUser);
        }
Example #2
0
        public async Task <Session> LoginAsync(LoginModel login)
        {
            login.Password = await encryptor.EncryptAsync(login.Password);

            var user = await repository.GetUserAsync(login);

            if (user == null)
            {
                throw new InvalidCredentialException("Invalid credentials");
            }
            var session = await repository.GetSessionAsync(user);

            if (session == null)
            {
                session = await repository.CreateSessionAsync(user);
            }
            return(session);
        }