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); }
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); }
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 ); } }
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); } }
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 ); } }
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 ); } }