Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();
        }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
        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();
        }
Esempio n. 10
0
        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();
        }