public void ShouldCreateOneCloudService() { var mockChannel = new MockRequestChannel(); var cloudServiceToCreate = new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }; var cloudServiceToReturn = new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel, }; mockChannel.AddReturnObject(cloudServiceToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid?jobOut; var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); var createdCloudService = cloudServiceOperations.Create(cloudServiceToCreate, out jobOut); Assert.NotNull(createdCloudService); Assert.True(createdCloudService is Commands.Utilities.WAPackIaaS.DataContract.CloudService); Assert.Equal(cloudServiceToReturn.Name, createdCloudService.Name); Assert.Equal(cloudServiceToReturn.Label, createdCloudService.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(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldCreateOneCloudService() { var mockChannel = new MockRequestChannel(); var cloudServiceToCreate = new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }; var cloudServiceToReturn = new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel, }; mockChannel.AddReturnObject(cloudServiceToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); var createdCloudService = cloudServiceOperations.Create(cloudServiceToCreate, out jobOut); Assert.NotNull(createdCloudService); Assert.True(createdCloudService is Commands.Utilities.WAPackIaaS.DataContract.CloudService); Assert.Equal(cloudServiceToReturn.Name, createdCloudService.Name); Assert.Equal(cloudServiceToReturn.Label, createdCloudService.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(baseURI, mockChannel.ClientRequests[0].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 ShouldReturnMultipleCloudServices() { var mockChannel = new MockRequestChannel(); var cldList = new List <object> { new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }, new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel } }; mockChannel.AddReturnObject(cldList); mockChannel.AddReturnObject(new CloudResource()).AddReturnObject(new VMRole { Name = "VMRole01", Label = "VMRole01-Label" }).AddReturnObject(new VM { }); mockChannel.AddReturnObject(new CloudResource()).AddReturnObject(new VMRole { Name = "VMRole01", Label = "VMRole01-Label" }).AddReturnObject(new VM { }); var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); var cloudServiceList = cloudServiceOperations.Read(); Assert.Equal(2, cloudServiceList.Count); Assert.True(cloudServiceList.All(cloudService => cloudService.Name == cloudServiceName)); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(7, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldReturnOneCloudService() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }); mockChannel.AddReturnObject(new CloudResource()); var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); Assert.Equal(1, cloudServiceOperations.Read().Count); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(3, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public override void ExecuteCmdlet() { 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); var createdCloudService = cloudServiceOperations.Read(this.Name); var results = new List<Utilities.WAPackIaaS.DataContract.CloudService>() { createdCloudService }; 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 void ShouldReturnOneCloudServiceByName() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new CloudService { Name = cloudServiceName, Label = cloudServiceLabel }); mockChannel.AddReturnObject(new CloudResource()); var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); Assert.AreEqual(cloudServiceName, cloudServiceOperations.Read(cloudServiceName).Name); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.AreEqual(3, requestList.Count); Assert.AreEqual(baseURI + "/" + cloudServiceName, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldReturnOneCloudService() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }); mockChannel.AddReturnObject(new CloudResource()); var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); Assert.Equal(1, cloudServiceOperations.Read().Count); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(3, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].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() { ConfirmAction( Force.IsPresent, string.Format(Resources.RemoveCloudServiceConfirmationMessage, CloudService.Name), string.Format(Resources.RemoveCloudServiceMessage), CloudService.Name, () => { Guid?cloudServiceJobId = null; var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); var deletedCloudService = cloudServiceOperations.Read(CloudService.Name); cloudServiceOperations.Delete(CloudService.Name, out cloudServiceJobId); var jobInfo = WaitForJobCompletion(cloudServiceJobId); if (this.PassThru) { WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed); } }); }
public override void ExecuteCmdlet() { ConfirmAction( Force.IsPresent, string.Format(Resources.RemoveCloudServiceConfirmationMessage, CloudService.Name), string.Format(Resources.RemoveCloudServiceMessage), CloudService.Name, () => { Guid? cloudServiceJobId = null; var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); var deletedCloudService = cloudServiceOperations.Read(CloudService.Name); cloudServiceOperations.Delete(CloudService.Name, out cloudServiceJobId); var jobInfo = WaitForJobCompletion(cloudServiceJobId); if (this.PassThru) { WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed); } }); }
public override void ExecuteCmdlet() { var cloudService = new CloudService() { Name = this.Name, Label = this.Label }; Guid?cloudServiceJobId = Guid.Empty; var cloudServiceOperations = new CloudServiceOperations(this.WebClientFactory); cloudServiceOperations.Create(cloudService, out cloudServiceJobId); WaitForJobCompletion(cloudServiceJobId); var createdCloudService = cloudServiceOperations.Read(this.Name); var results = new List <CloudService>() { createdCloudService }; 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 ShouldDeleteCloudService() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid?jobOut; var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); cloudServiceOperations.Delete(cloudServiceName, out jobOut); var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(HttpMethod.Delete.ToString(), requestList[0].Item1.Method); // Check the URI (for Azure consistency) Assert.Equal(baseURI + "/" + 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 ShouldReturnOneCloudServiceByName() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new CloudService { Name = cloudServiceName, Label = cloudServiceLabel }); mockChannel.AddReturnObject(new CloudResource()); var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); Assert.AreEqual(cloudServiceName, cloudServiceOperations.Read(cloudServiceName).Name); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.AreEqual(3, requestList.Count); Assert.AreEqual(baseURI + "/" + 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? 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 ShouldReturnMultipleCloudServices() { var mockChannel = new MockRequestChannel(); var cldList = new List<object> { new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }, new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel } }; mockChannel.AddReturnObject(cldList); mockChannel.AddReturnObject(new CloudResource()).AddReturnObject(new VMRole { Name = "VMRole01", Label = "VMRole01-Label" }).AddReturnObject(new VM {}); mockChannel.AddReturnObject(new CloudResource()).AddReturnObject(new VMRole { Name = "VMRole01", Label = "VMRole01-Label" }).AddReturnObject(new VM {}); var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); var cloudServiceList = cloudServiceOperations.Read(); Assert.Equal(2, cloudServiceList.Count); Assert.True(cloudServiceList.All(cloudService => cloudService.Name == cloudServiceName)); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.Equal(7, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldDeleteCloudService() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new Commands.Utilities.WAPackIaaS.DataContract.CloudService { Name = cloudServiceName, Label = cloudServiceLabel }, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), mockChannel)); cloudServiceOperations.Delete(cloudServiceName, out jobOut); var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(HttpMethod.Delete.ToString(), requestList[0].Item1.Method); // Check the URI (for Azure consistency) Assert.Equal(baseURI + "/" + cloudServiceName, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldReturnEmptyOnNoResult() { var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), MockRequestChannel.Create())); Assert.False(cloudServiceOperations.Read().Any()); }
public void ShouldReturnEmptyOnNoResult() { var cloudServiceOperations = new CloudServiceOperations(new WebClientFactory(new Subscription(), MockRequestChannel.Create())); Assert.False(cloudServiceOperations.Read().Any()); }