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 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)); }
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? jobId = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); vmRoleOperations.SetInstanceCount(this.VMRole.Name, this.VMRole, this.InstanceCount, out jobId); var jobInfo = WaitForJobCompletion(jobId); if (this.PassThru) { WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed); } }
public override void ExecuteCmdlet() { Guid?jobId = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); vmRoleOperations.SetInstanceCount(this.VMRole.Name, this.VMRole, this.InstanceCount, out jobId); var jobInfo = WaitForJobCompletion(jobId); if (this.PassThru) { WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed); } }
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)); }
public override void ExecuteCmdlet() { IEnumerable<Utilities.WAPackIaaS.DataContract.CloudService> results = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); if (this.ParameterSetName == WAPackCmdletParameterSets.FromName) { var cloudService = cloudServiceOperations.Read(this.Name); results = new List<Utilities.WAPackIaaS.DataContract.CloudService>() { cloudService }; } else if (this.ParameterSetName == WAPackCmdletParameterSets.Empty) { results = cloudServiceOperations.Read(); } this.GenerateCmdletOutput(results); }
public override void ExecuteCmdlet() { IEnumerable <Utilities.WAPackIaaS.DataContract.CloudService> results = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); if (this.ParameterSetName == WAPackCmdletParameterSets.FromName) { var cloudService = cloudServiceOperations.Read(this.Name); results = new List <Utilities.WAPackIaaS.DataContract.CloudService>() { cloudService }; } else if (this.ParameterSetName == WAPackCmdletParameterSets.Empty) { results = cloudServiceOperations.Read(); } this.GenerateCmdletOutput(results); }
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 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.IsNotNull(createdVMRole); Assert.IsInstanceOfType(createdVMRole, typeof(VMRole)); Assert.AreEqual(vmRoleToReturn.Name, createdVMRole.Name); Assert.AreEqual(vmRoleToReturn.Label, createdVMRole.Label); var requestList = mockChannel.ClientRequests; Assert.AreEqual(1, requestList.Count); Assert.AreEqual(HttpMethod.Post.ToString(), requestList[0].Item1.Method); // Check the URI (for Azure consistency) Assert.AreEqual(String.Format(genericBaseUri, cloudServiceName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public override void ExecuteCmdlet() { ConfirmAction( Force.IsPresent, string.Format(Resources.RemoveVMRoleConfirmationMessage, VMRole.Name), string.Format(Resources.RemoveVMRoleMessage), VMRole.Name, () => { JobInfo jobInfo = null; Guid? vmRoleJobId = null; Guid? cloudJobId = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); if (this.ParameterSetName == WAPackCmdletParameterSets.FromVMRoleObject) { vmRoleOperations.Delete(VMRole.Name, VMRole.Name, out vmRoleJobId); jobInfo = WaitForJobCompletion(vmRoleJobId); // If no CloudService name is given, we assume the VMRole was created using WAP // in which case the CloudService name is the same as the VMRole name var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); cloudServiceOperations.Delete(VMRole.Name, out cloudJobId); WaitForJobCompletion(vmRoleJobId); } else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService) { vmRoleOperations.Delete(this.CloudServiceName, VMRole.Name, out vmRoleJobId); jobInfo = WaitForJobCompletion(vmRoleJobId); } if (this.PassThru) { WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed); } }); }
public override void ExecuteCmdlet() { ConfirmAction( Force.IsPresent, string.Format(Resources.RemoveVMRoleConfirmationMessage, VMRole.Name), string.Format(Resources.RemoveVMRoleMessage), VMRole.Name, () => { JobInfo jobInfo = null; Guid?vmRoleJobId = null; Guid?cloudJobId = null; var vmRoleOperations = new VMRoleOperations(this.WebClientFactory); if (this.ParameterSetName == WAPackCmdletParameterSets.FromVMRoleObject) { vmRoleOperations.Delete(VMRole.Name, VMRole.Name, out vmRoleJobId); jobInfo = WaitForJobCompletion(vmRoleJobId); // If no CloudService name is given, we assume the VMRole was created using WAP // in which case the CloudService name is the same as the VMRole name var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); cloudServiceOperations.Delete(VMRole.Name, out cloudJobId); WaitForJobCompletion(vmRoleJobId); } else if (this.ParameterSetName == WAPackCmdletParameterSets.FromCloudService) { vmRoleOperations.Delete(this.CloudServiceName, VMRole.Name, out vmRoleJobId); jobInfo = WaitForJobCompletion(vmRoleJobId); } if (this.PassThru) { WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed); } }); }
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 ShouldDeleteVMRole() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new VMRole { Name = vmRoleName, Label = vmRoleLabel }, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid?jobOut; var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel)); vmRoleOperations.Delete(cloudServiceName, vmRoleName, out jobOut); Assert.Equal(mockChannel.ClientRequests.Count, 1); Assert.Equal(HttpMethod.Delete.ToString(), mockChannel.ClientRequests[0].Item1.Method); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(String.Format(specificBaseUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[0].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 ShouldDeleteVMRole() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new VMRole { Name = vmRoleName, Label = vmRoleLabel }, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel)); vmRoleOperations.Delete(cloudServiceName, vmRoleName, out jobOut); Assert.Equal(mockChannel.ClientRequests.Count, 1); Assert.Equal(HttpMethod.Delete.ToString(), mockChannel.ClientRequests[0].Item1.Method); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(String.Format(specificBaseUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
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); }