public void GetByLogin_LoginExists() { var userRepository = new UserRepository(_contextFactory); var authenticationRepository = new LoginAuthenticationRepository(_contextFactory); var user = new User { Name = "name", Email = "email" }; var userId = userRepository.Create(user); var initalLoginAuth = new LoginAuthentication { UserId = userId, LoginName = "login", PasswordHash = Enumerable.Range(0, 32).Select(i => (byte)i).ToArray(), Salt = Enumerable.Range(0, 16).Select(i => (byte)i).ToArray() }; authenticationRepository.Save(initalLoginAuth); var restoredLoginAuthentication = authenticationRepository.GetByLogin(initalLoginAuth.LoginName); Assert.NotNull(restoredLoginAuthentication); Assert.AreEqual(initalLoginAuth.UserId, restoredLoginAuthentication.UserId); Assert.AreEqual(initalLoginAuth.LoginName, restoredLoginAuthentication.LoginName); CollectionAssert.AreEqual(initalLoginAuth.Salt, restoredLoginAuthentication.Salt); CollectionAssert.AreEqual(initalLoginAuth.PasswordHash, restoredLoginAuthentication.PasswordHash); }
public void GetByLogin_NullIsPassed() { var repository = new LoginAuthenticationRepository(_contextFactory); repository.GetByLogin(null); }
public void GetByLogin_LoginDoesNotExist() { var repository = new LoginAuthenticationRepository(_contextFactory); var loginAuthentication = repository.GetByLogin("login"); Assert.IsNull(loginAuthentication); }
public void Update_IdIsNotZero() { var userRepository = new UserRepository(_contextFactory); var authenticationRepository = new LoginAuthenticationRepository(_contextFactory); //Create user var user = new User { Name = "name", Email = "email" }; var userId1 = userRepository.Create(user); var user2 = new User { Name = "name2", Email = "email2" }; var userId2 = userRepository.Create(user2); //Save first version login authentication record var initialLoginAuthentication = new LoginAuthentication { Id = 0, LoginName = "login", UserId = userId1, PasswordHash = Enumerable.Range(0, 10).Select(i => (byte)i).ToArray(), Salt = Enumerable.Range(0, 10).Select(i => (byte)i).ToArray() }; authenticationRepository.Save(initialLoginAuthentication); //Update login authentication record var updatedLoginAuthentication = authenticationRepository.GetByLogin(initialLoginAuthentication.LoginName); updatedLoginAuthentication.LoginName = "loginUpd"; updatedLoginAuthentication.PasswordHash = Enumerable.Range(0, 10).Select(i => (byte) (i + 1)).ToArray(); updatedLoginAuthentication.Salt = Enumerable.Range(0, 10).Select(i => (byte) (i + 2)).ToArray(); updatedLoginAuthentication.UserId = userId2; authenticationRepository.Update(updatedLoginAuthentication); //Check what's in the DB var storedLoginAuthentication = _contextFactory.GetContext().LoginsAuthentication.First(); Assert.NotNull(storedLoginAuthentication); Assert.AreEqual(updatedLoginAuthentication.UserId, storedLoginAuthentication.UserId); Assert.AreEqual(updatedLoginAuthentication.LoginName, storedLoginAuthentication.LoginName); CollectionAssert.AreEqual(updatedLoginAuthentication.Salt, storedLoginAuthentication.Salt); CollectionAssert.AreEqual(updatedLoginAuthentication.PasswordHash, storedLoginAuthentication.PasswordHash); }