public void PermissionsModifiedMemo_Constructor_Initializes_Properties  ()
        {
            //------------Setup for test--------------------------
            
            //------------Execute Test---------------------------
            var permissionsModifiedMemo = new PermissionsModifiedMemo();

            //------------Assert Results-------------------------
            Assert.IsNotNull(permissionsModifiedMemo.ModifiedPermissions);

        }
        public void EnvironmentTreeViewModel_PermissionsChanged_MemoIDEqualsEnvironmentServerId_UserPermissionChangesNonLocalHost()
        {
            //------------Setup for test--------------------------


            var resourceID = Guid.NewGuid();
            //var connectionServerId = Guid.NewGuid();
            var memoServerID = Guid.NewGuid();

            var pubMemo = new PermissionsModifiedMemo { ServerID = memoServerID };

            pubMemo.ModifiedPermissions.Add(new WindowsGroupPermission { ResourceID = resourceID, Permissions = Permissions.Execute });
            pubMemo.ModifiedPermissions.Add(new WindowsGroupPermission { ResourceID = resourceID, Permissions = Permissions.DeployTo });

            var eventPublisher = new EventPublisher();
            var connection = new Mock<IEnvironmentConnection>();
            connection.Setup(e => e.ServerEvents).Returns(eventPublisher);
            connection.SetupGet(c => c.ServerID).Returns(memoServerID);

            var srepo = new Mock<IStudioResourceRepository>();
            var repo = new Mock<IResourceRepository>();
#pragma warning disable 168
            var environment = new EnvironmentModel(Guid.NewGuid(), connection.Object, repo.Object, srepo.Object) { Name = "localhost" };
            connection.Raise(environmentConnection => environmentConnection.NetworkStateChanged += null, new NetworkStateEventArgs(NetworkState.Offline, NetworkState.Online));
#pragma warning restore 168
            connection.Setup(a => a.DisplayName).Returns("bob");
            //------------Execute Test---------------------------
            eventPublisher.Publish(pubMemo);
            srepo.Verify(a => a.UpdateRootAndFoldersPermissions(It.IsAny<Permissions>(), It.IsAny<Guid>(), true), Times.Never());
        }
        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);
        }