public void AuthenticateWithInvalidPasswordOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act User retUser = userService.Authenticate(_user.Username, _user.Password + "WRONG"); //assert - expect exception userService.Dispose(); }
public void AuthenticateWithNoExistentUserOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act User retUser = userService.Authenticate(_user.Username + "DOESNTEXIST", _user.Password); //assert - expect exception userService.Dispose(); }
public void AuthenticateValidPasswordOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act User retUser = userService.Authenticate(_user.Username, _user.Password); //assert Assert.AreEqual(_user, retUser); userService.Dispose(); }
public void CreateOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); User userToCreate = new User { Id = new Guid("0b21d4b6-eb42-456b-9828-a90cb604bceb"), Password = "******", Username = "******" }; mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act Guid id = userService.Create(userToCreate); //assert mockUserRepository.Verify(y => y.Create(It.IsAny<User>())); Assert.IsNotNull(id); userService.Dispose(); }
public void UpdateToExistingUsernameOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //set username to that of another user _user.Username = _users[0].Username; //act userService.Update(_user); //assert - expected exception userService.Dispose(); }
public void UpdateOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //set username to that of another user _user.Username = _user.Username + "WITHUPDATE"; //act userService.Update(_user); //assert - expected exception mockUserRepository.Verify(y => y.Update(It.IsAny<User>())); userService.Dispose(); }
public void GetOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); Guid id = _user.Id; mockUserRepository.Setup(x => x.Get(id)).Returns(_user); UserService userService = new UserService(mockUserRepository.Object); //act User retUser = userService.Get(id); //assert Assert.AreEqual(_user, retUser); userService.Dispose(); }
public void GetAllOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act List<User> retUsers = userService.GetAll().ToList(); //assert CollectionAssert.AreEqual(_users, retUsers); userService.Dispose(); }
public void DeleteOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act userService.Delete(_user.Id); //assert - expected exception mockUserRepository.Verify(y => y.Delete(It.IsAny<Guid>())); userService.Dispose(); }
public void CreateWithExistingUserOnUserService() { //arrange var mockUserRepository = new Mock<IUserRepository>(); mockUserRepository.Setup(x => x.GetAll()).Returns(_users); UserService userService = new UserService(mockUserRepository.Object); //act Guid id = userService.Create(_user); //assert - expect exception userService.Dispose(); }