public void SecurityServiceBase_Read_ReadPermissionsResultIsNotNull_PermissionsUpdated()
        {
            //------------Setup for test--------------------------
            var perms1 = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission(),
                new WindowsGroupPermission()
            };
            var perms2 = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { ResourceName = "Permission1" },
                new WindowsGroupPermission { ResourceName = "Permission2" },
                new WindowsGroupPermission { ResourceName = "Permission3" },
            };
            var securityServiceBase = new TestSecurityServiceBase { ReadPermissionsResult = perms1 };
            securityServiceBase.Read();
            Assert.AreEqual(perms1.Count, securityServiceBase.Permissions.Count);

            securityServiceBase.ReadPermissionsResult = perms2;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.AreEqual(perms2.Count, securityServiceBase.Permissions.Count);
            for(int i = 0; i < perms2.Count; i++)
            {
                Assert.AreEqual(perms2[i].ResourceName, securityServiceBase.Permissions[i].ResourceName);
            }
        }
Example #2
0
        public void SecurityServiceBase_Read_NoChanges_FiresPermissionsUpdatedEvent_HasModifiedPermissionsAsEventArgsProperty()
        {
            //------------Setup for test--------------------------
            List <WindowsGroupPermission> changedPermissions = null;
            var perms1 = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission {
                    ResourceName = "Permission1"
                },
                new WindowsGroupPermission {
                    ResourceName = "Permission2"
                },
                new WindowsGroupPermission {
                    ResourceName = "Permission3"
                },
            };
            var perms2 = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission {
                    ResourceName = "Permission1"
                },
                new WindowsGroupPermission {
                    ResourceName = "Permission2"
                },
                new WindowsGroupPermission {
                    ResourceName = "Permission3"
                },
            };
            var securityServiceBase = new TestSecurityServiceBase {
                ReadPermissionsResults = perms1
            };

            securityServiceBase.Read();
            securityServiceBase.PermissionsModified += (sender, args) =>
            {
                changedPermissions = args.ModifiedWindowsGroupPermissions;
            };

            //----------------Assert Preconditions--------------------------
            Assert.AreEqual(perms1.Count, securityServiceBase.Permissions.Count);
            Assert.IsNull(changedPermissions);
            securityServiceBase.ReadPermissionsResults = perms2;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.IsNotNull(changedPermissions);
            Assert.AreEqual(3, changedPermissions.Count);
        }
Example #3
0
        public void SecurityServiceBase_Remove_ResourceIDDoesExist_PermissionsRemoved()
        {
            //------------Setup for test--------------------------
            var toBeRemovedID = Guid.NewGuid();
            var resourceID    = toBeRemovedID;
            var permissions   = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission {
                    ResourceID = Guid.NewGuid(), Permissions = AuthorizationContext.View.ToPermissions()
                },
                new WindowsGroupPermission {
                    ResourceID = resourceID, Permissions = AuthorizationContext.View.ToPermissions()
                },
                new WindowsGroupPermission {
                    ResourceID = resourceID, Permissions = AuthorizationContext.Execute.ToPermissions()
                }
            };

            var securityService = new TestSecurityServiceBase {
                ReadPermissionsResults = permissions
            };

            securityService.Read();

            //------------Execute Test---------------------------
            securityService.Remove(toBeRemovedID);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, securityService.Permissions.Count);
            Assert.IsTrue(WindowsGroupPermissionEquals(permissions[0], securityService.Permissions[0]));
        }
        public void SecurityServiceBase_Read_ReadPermissionsResultIsNotNull_PermissionsUpdated()
        {
            //------------Setup for test--------------------------
            var perms1 = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission(),
                new WindowsGroupPermission()
            };
            var perms2 = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission {
                    ResourceName = "Permission1"
                },
                new WindowsGroupPermission {
                    ResourceName = "Permission2"
                },
                new WindowsGroupPermission {
                    ResourceName = "Permission3"
                },
            };
            var overrideResource = new NamedGuid
            {
                Name  = "Workflow",
                Value = new Guid()
            };
            var securityServiceBase = new TestSecurityServiceBase {
                ReadPermissionsResults = perms1, OverrideResource = overrideResource
            };

            securityServiceBase.Read();
            Assert.AreEqual(perms1.Count, securityServiceBase.Permissions.Count);

            securityServiceBase.ReadPermissionsResults = perms2;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.AreEqual(perms2.Count, securityServiceBase.Permissions.Count);
            for (int i = 0; i < perms2.Count; i++)
            {
                Assert.AreEqual(perms2[i].ResourceName, securityServiceBase.Permissions[i].ResourceName);
            }
        }
Example #5
0
        public void SecurityServiceBase_Read_ChangeEvent_Fired()
        {
            //------------Setup for test--------------------------
            var changedEventWasFired = false;
            var securityServiceBase  = new TestSecurityServiceBase();

            securityServiceBase.PermissionsChanged += (sender, args) => changedEventWasFired = true;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.IsTrue(changedEventWasFired);
        }
Example #6
0
        public void SecurityServiceBase_Read_ReadPermissionsResultIsNull_PermissionsCleared()
        {
            //------------Setup for test--------------------------
            var perms1 = new List <WindowsGroupPermission>
            {
                new WindowsGroupPermission(),
                new WindowsGroupPermission()
            };
            var securityServiceBase = new TestSecurityServiceBase {
                ReadPermissionsResults = perms1
            };

            securityServiceBase.Read();
            Assert.AreEqual(perms1.Count, securityServiceBase.Permissions.Count);

            securityServiceBase.ReadPermissionsResults = null;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.AreEqual(0, securityServiceBase.Permissions.Count);
        }
        public void SecurityServiceBase_Read_FiresPermissionsUpdatedEvent_HasModifiedPermissionsAsEventArgsProperty()
        {
            //------------Setup for test--------------------------
            List<WindowsGroupPermission> changedPermissions = null;
            var perms1 = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { ResourceName = "Permission1" },
            };
            var perms2 = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { ResourceName = "Permission1" },
                new WindowsGroupPermission { ResourceName = "Permission2" },
                new WindowsGroupPermission { ResourceName = "Permission3" },
            };
            var securityServiceBase = new TestSecurityServiceBase { ReadPermissionsResult = perms1 };
            securityServiceBase.Read();
            securityServiceBase.PermissionsModified += (sender, args) =>
            {
                changedPermissions = args.ModifiedWindowsGroupPermissions;
            };

            //----------------Assert Preconditions--------------------------
            Assert.AreEqual(perms1.Count, securityServiceBase.Permissions.Count);
            Assert.IsNull(changedPermissions);
            securityServiceBase.ReadPermissionsResult = perms2;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.IsNotNull(changedPermissions);
            Assert.AreEqual(3, changedPermissions.Count);
        }
        public void SecurityServiceBase_Remove_ResourceIDDoesExist_PermissionsRemoved()
        {
            //------------Setup for test--------------------------
            var toBeRemovedID = Guid.NewGuid();
            var resourceID = toBeRemovedID;
            var permissions = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission { ResourceID = Guid.NewGuid(), Permissions = AuthorizationContext.View.ToPermissions() },
                new WindowsGroupPermission { ResourceID = resourceID, Permissions = AuthorizationContext.View.ToPermissions() },
                new WindowsGroupPermission { ResourceID = resourceID, Permissions = AuthorizationContext.Execute.ToPermissions() }
            };

            var securityService = new TestSecurityServiceBase { ReadPermissionsResult = permissions };
            securityService.Read();

            var comparer = new WindowsGroupPermissionEqualityComparer();

            //------------Execute Test---------------------------
            securityService.Remove(toBeRemovedID);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, securityService.Permissions.Count);
            Assert.IsTrue(comparer.Equals(permissions[0], securityService.Permissions[0]));
        }
        public void SecurityServiceBase_Read_ChangeEvent_Fired()
        {
            //------------Setup for test--------------------------
            bool changedEventWasFired = false;
            var securityServiceBase = new TestSecurityServiceBase();
            securityServiceBase.PermissionsChanged += (sender, args) => changedEventWasFired = true;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.IsTrue(changedEventWasFired);
        }
        public void SecurityServiceBase_Read_ReadPermissionsResultIsNull_PermissionsCleared()
        {
            //------------Setup for test--------------------------
            var perms1 = new List<WindowsGroupPermission>
            {
                new WindowsGroupPermission(),
                new WindowsGroupPermission()
            };
            var securityServiceBase = new TestSecurityServiceBase { ReadPermissionsResult = perms1 };
            securityServiceBase.Read();
            Assert.AreEqual(perms1.Count, securityServiceBase.Permissions.Count);

            securityServiceBase.ReadPermissionsResult = null;

            //------------Execute Test---------------------------
            securityServiceBase.Read();

            //------------Assert Results-------------------------
            Assert.AreEqual(0, securityServiceBase.Permissions.Count);
        }