Inheritance: global::System.ComponentModel.INotifyPropertyChanged
        public void ShouldCreateOneVMRole()
        {
            var mockChannel = new MockRequestChannel();

            var vmRoleToCreate = new VMRole 
            {
                Name = vmRoleName,
                Label = vmRoleLabel
            };

            var vmRoleToReturn = new VMRole
            {
                Name = vmRoleName,
                Label = vmRoleLabel,
            };
            mockChannel.AddReturnObject(vmRoleToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() });

            Guid? jobOut;
            var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel));
            var createdVMRole = vmRoleOperations.Create(cloudServiceName, vmRoleToCreate, out jobOut);

            Assert.NotNull(createdVMRole);
            Assert.Equal(vmRoleToReturn.Name, createdVMRole.Name);
            Assert.Equal(vmRoleToReturn.Label, createdVMRole.Label);

            var requestList = mockChannel.ClientRequests;
            Assert.Equal(1, requestList.Count);
            Assert.Equal(HttpMethod.Post.ToString(), requestList[0].Item1.Method);

            // Check the URI (for Azure consistency)
            Assert.Equal(String.Format(genericBaseUri,cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1));
        }
Ejemplo n.º 2
0
        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 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));
        }