public void ShouldCreateOneCloudService() { var mockChannel = new MockRequestChannel(); var cloudServiceToCreate = new CloudService { Name = cloudServiceName, Label = cloudServiceLabel }; var cloudServiceToReturn = new 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.IsNotNull(createdCloudService); Assert.IsInstanceOfType(createdCloudService, typeof(CloudService)); Assert.AreEqual(cloudServiceToReturn.Name, createdCloudService.Name); Assert.AreEqual(cloudServiceToReturn.Label, createdCloudService.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(baseURI, 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 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() { 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); }