示例#1
0
        public async Task GetSessionAsync_UserExists_ShouldReturnTheSession()
        {
            // Arrange
            expectedSession.User   = expectedUser;
            expectedSession.UserId = expectedUser.Id;
            context.Add(expectedSession);
            context.SaveChanges();

            //Act
            var actualSession = await repository.GetSessionAsync(expectedUser);

            //Assert
            Assert.AreEqual(expectedSession, actualSession);
        }
示例#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);
        }