public override void ExecuteCmdlet()
        {
            IEnumerable<VMRole> results = null;
            var vmRoleOperations = new VMRoleOperations(this.WebClientFactory);

            if (this.ParameterSetName == WAPackCmdletParameterSets.FromName)
            {
                var vmRole = vmRoleOperations.Read(this.Name, this.Name);
                results = new List<VMRole>() { vmRole };
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService)
            {
                var vmRole = vmRoleOperations.Read(this.CloudServiceName, this.Name);
                results = new List<VMRole>() { vmRole };
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.Empty)
            {
                IEnumerable<CloudService> cloudServiceResults = null;
                var vmRoles = new List<VMRole>();

                var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory);
                cloudServiceResults = cloudServiceOperations.Read();

                foreach (var cloudService in cloudServiceResults)
                {
                    vmRoles.AddRange(vmRoleOperations.Read(cloudService.Name));
                }
                results = vmRoles;
            }

            this.GenerateCmdletOutput(results);
        }
Esempio n. 2
0
        public void ShouldReturnMultipleVMRoleVMs()
        {
            var mockChannel = new MockRequestChannel();
            var vmRole      = new VMRole
            {
                Name  = vmRoleName,
                Label = vmRoleLabel
            };
            var vmList = new List <VM> {
                new VM()
                {
                    Id = Guid.Empty
                }, new VM()
                {
                    Id = Guid.Empty
                }
            };

            vmRole.VMs.Load(vmList);
            mockChannel.AddReturnObject(vmRole);

            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var readVMRole       = vmRoleOperations.Read(cloudServiceName, vmRoleName);

            Assert.Equal(vmRoleName, readVMRole.Name);
            Assert.Equal(vmList.Count, readVMRole.VMs.Count);

            // Check the URI (for Azure consistency)
            var requestList = mockChannel.ClientRequests;

            Assert.Equal(2, requestList.Count);
            Assert.Equal(String.Format(specificBaseUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1));
        }
        public override void ExecuteCmdlet()
        {
            IEnumerable <VMRole> results = null;
            var vmRoleOperations         = new VMRoleOperations(this.WebClientFactory);

            if (this.ParameterSetName == WAPackCmdletParameterSets.FromName)
            {
                var vmRole = vmRoleOperations.Read(this.Name, this.Name);
                results = new List <VMRole>()
                {
                    vmRole
                };
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService)
            {
                var vmRole = vmRoleOperations.Read(this.CloudServiceName, this.Name);
                results = new List <VMRole>()
                {
                    vmRole
                };
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.Empty)
            {
                IEnumerable <CloudService> cloudServiceResults = null;
                var vmRoles = new List <VMRole>();

                var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory);
                cloudServiceResults = cloudServiceOperations.Read();

                foreach (var cloudService in cloudServiceResults)
                {
                    vmRoles.AddRange(vmRoleOperations.Read(cloudService.Name));
                }
                results = vmRoles;
            }

            this.GenerateCmdletOutput(results);
        }
        public void ShouldReturnOneVMRole()
        {
            var mockChannel = new MockRequestChannel();
            mockChannel.AddReturnObject(new VMRole { Name = vmRoleName, Label = vmRoleLabel });

            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            Assert.Equal(1, vmRoleOperations.Read(cloudServiceName).Count);

            // Check the URI (for Azure consistency)
            var requestList = mockChannel.ClientRequests;
            Assert.Equal(2, requestList.Count);
            Assert.Equal(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1));
        }
Esempio n. 5
0
        public void ShouldReturnOneVMRole()
        {
            var mockChannel = new MockRequestChannel();

            mockChannel.AddReturnObject(new VMRole {
                Name = vmRoleName, Label = vmRoleLabel
            });

            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));

            Assert.Equal(1, vmRoleOperations.Read(cloudServiceName).Count);

            // Check the URI (for Azure consistency)
            var requestList = mockChannel.ClientRequests;

            Assert.Equal(2, requestList.Count);
            Assert.Equal(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1));
        }
Esempio n. 6
0
        public void ShouldReturnMultipleVMRole()
        {
            const string vmRoleName01     = "VMRole01";
            const string vmRoleName02     = "VMRole02";
            const string vmRoleLabel01    = "VMRole01-Label";
            const string vmRoleLabel02    = "VMRole02-Label";
            const string cloudServiceName = "CloudService01";

            var mockChannel = new MockRequestChannel();
            var vmRoles     = new List <object>
            {
                new VMRole {
                    Name = vmRoleName01, Label = vmRoleLabel01
                },
                new VMRole {
                    Name = vmRoleName02, Label = vmRoleLabel02
                }
            };

            mockChannel.AddReturnObject(vmRoles);

            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var vmRoleList       = vmRoleOperations.Read(cloudServiceName);

            Assert.Equal(vmRoles.Count, vmRoleList.Count);
            Assert.True(vmRoleList[0].Name == vmRoleName01);
            Assert.True(vmRoleList[1].Name == vmRoleName02);

            // Check the URI (for Azure consistency)
            var requestList = mockChannel.ClientRequests;

            Assert.Equal(3, requestList.Count);
            Assert.Equal(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName01), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName02), mockChannel.ClientRequests[2].Item1.Address.AbsolutePath.Substring(1));
        }
 public void ShouldReturnEmptyOnNoResult()
 {
     var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), MockRequestChannel.Create()));
     Assert.False(vmRoleOperations.Read().Any());
 }
        public void ShouldReturnMultipleVMRoleVMs()
        {
            var mockChannel = new MockRequestChannel();
            var vmRole = new VMRole 
            {
                Name = vmRoleName,
                Label = vmRoleLabel
            };
            var vmList = new List<VM> { new VM() { Id = Guid.Empty }, new VM() { Id = Guid.Empty } };
            vmRole.VMs.Load(vmList);
            mockChannel.AddReturnObject(vmRole);

            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var readVMRole = vmRoleOperations.Read(cloudServiceName, vmRoleName);
            Assert.Equal(vmRoleName, readVMRole.Name);
            Assert.Equal(vmList.Count, readVMRole.VMs.Count);

            // Check the URI (for Azure consistency)
            var requestList = mockChannel.ClientRequests;
            Assert.Equal(2, requestList.Count);
            Assert.Equal(String.Format(specificBaseUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1));
        }
        public void ShouldReturnMultipleVMRole()
        {
            const string vmRoleName01 = "VMRole01";
            const string vmRoleName02 = "VMRole02";
            const string vmRoleLabel01 = "VMRole01-Label";
            const string vmRoleLabel02 = "VMRole02-Label";
            const string cloudServiceName = "CloudService01";

            var mockChannel = new MockRequestChannel();
            var vmRoles = new List<object>
            {
                new VMRole { Name = vmRoleName01, Label = vmRoleLabel01 },
                new VMRole { Name = vmRoleName02, Label = vmRoleLabel02 }
            };
            mockChannel.AddReturnObject(vmRoles);

            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var vmRoleList = vmRoleOperations.Read(cloudServiceName);

            Assert.Equal(vmRoles.Count, vmRoleList.Count);
            Assert.True(vmRoleList[0].Name == vmRoleName01);
            Assert.True(vmRoleList[1].Name == vmRoleName02);

            // Check the URI (for Azure consistency)
            var requestList = mockChannel.ClientRequests;
            Assert.Equal(3, requestList.Count);
            Assert.Equal(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName01), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1));
            Assert.Equal(String.Format(vmsUri, cloudServiceName, vmRoleName02), mockChannel.ClientRequests[2].Item1.Address.AbsolutePath.Substring(1));
        }
        public override void ExecuteCmdlet()
        {
            Guid?  vmRolejobId           = Guid.Empty;
            VMRole createdVmRole         = null;
            IEnumerable <VMRole> results = null;

            var vmRoleOperations = new VMRoleOperations(this.WebClientFactory);
            var newVMRole        = new VMRole()
            {
                Name  = this.Name,
                Label = this.Label,
                ResourceDefinition    = this.ResourceDefinition,
                InstanceView          = null,
                ResourceConfiguration = null,
                ProvisioningState     = null,
                Substate = null,
            };

            if (this.ParameterSetName == WAPackCmdletParameterSets.QuickCreate)
            {
                var cloudService = new Utilities.WAPackIaaS.DataContract.CloudService()
                {
                    Name  = this.Name,
                    Label = this.Label
                };

                Guid?cloudServiceJobId      = Guid.Empty;
                var  cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory);
                cloudServiceOperations.Create(cloudService, out cloudServiceJobId);
                WaitForJobCompletion(cloudServiceJobId);

                try
                {
                    createdVmRole = vmRoleOperations.Create(this.Name, newVMRole, out vmRolejobId);
                    WaitForJobCompletion(vmRolejobId);

                    var vmRole = vmRoleOperations.Read(this.Name, this.Name);
                    results = new List <VMRole>()
                    {
                        vmRole
                    };
                }
                catch (Exception)
                {
                    cloudServiceOperations.Delete(this.Name, out cloudServiceJobId);
                    WaitForJobCompletion(cloudServiceJobId);
                    throw;
                }
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService)
            {
                createdVmRole = vmRoleOperations.Create(this.CloudService.Name, newVMRole, out vmRolejobId);
                WaitForJobCompletion(vmRolejobId);

                var vmRole = vmRoleOperations.Read(this.CloudService.Name, this.Name);
                results = new List <VMRole>()
                {
                    vmRole
                };
            }

            this.GenerateCmdletOutput(results);
        }
        public override void ExecuteCmdlet()
        {
            Guid? vmRolejobId = Guid.Empty;
            VMRole createdVmRole = null;
            IEnumerable<VMRole> results = null;

            var vmRoleOperations = new VMRoleOperations(this.WebClientFactory);
            var newVMRole = new VMRole()
            {
                Name = this.Name,
                Label = this.Label,
                ResourceDefinition = this.ResourceDefinition,
                InstanceView = null,
                ResourceConfiguration = null,
                ProvisioningState = null,
                Substate = null,
            };

            if (this.ParameterSetName == WAPackCmdletParameterSets.QuickCreate)
            {
                var cloudService = new Utilities.WAPackIaaS.DataContract.CloudService()
                {
                    Name = this.Name,
                    Label = this.Label
                };

                Guid? cloudServiceJobId = Guid.Empty;
                var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory);
                cloudServiceOperations.Create(cloudService, out cloudServiceJobId);
                WaitForJobCompletion(cloudServiceJobId);

                try
                {
                    createdVmRole = vmRoleOperations.Create(this.Name, newVMRole, out vmRolejobId);
                    WaitForJobCompletion(vmRolejobId);

                    var vmRole = vmRoleOperations.Read(this.Name, this.Name);
                    results = new List<VMRole>() { vmRole };
                }
                catch (Exception)
                {
                    cloudServiceOperations.Delete(this.Name, out cloudServiceJobId);
                    WaitForJobCompletion(cloudServiceJobId);
                    throw;
                }
            }
            else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService)
            {
                createdVmRole = vmRoleOperations.Create(this.CloudService.Name, newVMRole, out vmRolejobId);
                WaitForJobCompletion(vmRolejobId);

                var vmRole = vmRoleOperations.Read(this.CloudService.Name, this.Name);
                results = new List<VMRole>() { vmRole };
            }

            this.GenerateCmdletOutput(results);
        }
Esempio n. 12
0
        public void ShouldReturnEmptyOnNoResult()
        {
            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), MockRequestChannel.Create()));

            Assert.False(vmRoleOperations.Read().Any());
        }