Beispiel #1
0
        public void CreateSystemRole_CannotGrantJobFunctionToTask_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                // Register
                var eventRaised = false;
                DomainEvent.Register <RuleViolationEvent> (p => eventRaised = true);

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository> ();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRoleJobFunction = systemRoleFactory.CreateSystemRole(
                    "RoleNameJobFunction", "Role description.", SystemRoleType.JobFunction);
                var systemRoleTask = systemRoleFactory.CreateSystemRole("RoleNameTask", "Role description.", SystemRoleType.Task);

                systemRoleTask.GrantSystemRole(systemRoleJobFunction);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Beispiel #2
0
        public void CreateSystemPermission_NoDuplicateGrantSystemPermissionWithContext_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                // Register
                var eventRaised = false;
                DomainEvent.Register <RuleViolationEvent> (p => eventRaised = true);

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository> ();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRole = systemRoleFactory.CreateSystemRole("RoleName", "Role description.", SystemRoleType.Task);

                var systemPermission1 = new SystemPermission("WellKnownName1", "Permission display name.", "Permission description.");
                systemRole.GrantSystemPermission(systemPermission1);

                var systemPermission2 = new SystemPermission("WellKnownName1", "Permission display name", "Permission description.");
                systemRole.GrantSystemPermission(systemPermission2);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Beispiel #3
0
        public void CreateSystemRole_NoDuplicateGrantSystemRoleWithContext_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                // Register
                var eventRaised = false;
                DomainEvent.Register <RuleViolationEvent>(p => eventRaised = true);

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository>();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRoleDuplicate1 = systemRoleFactory.CreateSystemRole("RoleName1", "Role description.", SystemRoleType.Task);

                var assignedToSystemRole = systemRoleFactory.CreateSystemRole("AssignedToRoleName", "Role description.", SystemRoleType.JobFunction);
                assignedToSystemRole.GrantSystemRole(systemRoleDuplicate1);
                assignedToSystemRole.GrantSystemRole(systemRoleDuplicate1);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }
Beispiel #4
0
        public void CreateSystemRole_GivenValidArguments_Succeeds()
        {
            var systemRoleRepository = new Mock <ISystemRoleRepository>();
            var systemRoleFactory    = new SystemRoleFactory(
                systemRoleRepository.Object);

            var systemRole = systemRoleFactory.CreateSystemRole("RoleName", "Role description.", SystemRoleType.JobFunction);

            Assert.IsNotNull(systemRole);
        }
Beispiel #5
0
        public void DestroySystemRole_GivenASystemRole_RoleIsMadeTransient()
        {
            var isTransient          = false;
            var systemRoleRepository = new Mock <ISystemRoleRepository>();

            systemRoleRepository.Setup(sr => sr.MakeTransient(It.IsAny <SystemRole>())).Callback(() => isTransient = true);
            var systemRoleFactory = new SystemRoleFactory(systemRoleRepository.Object);
            var systemRole        = new Mock <SystemRole>();

            systemRoleFactory.DestroySystemRole(systemRole.Object);

            Assert.IsTrue(isTransient);
        }
Beispiel #6
0
        public void CreateSystemPermission_CannotGrantSystemPermissionToTaskGroup_ValidationFailureEventIsRaised()
        {
            using (var serviceLocatorFixture = new ServiceLocatorFixture())
            {
                // Setup
                SetupServiceLocatorFixture(serviceLocatorFixture);

                // Register
                var eventRaised = false;
                DomainEvent.Register <RuleViolationEvent> (p => eventRaised = true);

                var systemRoleRepositoryMock = new Mock <ISystemRoleRepository> ();
                var systemRoleFactory        = new SystemRoleFactory(systemRoleRepositoryMock.Object);

                // Exercise
                var systemRole = systemRoleFactory.CreateSystemRole("RoleName", "Role description.", SystemRoleType.TaskGroup);

                var systemPermission = new SystemPermission("WellKnownName", "MyPermission", "My permission description.");
                systemRole.GrantSystemPermission(systemPermission);

                // Verify
                Assert.IsTrue(eventRaised);
            }
        }