Example #1
0
        public void CanAdd_should_throw_exception_if_name_empty()
        {
            var command = new AddRole {
                Name = null !
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanAdd(roles_0, command),
                                    new ValidationError("Name is required.", "Name"));
        }
Example #2
0
        public void CanDelete_should_throw_exception_if_name_empty()
        {
            var command = new DeleteRole {
                Name = null !
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanDelete(command, App(roles_0)),
                                    new ValidationError("Name is required.", "Name"));
        }
Example #3
0
        public void CanUpdate_should_not_throw_exception_if_role_exist_with_valid_command()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new UpdateRole {
                Name = roleName, Permissions = new[] { "P1" }
            };

            GuardAppRoles.CanUpdate(roles_1, command);
        }
Example #4
0
        public void CanDelete_should_not_throw_exception_if_success()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new DeleteRole {
                Name = roleName
            };

            GuardAppRoles.CanDelete(roles_1, command, contributors, clients);
        }
Example #5
0
        public void CanUpdate_should_not_throw_exception_if_properties_is_null()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new UpdateRole {
                Name = roleName, Permissions = new[] { "P1" }
            };

            GuardAppRoles.CanUpdate(roles_1, command);
        }
Example #6
0
        public void CanDelete_should_not_throw_exception_if_command_is_valid()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new DeleteRole {
                Name = roleName
            };

            GuardAppRoles.CanDelete(command, App(roles_1));
        }
Example #7
0
        public void CanDelete_should_throw_exception_if_client_found()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new DeleteRole {
                Name = roleName
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanDelete(roles_1, command, contributors, clients.Add("1", new AppClient("client", "1", roleName))),
                                    new ValidationError("Cannot remove a role when a client is assigned."));
        }
Example #8
0
        public void CanAdd_should_throw_exception_if_name_exists()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new AddRole {
                Name = roleName
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanAdd(roles_1, command),
                                    new ValidationError("A role with the same name already exists."));
        }
Example #9
0
        public void CanUpdate_should_throw_exception_if_default_role()
        {
            var roles_1 = roles_0.Add(Role.Developer);

            var command = new UpdateRole {
                Name = Role.Developer, Permissions = new[] { "P1" }
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanUpdate(roles_1, command),
                                    new ValidationError("Cannot update a default role."));
        }
Example #10
0
        public void CanUpdate_should_throw_exception_if_permission_is_null()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new UpdateRole {
                Name = roleName, Permissions = null
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanUpdate(roles_1, command),
                                    new ValidationError("Permissions is required.", "Permissions"));
        }
Example #11
0
        public void CanUpdate_should_throw_exception_if_name_empty()
        {
            var roles_1 = roles_0.Add(roleName);

            var command = new UpdateRole {
                Name = null, Permissions = new[] { "P1" }
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanUpdate(roles_1, command),
                                    new ValidationError("Name is required.", "Name"));
        }
Example #12
0
        public void CanDelete_should_throw_exception_if_default_role()
        {
            var roles_1 = roles_0.Add(Role.Developer);

            var command = new DeleteRole {
                Name = Role.Developer
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanDelete(roles_1, command, contributors, clients),
                                    new ValidationError("Cannot delete a default role."));
        }
Example #13
0
        public void CanDelete_should_throw_exception_if_client_found()
        {
            var roles_1 = roles_0.Add("clientRole");

            var command = new DeleteRole {
                Name = "clientRole"
            };

            ValidationAssert.Throws(() => GuardAppRoles.CanDelete(command, App(roles_1)),
                                    new ValidationError("Cannot remove a role when a client is assigned."));
        }