コード例 #1
0
        public void UserHasRole_Should_Return_False_IfUserDoes_NotHaveRole()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1"
                }, new Role()
                {
                    RoleName = "Role2"
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            bool userHasRole = service.UserHasRole("TestUser", "Admin");

            // Assert
            Assert.IsFalse(userHasRole, "Expected False. User Does not have Admin Role");
        }
コード例 #2
0
        public void GetUserRoles_Should_Return_All_User_Roles()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1"
                }, new Role()
                {
                    RoleName = "Role2"
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            var userRoles = service.GetUserRoles("TestUser");

            // Assert
            Assert.IsTrue(userRoles.Length == 2, "Expected to return 2 roles");
            Assert.IsTrue(userRoles[0] == "role1");
            Assert.IsTrue(userRoles[1] == "role2");
        }
コード例 #3
0
        public void UserHasRole_Should_Return_True_IfUserHasRole()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1"
                }, new Role()
                {
                    RoleName = "Role2"
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            bool userHasRole = service.UserHasRole("TestUser", "Role1");

            // Assert
            Assert.IsTrue(userHasRole, "Expected True.User has Role1");
        }
コード例 #4
0
        public void UserHasPrivilige_Should_Return_True_IsUser_Doe_Have_Privilige()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserName = "******"
            };

            user.Roles = new EntityCollection <Role> {
                new Role()
                {
                    RoleName = "Role1", Privileges = new EntityCollection <Privilege> {
                        new Privilege()
                        {
                            PrivilegeName = "Privilige1"
                        }, new Privilege()
                        {
                            PrivilegeName = "Privilige2"
                        }
                    }
                },
                new Role()
                {
                    RoleName = "Role2", Privileges = new EntityCollection <Privilege> {
                        new Privilege()
                        {
                            PrivilegeName = "Privilige3"
                        }
                    }
                }
            };
            repository.AddUser(user);
            var service = GetRoleService(repository, null);

            // Act
            bool userHasPrivilige = service.UserHasPrivilige("TestUser", "Privilige2");

            // Assert
            Assert.IsTrue(userHasPrivilige);
        }
コード例 #5
0
        public void AddUser_Should_AddUserToData()
        {
            // Arrange
            var repository = new TestUserRepository();
            var user       = new User()
            {
                UserID   = 20,
                UserName = "******",
                Password = "******",
                Email    = "TestEmail"
            };

            // Act
            repository.AddUser(user);
            var theNewUserViaID       = repository.GetUser(20);
            var theNewUserViaUserName = repository.GetUser("TestUserName");

            //Assert
            Assert.AreEqual(repository.GetAllUsers().Count(), 16);
            Assert.IsNotNull(theNewUserViaID);
            Assert.IsNotNull(theNewUserViaUserName);
        }