コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }
コード例 #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();
        }