コード例 #1
0
        public void AddUserSuccesTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            UserService userService = new UserService(mockUserDAL, new MockCrypthographyService(), new MockJwtAuthenticationManager());

            //Act
            var id = Guid.NewGuid();

            userService.AddUser(id, "*****@*****.**", "Password");

            //Assert
            Assert.AreEqual(id, mockUserDAL.users.First().UserId);
        }
コード例 #2
0
        public void RegisterUserSuccesTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();

            Services.UserService userService = new Services.UserService(mockUserDAL, new MockMessagePublisher());

            //Act
            var result = userService.Register(Guid.NewGuid(), "*****@*****.**", "Robert", "Hoi ik ben Robert");

            //Assert
            Assert.AreEqual(1, mockUserDAL.users.Count);
            Assert.AreEqual("*****@*****.**", mockUserDAL.users[0].Email);
            Assert.AreEqual("Robert", mockUserDAL.users[0].DisplayName);
            Assert.AreEqual("Hoi ik ben Robert", mockUserDAL.users[0].Biography);
        }
コード例 #3
0
        public void CheckCredentialsFailureTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();

            mockUserDAL.users.Add(new Models.User {
                Email = "*****@*****.**"
            });

            Services.UserService userService = new Services.UserService(mockUserDAL, new MockMessagePublisher());
            //Act
            var result = userService.CheckCredentials("*****@*****.**", "*****@*****.**", "Password", "Password");

            //Assert
            Assert.IsFalse(result);
        }
コード例 #4
0
        public void GetUserFailureTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            var         id          = Guid.NewGuid();

            mockUserDAL.users.Add(new Models.User {
                Email = "*****@*****.**", UserId = id
            });

            Services.UserService userService = new Services.UserService(mockUserDAL, new MockMessagePublisher());

            //Act
            var result = userService.GetUser(Guid.NewGuid());

            //Assert
            Assert.Null(result);
        }
コード例 #5
0
        public void AuthenticateFailureTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            UserService userService = new UserService(mockUserDAL, new MockCrypthographyService(), new MockJwtAuthenticationManager());

            var  id   = Guid.NewGuid();
            User user = new User {
                UserId = id, Email = "*****@*****.**", Password = "******", Role = Roles.User
            };

            mockUserDAL.users.Add(user);

            //Act
            string result = userService.Authenticate("*****@*****.**", "xxxxx");

            //Assert
            Assert.Null(result);
        }
コード例 #6
0
        public void DeleteUserFailureTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            UserService userService = new UserService(mockUserDAL, new MockCrypthographyService(), new MockJwtAuthenticationManager());

            var  id   = Guid.NewGuid();
            User user = new User {
                UserId = id, Email = "*****@*****.**", Password = "******", Role = Roles.User
            };

            mockUserDAL.users.Add(user);

            //Act
            userService.DeleteUser(Guid.NewGuid());

            //Assert
            Assert.AreEqual(1, mockUserDAL.users.Count());
        }
コード例 #7
0
        public void DeleteUserSuccesTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            UserService userService = new UserService(mockUserDAL, new MockCrypthographyService(), new MockJwtAuthenticationManager());

            var  id   = Guid.NewGuid();
            User user = new User {
                UserId = id, Email = "*****@*****.**", Password = "******", Role = Roles.User
            };

            mockUserDAL.users.Add(user);

            //Act
            userService.DeleteUser(id);

            //Assert
            Assert.Null(mockUserDAL.users.FirstOrDefault(e => e.UserId == id));
        }
コード例 #8
0
        public void GetUserSuccesTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            UserService userService = new UserService(mockUserDAL, new MockCrypthographyService(), new MockJwtAuthenticationManager());

            var  id   = Guid.NewGuid();
            User user = new User {
                UserId = id, Email = "*****@*****.**", Password = "******", Role = Roles.User
            };

            mockUserDAL.users.Add(user);

            //Act
            var result = userService.GetUser(id);

            //Assert
            Assert.AreEqual(id, result.UserId);
        }
コード例 #9
0
        public void GetUserSuccesTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            var         id          = Guid.NewGuid();

            mockUserDAL.users.Add(new Models.User {
                Email = "*****@*****.**", UserId = id
            });

            Services.UserService userService = new Services.UserService(mockUserDAL, new MockMessagePublisher());

            //Act
            var result = userService.GetUser(id);

            //Assert
            Assert.NotNull(result);
            Assert.AreEqual("*****@*****.**", result.Email);
            Assert.AreEqual(id, result.UserId);
        }
コード例 #10
0
        public void ChangeUserNoChangeTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            UserService userService = new UserService(mockUserDAL, new MockCrypthographyService(), new MockJwtAuthenticationManager());

            var  id   = Guid.NewGuid();
            User user = new User {
                UserId = id, Email = "*****@*****.**", Password = "******", Role = Roles.User
            };

            mockUserDAL.users.Add(user);

            //Act
            userService.ChangeUser(id, "*****@*****.**");

            //Assert
            Assert.AreEqual("*****@*****.**", mockUserDAL.users.First().Email);
            Assert.AreEqual(id, mockUserDAL.users.First().UserId);
        }
コード例 #11
0
        public void DeleteUserSuccesTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();

            var id = Guid.NewGuid();

            Models.User user = new Models.User {
                Email = "*****@*****.**", UserId = id
            };

            mockUserDAL.users.Add(user);

            Services.UserService userService = new Services.UserService(mockUserDAL, new MockMessagePublisher());

            //Act
            var result = userService.DeleteUser(user);

            //Assert
            Assert.True(result.Result);
            Assert.AreEqual(0, mockUserDAL.users.Count);
        }
コード例 #12
0
        public void UpdateUserFailureTest()
        {
            //Arrange
            MockUserDAL mockUserDAL = new MockUserDAL();
            var         id          = Guid.NewGuid();

            mockUserDAL.users.Add(new Models.User {
                Email = "*****@*****.**", UserId = id
            });
            mockUserDAL.users.Add(new Models.User {
                Email = "*****@*****.**", UserId = Guid.NewGuid()
            });

            Services.UserService userService = new Services.UserService(mockUserDAL, new MockMessagePublisher());

            //Act
            var result = userService.UpdateUser(new Models.User {
                UserId = id, Email = "*****@*****.**"
            });

            //Assert
            Assert.IsFalse(result.Result);
        }