SetCurrentPermissions() public method

public SetCurrentPermissions ( List windowsGroupPermissions ) : void
windowsGroupPermissions List
return void
Ejemplo n.º 1
0
        public void ClientSecurityService_PermissionsModified_NewPermissionsReceived_ShouldReplaceCurrentPermissions()
        {
            //------------Setup for test--------------------------
            var             connection     = new Mock <IEnvironmentConnection>();
            IEventPublisher eventPublisher = new EventPublisher();

            connection.Setup(c => c.ServerEvents).Returns(eventPublisher);
            var clientSecurityService = new TestClientSecurityService(connection.Object);
            var currentPermissions    = new List <WindowsGroupPermission>();
            var resourceID            = Guid.NewGuid();

            var resourcePermission = new WindowsGroupPermission();

            resourcePermission.ResourceID  = resourceID;
            resourcePermission.Permissions = Permissions.View & Permissions.Execute;

            var serverPermission = new WindowsGroupPermission();

            serverPermission.ResourceID  = Guid.Empty;
            serverPermission.Permissions = Permissions.DeployFrom & Permissions.DeployTo;
            serverPermission.IsServer    = true;

            currentPermissions.Add(serverPermission);
            currentPermissions.Add(resourcePermission);
            clientSecurityService.SetCurrentPermissions(currentPermissions);
            clientSecurityService.ReadAsync().Wait();

            var changedPermissions = new List <WindowsGroupPermission>();

            var changedResourcePermission = new WindowsGroupPermission();

            changedResourcePermission.ResourceID  = resourceID;
            changedResourcePermission.Permissions = Permissions.Contribute;

            var changedServerPermission = new WindowsGroupPermission();

            changedServerPermission.ResourceID  = Guid.Empty;
            changedServerPermission.Permissions = Permissions.Administrator;
            changedServerPermission.IsServer    = true;

            changedPermissions.Add(changedServerPermission);
            changedPermissions.Add(changedResourcePermission);

            var permissionsModifiedMemo = new PermissionsModifiedMemo();

            permissionsModifiedMemo.ModifiedPermissions = changedPermissions;
            //------------Execute Test---------------------------
            connection.Raise(environmentConnection => environmentConnection.PermissionsModified += null, null, changedPermissions);
            eventPublisher.Publish(permissionsModifiedMemo);
            //------------Assert Results-------------------------
            var updateResourcePermission = clientSecurityService.Permissions.FirstOrDefault(permission => permission.ResourceID == resourceID);
            var updateServerPermission   = clientSecurityService.Permissions.FirstOrDefault(permission => permission.ResourceID == Guid.Empty);

            Assert.IsNotNull(updateResourcePermission);
            Assert.IsNotNull(updateServerPermission);
            Assert.AreEqual(Permissions.Contribute, updateResourcePermission.Permissions);
            Assert.AreEqual(Permissions.Administrator, updateServerPermission.Permissions);
        }
        public void ClientSecurityService_PermissionsModified_NewPermissionsReceived_ShouldReplaceCurrentPermissions()
        {
            //------------Setup for test--------------------------
            var connection = new Mock<IEnvironmentConnection>();
            IEventPublisher eventPublisher = new EventPublisher();
            connection.Setup(c => c.ServerEvents).Returns(eventPublisher);
            var clientSecurityService = new TestClientSecurityService(connection.Object);
            var currentPermissions = new List<WindowsGroupPermission>();
            Guid resourceID = Guid.NewGuid();

            var resourcePermission = new WindowsGroupPermission();
            resourcePermission.ResourceID = resourceID;
            resourcePermission.Permissions = Permissions.View & Permissions.Execute;

            var serverPermission = new WindowsGroupPermission();
            serverPermission.ResourceID = Guid.Empty;
            serverPermission.Permissions = Permissions.DeployFrom & Permissions.DeployTo;
            serverPermission.IsServer = true;

            currentPermissions.Add(serverPermission);
            currentPermissions.Add(resourcePermission);
            clientSecurityService.SetCurrentPermissions(currentPermissions);
            clientSecurityService.ReadAsync().Wait();

            var changedPermissions = new List<WindowsGroupPermission>();

            var changedResourcePermission = new WindowsGroupPermission();
            changedResourcePermission.ResourceID = resourceID;
            changedResourcePermission.Permissions = Permissions.Contribute;

            var changedServerPermission = new WindowsGroupPermission();
            changedServerPermission.ResourceID = Guid.Empty;
            changedServerPermission.Permissions = Permissions.Administrator;
            changedServerPermission.IsServer = true;

            changedPermissions.Add(changedServerPermission);
            changedPermissions.Add(changedResourcePermission);

            var permissionsModifiedMemo = new PermissionsModifiedMemo();
            permissionsModifiedMemo.ModifiedPermissions = changedPermissions;
            //------------Execute Test---------------------------
            connection.Raise(environmentConnection => environmentConnection.PermissionsModified += null, null,changedPermissions);
            eventPublisher.Publish(permissionsModifiedMemo);
            //------------Assert Results-------------------------
            var updateResourcePermission = clientSecurityService.Permissions.FirstOrDefault(permission => permission.ResourceID == resourceID);
            var updateServerPermission = clientSecurityService.Permissions.FirstOrDefault(permission => permission.ResourceID == Guid.Empty);
            Assert.IsNotNull(updateResourcePermission);
            Assert.IsNotNull(updateServerPermission);
            Assert.AreEqual(Permissions.Contribute, updateResourcePermission.Permissions);
            Assert.AreEqual(Permissions.Administrator, updateServerPermission.Permissions);
        }