public override void ExecuteCmdlet()
        {
            CollectionUpdateDetails       details  = null;
            OperationResultWithTrackingId response = null;
            Collection collection = null;

            collection = FindCollection(CollectionName);
            if (collection == null)
            {
                return;
            }

            details = new CollectionUpdateDetails()
            {
                TemplateImageName           = ImageName,
                WaitBeforeShutdownInMinutes = ForceLogoffWhenUpdateComplete ? -1 : 0,
                SubnetName = string.IsNullOrEmpty(SubnetName) ? null : SubnetName
            };

            if (ShouldProcess(CollectionName, Commands_RemoteApp.UpdateCollection))
            {
                response = CallClient(() => Client.Collections.Set(CollectionName, true, false, details), Client.Collections);
            }

            if (response != null)
            {
                WriteTrackingId(response);
            }
        }
        public void SetInactiveCollectionAdConfigTest()
        {
            SetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon <SetAzureRemoteAppCollection>();
            string collectionName = "mycol";

            System.Security.SecureString password = new System.Security.SecureString();
            string expectedTrackingId             = "fasdfsadfsdf";
            CollectionUpdateDetails requestData   = null;
            string     userName           = @"MyDomain\Administrator";
            Collection expectedCollection = null;

            // Required parameters for this test
            mockCmdlet.CollectionName = collectionName;
            password.AppendChar('f');
            mockCmdlet.Credential = new PSCredential(userName, password);
            requestData           = new CollectionUpdateDetails()
            {
                AdInfo = new ActiveDirectoryConfig()
                {
                    UserName = userName,
                    Password = "******"
                }
            };

            expectedCollection = new Collection()
            {
                Name   = collectionName,
                Status = "Inactive",
                AdInfo = new ActiveDirectoryConfig()
            };

            PerformCollectionTestWithAdInfoHelper(mockCmdlet, collectionName, expectedCollection, expectedTrackingId, requestData, true);
        }
        private void PerfomrCollectionTestHelper(
            RdsCmdlet mockCmdlet,
            string collectionName,
            Collection expectedCollection,
            String trackingId,
            CollectionUpdateDetails reqestData,
            bool forceRedeploy)
        {
            ISetup <IRemoteAppManagementClient, Task <CollectionResult> > setupGet = null;
            ISetup <IRemoteAppManagementClient, Task <OperationResultWithTrackingId> > setupSetApi = null;
            MockCommandRuntime           cmdRuntime  = null;
            IEnumerable <TrackingResult> trackingIds = null;

            // Setup the environment for testing this cmdlet
            setupGet = remoteAppManagementClientMock.Setup(c => c.Collections.GetAsync(collectionName, It.IsAny <CancellationToken>()));

            setupGet.Returns(Task.Factory.StartNew(
                                 () =>
                                 new CollectionResult()
            {
                Collection = expectedCollection,
                StatusCode = System.Net.HttpStatusCode.OK
            }));

            setupSetApi = remoteAppManagementClientMock.Setup(
                c => c.Collections.SetAsync(
                    collectionName,
                    forceRedeploy,
                    false,
                    It.Is <CollectionUpdateDetails>(col =>
                                                    col.CustomRdpProperty == reqestData.CustomRdpProperty &&
                                                    col.Description == reqestData.Description &&
                                                    col.PlanName == reqestData.PlanName &&
                                                    col.TemplateImageName == reqestData.TemplateImageName &&
                                                    col.AdInfo == null),
                    It.IsAny <CancellationToken>()));
            setupSetApi.Returns(Task.Factory.StartNew(() => new OperationResultWithTrackingId()
            {
                TrackingId = trackingId
            }));

            mockCmdlet.ResetPipelines();

            mockCmdlet.ExecuteCmdlet();

            cmdRuntime = mockCmdlet.runTime();
            if (cmdRuntime.ErrorStream.Count > 0)
            {
                Assert.True(cmdRuntime.ErrorStream.Count == 0,
                            String.Format("Set-AzureRemoteAppCollection returned the following error {0}",
                                          mockCmdlet.runTime().ErrorStream[0].Exception.Message));
            }

            trackingIds = LanguagePrimitives.GetEnumerable(mockCmdlet.runTime().OutputPipeline).Cast <TrackingResult>();
            Assert.NotNull(trackingIds);

            Assert.Equal(1, trackingIds.Count());

            Assert.True(trackingIds.Any(t => t.TrackingId == trackingId), "The actual result does not match the expected.");
        }
        public void SetCollectionPlanTest()
        {
            SetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon <SetAzureRemoteAppCollection>();
            string collectionName               = "mycol";
            string expectedTrackingId           = "2432145";
            CollectionUpdateDetails requestData = null;
            Collection expectedCollection       = null;

            // Required parameters for this test
            mockCmdlet.CollectionName = collectionName;
            mockCmdlet.Plan           = billingPlan;
            requestData = new CollectionUpdateDetails()
            {
                PlanName = mockCmdlet.Plan,
                AdInfo   = null
            };

            expectedCollection = new Collection()
            {
                Name   = collectionName,
                Status = "Active"
            };

            PerfomrCollectionTestHelper(mockCmdlet, collectionName, expectedCollection, expectedTrackingId, requestData, false);
        }
        public void PatchCollectionTest()
        {
            UpdateAzureRemoteAppCollection mockCmdlet = SetUpTestCommon <UpdateAzureRemoteAppCollection>();
            string collectionName               = "mycol";
            string expectedTrackingId           = "2432145";
            String imageName                    = "my template image";
            CollectionUpdateDetails requestData = null;
            Collection expectedCollection       = null;

            // Required parameters for this test
            mockCmdlet.CollectionName = collectionName;
            mockCmdlet.ImageName      = imageName;
            requestData = new CollectionUpdateDetails()
            {
                TemplateImageName = mockCmdlet.ImageName
            };

            expectedCollection = new Collection()
            {
                Name   = collectionName,
                Status = "Active"
            };

            PerfomrCollectionTestHelper(mockCmdlet, collectionName, expectedCollection, expectedTrackingId, requestData, true);
        }
        public void SetCollectionDescriptionTest()
        {
            SetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon <SetAzureRemoteAppCollection>();
            string collectionName               = "mycol";
            string expectedTrackingId           = "213145";
            CollectionUpdateDetails requestData = null;
            Collection expectedCollection       = null;

            // Required parameters for this test
            mockCmdlet.CollectionName = collectionName;
            mockCmdlet.Description    = "This is my test collection";
            requestData = new CollectionUpdateDetails()
            {
                Description = mockCmdlet.Description
            };

            expectedCollection = new Collection()
            {
                Name   = collectionName,
                Status = "Active"
            };

            PerfomrCollectionTestHelper(mockCmdlet, collectionName, expectedCollection, expectedTrackingId, requestData, false);
        }
        public void SetCollectionCustomRdpPropertyTest()
        {
            SetAzureRemoteAppCollection mockCmdlet = SetUpTestCommon <SetAzureRemoteAppCollection>();
            string collectionName               = "mycol";
            string expectedTrackingId           = "fdadffdas";
            CollectionUpdateDetails requestData = null;
            Collection expectedCollection       = null;

            // Required parameters for this test
            mockCmdlet.CollectionName    = collectionName;
            mockCmdlet.CustomRdpProperty = "some:value:*";
            requestData = new CollectionUpdateDetails()
            {
                CustomRdpProperty = mockCmdlet.CustomRdpProperty
            };

            expectedCollection = new Collection()
            {
                Name   = collectionName,
                Status = "Active"
            };

            PerfomrCollectionTestHelper(mockCmdlet, collectionName, expectedCollection, expectedTrackingId, requestData, false);
        }
Пример #8
0
        public override void ExecuteCmdlet()
        {
            NetworkCredential             creds    = null;
            CollectionUpdateDetails       details  = null;
            OperationResultWithTrackingId response = null;
            Collection collection    = null;
            bool       forceRedeploy = false;

            collection = FindCollection(CollectionName);
            if (collection == null)
            {
                return;
            }

            details = new CollectionUpdateDetails();

            if (Credential != null)
            {
                if (collection.AdInfo == null)
                {
                    ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                        Commands_RemoteApp.AadInfoCanNotBeAddedToCloudOnlyCollectionMessage,
                        String.Empty,
                        Client.Collections,
                        ErrorCategory.InvalidArgument);
                    ThrowTerminatingError(er);
                }

                details.AdInfo = new ActiveDirectoryConfig();

                creds = Credential.GetNetworkCredential();
                details.AdInfo.UserName           = Credential.UserName;
                details.AdInfo.Password           = creds.Password;
                details.AdInfo.DomainName         = collection.AdInfo.DomainName;
                details.AdInfo.OrganizationalUnit = collection.AdInfo.OrganizationalUnit;

                if (String.Equals("Inactive", collection.Status, StringComparison.OrdinalIgnoreCase))
                {
                    // the collection may have failed due to bad domain join information before,
                    // re-trying with the new information
                    forceRedeploy = true;
                }
            }
            else if (Plan != null)
            {
                details.PlanName = Plan;
            }
            else if (Description != null)
            {
                details.Description = Description;
            }
            else if (CustomRdpProperty != null)
            {
                details.CustomRdpProperty = CustomRdpProperty;
            }
            else
            {
                ErrorRecord er = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                    "At least one parameter must be set with this cmdlet",
                    String.Empty,
                    Client.Collections,
                    ErrorCategory.InvalidArgument);
                ThrowTerminatingError(er);
            }

            response = CallClient(() => Client.Collections.Set(CollectionName, forceRedeploy, false, details), Client.Collections);
            if (response != null)
            {
                WriteTrackingId(response);
            }
        }
Пример #9
0
 /// <summary>
 /// Sets a new information to the collection with given id.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RemoteApp.ICollectionOperations.
 /// </param>
 /// <param name='collectionName'>
 /// Required. The name of the collection.
 /// </param>
 /// <param name='forceRedeploy'>
 /// Required. A flag denoting if the request is to re-deploy the
 /// collection after it is updated.
 /// </param>
 /// <param name='populateOnly'>
 /// Required. A flag denoting if the request is to populate the
 /// collection details(true for populate only).
 /// </param>
 /// <param name='collectionDetails'>
 /// Required. Details for the collection to be updated.
 /// </param>
 /// <returns>
 /// The response containing the operation tracking id.
 /// </returns>
 public static Task <OperationResultWithTrackingId> SetAsync(this ICollectionOperations operations, string collectionName, bool forceRedeploy, bool populateOnly, CollectionUpdateDetails collectionDetails)
 {
     return(operations.SetAsync(collectionName, forceRedeploy, populateOnly, collectionDetails, CancellationToken.None));
 }
Пример #10
0
 /// <summary>
 /// Sets a new information to the collection with given id.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.RemoteApp.ICollectionOperations.
 /// </param>
 /// <param name='collectionName'>
 /// Required. The name of the collection.
 /// </param>
 /// <param name='forceRedeploy'>
 /// Required. A flag denoting if the request is to re-deploy the
 /// collection after it is updated.
 /// </param>
 /// <param name='populateOnly'>
 /// Required. A flag denoting if the request is to populate the
 /// collection details(true for populate only).
 /// </param>
 /// <param name='collectionDetails'>
 /// Required. Details for the collection to be updated.
 /// </param>
 /// <returns>
 /// The response containing the operation tracking id.
 /// </returns>
 public static OperationResultWithTrackingId Set(this ICollectionOperations operations, string collectionName, bool forceRedeploy, bool populateOnly, CollectionUpdateDetails collectionDetails)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((ICollectionOperations)s).SetAsync(collectionName, forceRedeploy, populateOnly, collectionDetails);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }