Exemplo n.º 1
0
        public void HasOperation_GIVEN_User_Has_No_Operations_WHEN_OperationName_Is_ABC_THEN_Returns_False()
        {
            var role = new Role { Name = "Role" };

            var result = role.HasOperation("ABC");

            result.ShouldBeFalse();
        }
Exemplo n.º 2
0
        public void AddOperation_Add_Operation_To_List()
        {
            var operation = new Operation { Name = "Operation" };
            var role = new Role { Name = "Role" };

            role.AddOperation(operation);
            role.Operations.ShouldContain(operation);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a role to a user
        /// </summary>
        /// <param name="role">role to add</param>
        public virtual void AddRole(Role role)
        {
            if (role == null)
                throw new ArgumentNullException();

            if(!_roles.Contains(role))
                _roles.Add(role);
        }
Exemplo n.º 4
0
        public void AddRole_Adds_To_Roles_List()
        {
            var role = new Role { Name = "Role" };

            var user = new User();
            user.AddRole(role);

            user.Roles.ShouldContain(role);
        }
Exemplo n.º 5
0
        public void HasOperation_GIVEN_User_Has_Operation_With_Name_DEF_WHEN_operationName_Is_ABC_THEN_Returns_False()
        {
            var operation = new Operation { Name = "DEF" };
            var role = new Role { Name = "Role" };
            role.AddOperation(operation);

            var result = role.HasOperation("ABC");

            result.ShouldBeFalse();
        }
Exemplo n.º 6
0
        public void AddRole_GIVEN_User_Has_Role_WHEN_Adding_Same_Role_Again_THEN_Roles_Count_Remains_1()
        {
            var role = new Role { Name = "Role" };

            var user = new User();
            user.AddRole(role);
            user.AddRole(role);

            user.Roles.ShouldContain(role);
            user.Roles.Count().ShouldEqual(1);
        }
Exemplo n.º 7
0
        public void AddOperation_GIVEN_Operation_Already_Added_WHEN_Added_Again_THEN_Does_Not_Add_To_List_Again()
        {
            var operation = new Operation { Name = "Operation" };
            var role = new Role { Name = "Role" };

            role.AddOperation(operation);
            role.AddOperation(operation);

            role.Operations.ShouldContain(operation);
            role.Operations.Count().ShouldEqual(1);
        }
Exemplo n.º 8
0
        public void HasOperation_GIVEN_User_Has_Operation_With_Name_ABC_WHEN_operationName_Is_ABC_THEN_Returns_True()
        {
            const string OperationName = "ABC";

            var operation = new Operation { Name = OperationName };
            var role = new Role { Name = "Role" };
            role.AddOperation(operation);

            var result = role.HasOperation(OperationName);

            result.ShouldBeTrue();
        }
Exemplo n.º 9
0
        public void HasOperation_GIVEN_User_Has_1_Role_With_No_Operations_WHEN_operationName_Is_ABC_THEN_Returns_False()
        {
            const string CheckForOperationName = "ABC";

            var role = new Role { Name = "Role" };
            var user = new User();
            user.AddRole(role);

            var result = user.HasOperation(CheckForOperationName);

            result.ShouldBeFalse();
        }
        public void CanPerformOperation_GIVEN_Ctor_user_Has_Operation_But_Identity_Is_Not_Authenticated_THEN_Returns_False()
        {
            const string OperationName = "ABC";

            var operation = new Operation { Name = OperationName };
            var role = new Role { Name = "role" };
            role.AddOperation(operation);

            var user = new User();
            user.SetProperty(u => u.Id, 1);
            user.AddRole(role);

            var mockedIdentity = new Mock<IJumbleblocksIdentity>();
            mockedIdentity.Setup(i => i.IsAuthenticated).Returns(false);

            var principal = new JumbleblocksPrincipal(mockedIdentity.Object, user);

            var result = principal.CanPerformOperation(OperationName);

            result.ShouldBeFalse();
        }
Exemplo n.º 11
0
        public void HasRole_GIVEN_User_Has_Role_With_Name_ABC_WHEN_roleName_Is_ABC_THEN_Returns_True()
        {
            const string RoleName = "ABC";

            var role = new Role { Name = RoleName };
            var user = new User();
            user.AddRole(role);

            var result = user.HasRole(RoleName);

            result.ShouldBeTrue();
        }
        public void HasOperation_GIVEN_Has_Operation_ABC_WHEN_operationName_IS_DEF_THEN_Returns_False()
        {
            const string OperationName = "ABC";
            const string CheckOperationName = "DEF";

            var role = new Role { Name = "role" };
            role.AddOperation(new Operation { Name = OperationName });

            var user = new User();
            user.SetProperty(u => u.Id, 1);
            user.AddRole(role);

            var principal = new JumbleblocksPrincipal(new JumbleblocksUserIdentity(user), user);

            var result = principal.HasOperation(CheckOperationName);

            result.ShouldBeFalse();
        }
        public void IsInRole_GIVEN_Has_Role_ABC_WHEN_roleName_IS_DEF_THEN_Returns_False()
        {
            const string RoleName = "ABC";
            const string CheckRoleName = "DEF";

            var role = new Role { Name = RoleName };
            var user = new User();
            user.SetProperty(u => u.Id, 1);
            user.AddRole(role);

            var principal = new JumbleblocksPrincipal(new JumbleblocksUserIdentity(user), user);

            var result = principal.IsInRole(CheckRoleName);

            result.ShouldBeFalse();
        }
        public void CanPerformRole_GIVEN_Ctor_user_Has_Role_And_Identity_Is_Authenticated_THEN_Returns_True()
        {
            const string RoleName = "ABC";

            var role = new Role { Name = RoleName };
            var user = new User();
            user.SetProperty(u => u.Id, 1);
            user.AddRole(role);

            var mockedIdentity = new Mock<IJumbleblocksIdentity>();
            mockedIdentity.Setup(i => i.IsAuthenticated).Returns(true);

            var principal = new JumbleblocksPrincipal(mockedIdentity.Object, user);

            var result = principal.CanPerformRole(RoleName);

            result.ShouldBeTrue();
        }
Exemplo n.º 15
0
        public void AddOperation_WHEN_operation_Is_Null_THEN_Throws_ArgumentNullException()
        {
            var role = new Role { Name = "Role" };

            role.AddOperation(null);
        }
Exemplo n.º 16
0
        public void NameEquals_GIVEN_Role_Name_Is_ABC_WHEN_roleName_Is_abc_THEN_Returns_False()
        {
            const string RoleName = "ABC";
            const string CheckForRoleName = "abc";

            var role = new Role { Name = RoleName };

            var result = role.NameEquals(CheckForRoleName);

            result.ShouldBeFalse();
        }
Exemplo n.º 17
0
        public void NameEquals_GIVEN_Role_Name_Is_ABC_WHEN_roleName_Is_ABC_THEN_Returns_True()
        {
            const string RoleName = "ABC";
            var role = new Role { Name = RoleName };

            var result = role.NameEquals(RoleName);

            result.ShouldBeTrue();
        }
Exemplo n.º 18
0
        public void HasRole_GIVEN_User_Has_Role_With_Name_ABC_WHEN_roleName_Is_DEF_THEN_Returns_False()
        {
            const string RoleName = "ABC";
            const string CheckForRoleName = "DEF";

            var role = new Role { Name = RoleName };
            var user = new User();
            user.AddRole(role);

            var result = user.HasRole(CheckForRoleName);

            result.ShouldBeFalse();
        }