public override void ExecuteCmdlet() { CollectionVmsListResult vmList = null; ActiveDirectoryConfigResult adConfig = null; adConfig = CallClient(() => Client.Collections.GetAd(CollectionName), Client.Collections); vmList = CallClient(() => Client.Collections.ListVms(CollectionName), Client.Collections); if ((vmList != null) && (vmList.Vms != null) && (adConfig != null) && (adConfig.ActiveDirectoryConfig != null)) { IList <DirectoryEntry> staleEntries = GetVmAdStaleEntries(vmList.Vms, adConfig.ActiveDirectoryConfig, Credential); foreach (DirectoryEntry staleEntry in staleEntries) { string staleEntryCN = ActiveDirectoryHelper.GetCN(staleEntry); string shouldProcessMessage = String.Format(Commands_RemoteApp.GenericDeleteConfirmation, staleEntryCN); string verboseDescription = String.Format(Commands_RemoteApp.GenericDeleteVerboseDescription, staleEntryCN); if (ShouldProcess(verboseDescription, shouldProcessMessage, null)) { WriteVerbose(String.Format(Commands_RemoteApp.GenericVerboseDelete, staleEntryCN)); ActiveDirectoryHelper.DeleteEntry(staleEntry); WriteObject(staleEntryCN); } else { WriteVerbose(String.Format(Commands_RemoteApp.GenericVerboseSkip, staleEntryCN)); } } } }
private RemoteAppVm GetVm(string collectionName, string userUpn) { CollectionVmsListResult response = null; response = CallClient(() => Client.Collections.ListVms(collectionName), Client.Collections); if (response != null && response.Vms != null) { foreach (RemoteAppVm vm in response.Vms) { if (vm != null && vm.LoggedOnUserUpns != null) { foreach (string user in vm.LoggedOnUserUpns) { if (string.Compare(user, userUpn, true) == 0) { return(vm); } } } } } return(null); }
public override void ExecuteCmdlet() { CollectionVmsListResult response = null; response = CallClient(() => Client.Collections.ListVms(CollectionName), Client.Collections); if (response != null && response.Vms != null) { WriteObject(response.Vms); } }
public void CanRestartVm() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); RemoteAppManagementClient client = GetRemoteAppManagementClient(); CollectionListResult collectionList = null; Assert.DoesNotThrow(() => { collectionList = client.Collections.List(); }); Assert.NotNull(collectionList); Assert.NotEmpty(collectionList.Collections); foreach (Collection collection in collectionList.Collections) { CollectionVmsListResult vmsList = null; Assert.DoesNotThrow(() => { vmsList = client.Collections.ListVms(collection.Name); }); Assert.NotNull(vmsList); Assert.NotEmpty(vmsList.Vms); Assert.DoesNotThrow(() => { RestartVmCommandParameter restartParam = new RestartVmCommandParameter(); restartParam.VirtualMachineName = vmsList.Vms[0].VirtualMachineName; restartParam.LogoffMessage = "You will be logged off after 2 minutes"; restartParam.LogoffWaitTimeInSeconds = 120; OperationResultWithTrackingId restartResult = client.Collections.RestartVm(collection.Name, restartParam); Assert.True(restartResult.StatusCode == HttpStatusCode.OK); Assert.NotNull(restartResult.TrackingId); }); break; } } }
public static int SetUpDefaultRemoteAppVm(Mock <IRemoteAppManagementClient> clientMock, string collectionName, string vmName, string userUpn, string trackingId) { CollectionVmsListResult response = new CollectionVmsListResult(); OperationResultWithTrackingId restartResponse = new OperationResultWithTrackingId() { StatusCode = System.Net.HttpStatusCode.Accepted, TrackingId = trackingId, RequestId = "111-2222-4444" }; response.Vms = new List <RemoteAppVm>() { new RemoteAppVm() { VirtualMachineName = vmName, LoggedOnUserUpns = { userUpn, "*****@*****.**" } }, new RemoteAppVm() { VirtualMachineName = "testVm2", LoggedOnUserUpns = { "*****@*****.**" } } }; mockVmList = new List <RemoteAppVm>(); foreach (RemoteAppVm vm in response.Vms) { RemoteAppVm mockVm = new RemoteAppVm() { VirtualMachineName = vm.VirtualMachineName, LoggedOnUserUpns = vm.LoggedOnUserUpns }; mockVmList.Add(mockVm); } ISetup <IRemoteAppManagementClient, Task <CollectionVmsListResult> > setup = clientMock.Setup(c => c.Collections.ListVmsAsync(collectionName, It.IsAny <CancellationToken>())); setup.Returns(Task.Factory.StartNew(() => response)); ISetup <IRemoteAppManagementClient, Task <OperationResultWithTrackingId> > setupRestart = clientMock.Setup(c => c.Collections.RestartVmAsync(collectionName, It.IsAny <RestartVmCommandParameter>(), It.IsAny <CancellationToken>())); setupRestart.Returns(Task.Factory.StartNew(() => restartResponse)); return(mockVmList.Count); }
public static int SetUpStaleVmObjectsTest(Mock <IRemoteAppManagementClient> clientMock, string collectionName, string[] vmNames) { CollectionVmsListResult response = new CollectionVmsListResult(); ActiveDirectoryConfigResult getAdResponse = new ActiveDirectoryConfigResult() { ActiveDirectoryConfig = new ActiveDirectoryConfig() { DomainName = "contoso.com", OrganizationalUnit = null, UserName = "******", Password = "******" } }; response.Vms = new List <RemoteAppVm>(); foreach (string vmName in vmNames) { response.Vms.Add(new RemoteAppVm() { VirtualMachineName = vmName, LoggedOnUserUpns = { } }); } ; mockVmList = new List <RemoteAppVm>(); foreach (RemoteAppVm vm in response.Vms) { RemoteAppVm mockVm = new RemoteAppVm() { VirtualMachineName = vm.VirtualMachineName, LoggedOnUserUpns = vm.LoggedOnUserUpns }; mockVmList.Add(mockVm); } ISetup <IRemoteAppManagementClient, Task <CollectionVmsListResult> > setup = clientMock.Setup(c => c.Collections.ListVmsAsync(collectionName, It.IsAny <CancellationToken>())); setup.Returns(Task.Factory.StartNew(() => response)); ISetup <IRemoteAppManagementClient, Task <ActiveDirectoryConfigResult> > setupGetAd = clientMock.Setup(c => c.Collections.GetAdAsync(collectionName, It.IsAny <CancellationToken>())); setupGetAd.Returns(Task.Factory.StartNew(() => getAdResponse)); return(mockVmList.Count); }
public override void ExecuteCmdlet() { CollectionVmsListResult vmList = null; ActiveDirectoryConfigResult adConfig = null; adConfig = CallClient(() => Client.Collections.GetAd(CollectionName), Client.Collections); vmList = CallClient(() => Client.Collections.ListVms(CollectionName), Client.Collections); if (vmList != null && vmList.Vms != null) { IList <DirectoryEntry> staleEntries = GetVmAdStaleEntries(vmList.Vms, adConfig.ActiveDirectoryConfig, Credential); foreach (DirectoryEntry staleEntry in staleEntries) { WriteObject(ActiveDirectoryHelper.GetCN(staleEntry)); } } }
public void CanListVms() { using (UndoContext undoContext = UndoContext.Current) { undoContext.Start(); RemoteAppManagementClient client = GetRemoteAppManagementClient(); CollectionListResult collectionList = null; Assert.DoesNotThrow(() => { collectionList = client.Collections.List(); }); Assert.NotNull(collectionList); Assert.NotEmpty(collectionList.Collections); foreach (Collection collection in collectionList.Collections) { CollectionVmsListResult vmsList = null; Assert.DoesNotThrow(() => { vmsList = client.Collections.ListVms(collection.Name); }); Assert.NotNull(vmsList); Assert.NotEmpty(vmsList.Vms); foreach (RemoteAppVm vm in vmsList.Vms) { Assert.NotNull(vm.VirtualMachineName); Assert.NotNull(vm.LoggedOnUserUpns); } } } }