예제 #1
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);
        }
예제 #2
0
        public void CreateSystemPermission_CannotGrantSystemPermissionToJobFunction_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.JobFunction );

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

                // Verify
                Assert.IsTrue ( eventRaised );
            }
        }
예제 #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);
            }
        }
예제 #4
0
        public void CreateSystemRole_CannotGrantTaskGroupToTask_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 systemRoleTask = systemRoleFactory.CreateSystemRole ( "RoleNameSystemTask", "Role description.", SystemRoleType.Task );
                var systemRoleTaskGroup = systemRoleFactory.CreateSystemRole ( "RoleNameTaskGroup", "Role description.", SystemRoleType.TaskGroup );

                systemRoleTask.GrantSystemRole ( systemRoleTaskGroup );

                // Verify
                Assert.IsTrue ( eventRaised );
            }
        }
예제 #5
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 );
            }
        }