public void CreateUserDALError2Test() { const string Name = "user"; const string Email = "*****@*****.**"; const string Password = "******"; string message; User userToCreate = new User { Username = Name, Email = Email, Password = Password }; userToCreate.Roles.Add(new Role { Name = AccountService.UserDefaultRole }); AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.AtLeastOnce(); _usersRepository.Expect(x => x.CheckIfUsernameAvailable(Name)).Return(true); _usersRepository.Expect(x => x.CheckIfEmailAvailable(Email)).Throw(new DbException("Message")); _mockRepository.ReplayAll(); User actual = accountService.CreateUser(Name, Email, Password, out message); Assert.AreEqual(null, actual); Assert.AreEqual(AccountService.ErrorDuringUserCreation, message); _mockRepository.VerifyAll(); }
public void ValidateUserNotFoundTest() { const string Name = "user"; const string Password = "******"; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once(); _usersRepository.Expect(x => x.GetUserByNameAndPassword(Name, Password)).Return(null); _mockRepository.ReplayAll(); User actual = accountService.ValidateUser(Name, Password, out message); Assert.AreEqual(null, actual); Assert.AreEqual(AccountService.UserNotFoundMessage, message); _mockRepository.VerifyAll(); }
public void ValidateUserSuccessTest() { const string Name = "user"; const string Password = "******"; User user = new User(); List<Role> roles = new List<Role> { new Role { Key = 1, Name = "Vassas", Description = "Blah" } }; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once(); _dalContext.Expect(x => x.RolesRepository).Return(_rolesRepository).Repeat.Once(); _usersRepository.Expect(x => x.GetUserByNameAndPassword(Name, Password)).Return(user); _rolesRepository.Expect(x => x.GetRolesForUser(Name)).Return(roles).Repeat.Once(); _mockRepository.ReplayAll(); User actual = accountService.ValidateUser(Name, Password, out message); Assert.AreEqual(user, actual); CollectionAssert.AreEqual(roles, user.Roles.ToList()); Assert.IsNull(message); _mockRepository.VerifyAll(); }
public void ValidateUserDALErrorTest() { const string Name = "user"; const string Password = "******"; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once(); _usersRepository.Expect(x => x.GetUserByNameAndPassword(Name, Password)).Throw(new DbException("An error")); _mockRepository.ReplayAll(); User actual = accountService.ValidateUser(Name, Password, out message); Assert.AreEqual(null, actual); Assert.AreEqual(AccountService.ErrorDuringReadingUserMessage, message); _mockRepository.VerifyAll(); }
public void GetRolesForUserSuccessTest() { const string Name = "user"; List<Role> roles = new List<Role> { new Role { Name = "r1" }, new Role { Name = "r2" }, }; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.RolesRepository).Return(_rolesRepository).Repeat.Once(); _rolesRepository.Expect(x => x.GetRolesForUser(Name)).Return(roles); _mockRepository.ReplayAll(); List<string> actual = accountService.GetRolesForUser(Name, out message); CollectionAssert.AreEqual(roles.Select(x=>x.Name).ToArray(), actual); Assert.IsNull(message); _mockRepository.VerifyAll(); }
public void GetRolesForUserNotFoundTest() { const string Name = "user"; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.RolesRepository).Return(_rolesRepository).Repeat.Once(); _rolesRepository.Expect(x => x.GetRolesForUser(Name)).Return(new List<Role>()); _mockRepository.ReplayAll(); List<string> actual = accountService.GetRolesForUser(Name, out message); Assert.AreEqual(0, actual.Count); Assert.AreEqual(AccountService.UserNotFoundMessage, message); _mockRepository.VerifyAll(); }
public void GetRolesForUserDALErrorTest() { const string Name = "user"; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.RolesRepository).Return(_rolesRepository).Repeat.Once(); _rolesRepository.Expect(x => x.GetRolesForUser(Name)).Throw(new DbException("An error")); _mockRepository.ReplayAll(); List<string> actual = accountService.GetRolesForUser(Name, out message); Assert.AreEqual(null, actual); Assert.AreEqual(AccountService.ErrorDuringReadingUserMessage, message); _mockRepository.VerifyAll(); }
public void CreateUserUserExistsTest() { const string Name = "user"; const string Email = "*****@*****.**"; const string Password = "******"; string message; AccountService accountService = new AccountService(_dalContext); _dalContext.Expect(x => x.UsersRepository).Return(_usersRepository).Repeat.Once(); _usersRepository.Expect(x => x.CheckIfUsernameAvailable(Name)).Return(false).Repeat.Once(); _mockRepository.ReplayAll(); User actual = accountService.CreateUser(Name, Email, Password, out message); Assert.AreEqual(null, actual); Assert.AreEqual(AccountService.UserNameIsAlreadyTaken, message); _mockRepository.VerifyAll(); }