Ejemplo n.º 1
0
        public static int SetUpDefaultRemoteAppCollection(Mock<IRemoteAppManagementClient> clientMock, string collectionName)
        {
            CollectionListResult response = new CollectionListResult();
            response.Collections = new List<Collection>()
            {
                new Collection()
                {
                    Name = collectionName,
                    Region = "West US",
                    Status = "Active"
                },

                new Collection()
                {
                    Name = "test2",
                    Region = "West US",
                    Status = "Active"
                }
            };

            mockCollectionList = new List<Collection>();
            foreach (Collection collection in response.Collections)
            {
                Collection mockCollection = new Collection()
                {
                    Name = collection.Name,
                    Region = collection.Region,
                    Status = collection.Status
                };
                mockCollectionList.Add(mockCollection);
            }

            ISetup<IRemoteAppManagementClient, Task<CollectionListResult>> setup = clientMock.Setup(c => c.Collections.ListAsync(It.IsAny<CancellationToken>()));
            setup.Returns(Task.Factory.StartNew(() => response));

            return mockCollectionList.Count;
        }
Ejemplo n.º 2
0
 public Collection(Microsoft.Azure.Management.RemoteApp.Models.Collection col)
 {
     AdInfo                  = col.AdInfo;
     BillingPlanName         = col.BillingPlanName;
     Type                    = col.Type;
     CustomRdpProperty       = col.CustomRdpProperty;
     Description             = col.Description;
     DnsServers              = col.DnsServers;
     LastErrorCode           = col.LastErrorCode;
     LastModifiedTimeUtc     = col.LastModifiedTimeUtc;
     LastModifiedLocalTime   = col.LastModifiedTimeUtc.ToLocalTime();
     MaxSessions             = col.MaxSessions;
     Mode                    = col.Mode;
     Name                    = col.Name;
     OfficeType              = col.OfficeType;
     ReadyForPublishing      = col.ReadyForPublishing;
     Region                  = col.Region;
     SessionWarningThreshold = col.SessionWarningThreshold;
     Status                  = col.Status;
     SubnetName              = col.SubnetName;
     TemplateImageName       = col.TemplateImageName;
     TrialOnly               = col.TrialOnly;
     VnetName                = String.IsNullOrWhiteSpace(col.VnetName) || col.VnetName.StartsWith("simplevnet-") ? "" : col.VnetName;
 }
        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);
        }
Ejemplo n.º 4
0
        public static bool ContainsExpectedCollection(List<Collection> expectedResult, Collection actual)
        {
            bool isIdentical = false;
            foreach (Collection expected in expectedResult)
            {
                isIdentical = expected.Name == actual.Name;
                isIdentical &= expected.Region == actual.Region;
                isIdentical &= expected.Status == actual.Status;
                if (isIdentical)
                {
                    break;
                }
            }

            return isIdentical;
        }
        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 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);
        }
        public void SetCollection()
        {
            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);
        }