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 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 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 ShouldReturnOneLogicalNetwork() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new LogicalNetwork { ID = Guid.Empty, CloudId = Guid.Empty, Name = logicalNetworkName }); var logicalNetworkOperations = new LogicalNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); Assert.AreEqual(1, logicalNetworkOperations.Read().Count); }
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 void ShouldReturnMultipleLogicalNetworks() { var mockChannel = new MockRequestChannel(); var logicalNetworks = new List<object> { new LogicalNetwork { ID = Guid.Empty, CloudId = Guid.Empty, Name = logicalNetworkName }, new LogicalNetwork { ID = Guid.Empty, CloudId = Guid.Empty, Name = logicalNetworkName } }; mockChannel.AddReturnObject(logicalNetworks); var logicalNetworkOperations = new LogicalNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); var logicalNetworkList = logicalNetworkOperations.Read(); Assert.AreEqual(2, logicalNetworkList.Count); Assert.IsTrue(logicalNetworkList.All(logicalNetwork => logicalNetwork.Name == logicalNetworkName)); }
public void ShouldCreateOneVMNetwork() { Guid VNetLogicalNetworkId = Guid.NewGuid(); Guid StampId= Guid.NewGuid(); var mockChannel = new MockRequestChannel(); var vmNetworkToCreate = new VMNetwork() { Name = vNetName, Description = vNetDescription, LogicalNetworkId = VNetLogicalNetworkId, StampId = StampId, }; var vmNetworkToReturn = new VMNetwork() { Name = vNetName, Description = vNetDescription, LogicalNetworkId = VNetLogicalNetworkId, StampId = StampId, }; mockChannel.AddReturnObject(vmNetworkToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var VMNetworkOperations = new VMNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); var createdVMNetwork = VMNetworkOperations.Create(vmNetworkToCreate, out jobOut); Assert.IsNotNull(createdVMNetwork); Assert.IsInstanceOfType(createdVMNetwork, typeof(VMNetwork)); Assert.AreEqual(vmNetworkToReturn.Name, vmNetworkToCreate.Name); Assert.AreEqual(vmNetworkToReturn.Description, vmNetworkToCreate.Description); Assert.AreEqual(vmNetworkToReturn.LogicalNetworkId, vmNetworkToCreate.LogicalNetworkId); Assert.AreEqual(vmNetworkToReturn.StampId, vmNetworkToCreate.StampId); var requestList = mockChannel.ClientRequests; Assert.AreEqual(1, requestList.Count); Assert.AreEqual(HttpMethod.Post.ToString(), requestList[0].Item1.Method); // Check the URI Assert.AreEqual(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldReturnOneVMRoleByName() { var mockChannel = new MockRequestChannel(); mockChannel.AddReturnObject(new VMRole { Name = vmRoleName, Label = vmRoleLabel }); var vmRoleOperations = new VMRoleOperations(new WebClientFactory(new Subscription(), mockChannel)); Assert.AreEqual(vmRoleName, vmRoleOperations.Read(cloudServiceName, vmRoleName).Name); // Check the URI (for Azure consistency) var requestList = mockChannel.ClientRequests; Assert.AreEqual(2, requestList.Count); Assert.AreEqual(String.Format(specificBaseUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); Assert.AreEqual(String.Format(vmsUri, cloudServiceName, vmRoleName), mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldCreateOneVMSubnet() { var mockChannel = new MockRequestChannel(); var vmSubnetToCreate = new VMSubnet() { Name = vmSubnetName, VMNetworkName = vmNetworkName, VMNetworkId = Guid.Empty, Subnet = subnet, StampId = Guid.Empty }; var vmSubnetToReturn = new VMSubnet() { Name = vmSubnetName, VMNetworkName = vmNetworkName, VMNetworkId = Guid.Empty, Subnet = subnet, StampId = Guid.Empty }; mockChannel.AddReturnObject(vmSubnetToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var vmSubnetOperations = new VMSubnetOperations(new WebClientFactory(new Subscription(), mockChannel)); var createdVMSubnet = vmSubnetOperations.Create(vmSubnetToCreate, out jobOut); Assert.NotNull(createdVMSubnet); Assert.True(createdVMSubnet is VMSubnet); Assert.Equal(vmSubnetToReturn.Name, createdVMSubnet.Name); Assert.Equal(vmSubnetToReturn.VMNetworkName, createdVMSubnet.VMNetworkName); Assert.Equal(vmSubnetToReturn.VMNetworkId, createdVMSubnet.VMNetworkId); Assert.Equal(vmSubnetToReturn.Subnet, createdVMSubnet.Subnet); Assert.Equal(vmSubnetToReturn.StampId, createdVMSubnet.StampId); var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(HttpMethod.Post.ToString(), requestList[0].Item1.Method); // Check the URI Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldCreateOneStaticIPAddressPool() { var mockChannel = new MockRequestChannel(); var staticIPAddressPoolToCreate = new StaticIPAddressPool() { Name = staticIPAddressPoolName, VMSubnetId = Guid.Empty, IPAddressRangeStart = ipAddressRangeStart, IPAddressRangeEnd = ipAddressRangeEnd, StampId = Guid.Empty }; var staticIPAddressPoolToReturn = new StaticIPAddressPool() { Name = staticIPAddressPoolName, IPAddressRangeStart = ipAddressRangeStart, IPAddressRangeEnd = ipAddressRangeEnd, StampId = Guid.Empty }; mockChannel.AddReturnObject(staticIPAddressPoolToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var staticIPAddressPoolOperations = new StaticIPAddressPoolOperations(new WebClientFactory(new Subscription(), mockChannel)); var createdStaticIPAddressPool = staticIPAddressPoolOperations.Create(staticIPAddressPoolToCreate, out jobOut); Assert.NotNull(createdStaticIPAddressPool); Assert.True(createdStaticIPAddressPool is StaticIPAddressPool); Assert.Equal(staticIPAddressPoolToReturn.Name, createdStaticIPAddressPool.Name); Assert.Equal(staticIPAddressPoolToReturn.VMSubnetId, createdStaticIPAddressPool.VMSubnetId); Assert.Equal(staticIPAddressPoolToReturn.IPAddressRangeStart, createdStaticIPAddressPool.IPAddressRangeStart); Assert.Equal(staticIPAddressPoolToReturn.IPAddressRangeEnd, createdStaticIPAddressPool.IPAddressRangeEnd); Assert.Equal(staticIPAddressPoolToReturn.StampId, createdStaticIPAddressPool.StampId); var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(HttpMethod.Post.ToString(), requestList[0].Item1.Method); // Check the URI Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void VmCreateShouldThrowWhenNoObjectReturned() { var mockChannel = new MockRequestChannel(); var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() }; mockChannel.AddReturnObject(testCloud); var vmOps = new VirtualMachineOperations(new WebClientFactory(new Subscription(), mockChannel)); var vmToCreate = new VirtualMachine { VirtualHardDiskId = Guid.NewGuid(), Name = "Test" }; Guid?jobOut; Assert.Throws <WAPackOperationException>(() => vmOps.Create(vmToCreate, out jobOut)); }
public void VmCreateShouldThrowIfNoVhdAndNoTemplateSupplied() { var channel = new MockRequestChannel(); var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() }; channel.AddReturnObject(testCloud); var sub = new Subscription(); var vmOps = new VirtualMachineOperations(new WebClientFactory(sub, channel)); var vmToCreate = new VirtualMachine { Name = "Test" }; Guid?jobOut; Assert.Throws <WAPackOperationException>(() => vmOps.Create(vmToCreate, out jobOut)); }
public void WaitOnJobCompletesImmediately() { // Fix test flakiness TestExecutionHelpers.RetryAction( () => { Guid jobId = Guid.NewGuid(); MockRequestChannel mockChannel = MockRequestChannel.Create(); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = true }); var jobOperations = new JobOperations(new WebClientFactory( new Subscription(), mockChannel)); DateTime start = DateTime.Now; jobOperations.WaitOnJob(jobId); Assert.True((DateTime.Now - start).TotalMilliseconds < 500); }); }
public void ShouldReturnMultipleLogicalNetworks() { var mockChannel = new MockRequestChannel(); var logicalNetworks = new List <object> { new LogicalNetwork { ID = Guid.Empty, CloudId = Guid.Empty, Name = logicalNetworkName }, new LogicalNetwork { ID = Guid.Empty, CloudId = Guid.Empty, Name = logicalNetworkName } }; mockChannel.AddReturnObject(logicalNetworks); var logicalNetworkOperations = new LogicalNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); var logicalNetworkList = logicalNetworkOperations.Read(); Assert.Equal(2, logicalNetworkList.Count); Assert.True(logicalNetworkList.All(logicalNetwork => logicalNetwork.Name == logicalNetworkName)); }
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 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 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 WaitOnJobTimeoutJobNotFinished() { Guid jobId = Guid.NewGuid(); MockRequestChannel mockChannel = MockRequestChannel.Create(); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); mockChannel.AddReturnObject(new Job { Name = "TestJob", ID = jobId, IsCompleted = false, Status = "Running" }); var jobOperations = new JobOperations(new WebClientFactory( new Subscription(), mockChannel)); DateTime start = DateTime.Now; var result = jobOperations.WaitOnJob(jobId, 6000); var diff = (DateTime.Now - start).TotalMilliseconds; Assert.True(diff > 6000); Assert.Equal(JobStatusEnum.OperationTimedOut, result.jobStatus); }
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 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 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 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 DeleteVM() { var sub = new Subscription(); var channel = new MockRequestChannel(); //Response to client getting /Clouds (client needs stampId, gets it from clouds) var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() }; channel.AddReturnObject(testCloud); //Response to the DELETE channel.AddReturnObject(null, new WebHeaderCollection {"x-ms-request-id:" + Guid.NewGuid()}); var vmOps = new VirtualMachineOperations(new WebClientFactory(sub, channel)); Guid toDelete = Guid.NewGuid(); Guid? jobOut; vmOps.Delete(toDelete, out jobOut); //Check the requests the client generated Assert.AreEqual(channel.ClientRequests.Count, 2); Assert.AreEqual(channel.ClientRequests[1].Item1.Method, HttpMethod.Delete.ToString()); }
private static VirtualMachine InitVirtualMachineOperation(MockRequestChannel mockChannel, out VirtualMachineOperations vmOperations) { //Cloud for return value of first request (client gets cloud to get stampId) var testCloud = new Cloud {ID = Guid.NewGuid(), StampId = Guid.NewGuid()}; mockChannel.AddReturnObject(testCloud); //VM for return value of second request (client updates VM with operation) var testVM = new VirtualMachine {ID = Guid.NewGuid(), StampId = testCloud.StampId}; mockChannel.AddReturnObject(testVM, new WebHeaderCollection {"x-ms-request-id:" + Guid.NewGuid()}); var factory = new WebClientFactory(new Subscription(), mockChannel); vmOperations = new VirtualMachineOperations(factory); return testVM; }
public void ShouldDeleteVMSubnet() { const string subnet = "192.168.1.0/24"; const string vmNetworkName = "VNet01"; const string vmSubnetName = "VMSubnet01"; var mockChannel = new MockRequestChannel(); var existingVMSubnet = new VMSubnet() { Name = vmSubnetName, VMNetworkName = vmNetworkName, VMNetworkId = Guid.Empty, Subnet = subnet, StampId = Guid.Empty }; mockChannel.AddReturnObject(new Cloud() { StampId = Guid.NewGuid() }); mockChannel.AddReturnObject(existingVMSubnet, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var vmSubnetOperations = new VMSubnetOperations(new WebClientFactory(new Subscription(), mockChannel)); vmSubnetOperations.Delete(Guid.Empty, out jobOut); Assert.Equal(2, mockChannel.ClientRequests.Count); Assert.Equal(HttpMethod.Delete.ToString(), mockChannel.ClientRequests[1].Item1.Method); // Check the URI var requestURI = mockChannel.ClientRequests[1].Item1.Address.AbsolutePath; Assert.Equal("/Clouds", mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); Assert.Equal(baseURI, mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1).Remove(requestURI.IndexOf('(') - 1)); }
public void VmCreateShouldThrowWhenNoObjectReturned() { var mockChannel = new MockRequestChannel(); var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() }; mockChannel.AddReturnObject(testCloud); var vmOps = new VirtualMachineOperations(new WebClientFactory(new Subscription(), mockChannel)); var vmToCreate = new VirtualMachine { VirtualHardDiskId = Guid.NewGuid(), Name = "Test" }; Guid? jobOut; vmOps.Create(vmToCreate, out jobOut); }
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 ShouldReturnOneVMSubnet() { const string subnet = "192.168.1.0/24"; const string vmNetworkName = "VNet01"; const string vmSubnetName = "VMSubnet01"; var mockChannel = new MockRequestChannel(); var vmSubnetToCreate = new VMSubnet() { Name = vmSubnetName, VMNetworkName = vmNetworkName, VMNetworkId = Guid.Empty, Subnet = subnet, StampId = Guid.Empty }; mockChannel.AddReturnObject(vmSubnetToCreate); var vmSubnetOperations = new VMSubnetOperations(new WebClientFactory(new Subscription(), mockChannel)); var readStaticIPAddressPool = vmSubnetOperations.Read(new VMNetwork() { StampId = Guid.Empty, ID = Guid.Empty }); Assert.Equal(1, readStaticIPAddressPool.Count); // Check the URI var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldReturnOneVMNetworkByID() { var mockChannel = new MockRequestChannel(); var vmNetworkToReturn = new VMNetwork() { Name = vNetName, Description = vNetDescription, LogicalNetworkId = Guid.Empty, StampId = Guid.Empty, }; mockChannel.AddReturnObject(vmNetworkToReturn); var VMNetworkOperations = new VMNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); var readVMNetwork = VMNetworkOperations.Read(Guid.Empty); Assert.Equal(Guid.Empty, readVMNetwork.ID); // Check the URI var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldDeleteStaticVMNetwork() { var mockChannel = new MockRequestChannel(); var existingVmNetwork = new VMNetwork() { Name = vNetName, Description = vNetDescription, LogicalNetworkId = Guid.Empty, StampId = Guid.Empty, }; mockChannel.AddReturnObject(new Cloud() { StampId = Guid.NewGuid() }); mockChannel.AddReturnObject(existingVmNetwork, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var VMNetworkOperations = new VMNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); VMNetworkOperations.Delete(Guid.Empty, out jobOut); Assert.Equal(2, mockChannel.ClientRequests.Count); Assert.Equal(HttpMethod.Delete.ToString(), mockChannel.ClientRequests[1].Item1.Method); // Check the URI var requestURI = mockChannel.ClientRequests[1].Item1.Address.AbsolutePath; Assert.Equal("/Clouds", mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); Assert.Equal(baseURI, mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1).Remove(requestURI.IndexOf('(') - 1)); }
public void ShouldReturnMultipleVMNetworks() { var mockChannel = new MockRequestChannel(); var vmNetworkList = new List<object> { new VMNetwork { Name = vNetName, Description = vNetDescription }, new VMNetwork { Name = vNetName, Description = vNetDescription } }; mockChannel.AddReturnObject(vmNetworkList); var VMNetworkOperations = new VMNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); var readVMNetwork = VMNetworkOperations.Read(); Assert.Equal(2, readVMNetwork.Count); Assert.True(readVMNetwork.All(vmNetwork => vmNetwork.Name == vNetName)); // Check the URI var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldReturnOneStaticIPAddressPool() { var mockChannel = new MockRequestChannel(); var staticIPAddressPoolToCreate = new StaticIPAddressPool() { Name = staticIPAddressPoolName, VMSubnetId = Guid.Empty, IPAddressRangeStart = ipAddressRangeStart, IPAddressRangeEnd = ipAddressRangeEnd, StampId = Guid.Empty }; mockChannel.AddReturnObject(staticIPAddressPoolToCreate); var staticIPAddressPoolOperations = new StaticIPAddressPoolOperations(new WebClientFactory(new Subscription(), mockChannel)); var readStaticIPAddressPool = staticIPAddressPoolOperations.Read(new VMSubnet(){ StampId = Guid.Empty, ID = Guid.Empty }); Assert.Equal(1, readStaticIPAddressPool.Count); // Check the URI var requestList = mockChannel.ClientRequests; Assert.Equal(1, requestList.Count); Assert.Equal(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void ShouldDeleteStaticIPAddressPool() { var mockChannel = new MockRequestChannel(); var existingStaticIPAddressPool = new StaticIPAddressPool() { Name = staticIPAddressPoolName, VMSubnetId = Guid.Empty, IPAddressRangeStart = ipAddressRangeStart, IPAddressRangeEnd = ipAddressRangeEnd, StampId = Guid.Empty }; mockChannel.AddReturnObject(new Cloud() { StampId = Guid.NewGuid() }); mockChannel.AddReturnObject(existingStaticIPAddressPool, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); Guid? jobOut; var staticIPAddressPoolOperations = new StaticIPAddressPoolOperations(new WebClientFactory(new Subscription(), mockChannel)); staticIPAddressPoolOperations.Delete(Guid.Empty, out jobOut); Assert.Equal(2, mockChannel.ClientRequests.Count); Assert.Equal(HttpMethod.Delete.ToString(), mockChannel.ClientRequests[1].Item1.Method); // Check the URI var requestURI = mockChannel.ClientRequests[1].Item1.Address.AbsolutePath; Assert.Equal("/Clouds", mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); Assert.Equal(baseURI, mockChannel.ClientRequests[1].Item1.Address.AbsolutePath.Substring(1).Remove(requestURI.IndexOf('(') - 1)); }
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 CreateVMFromTemplate() { var mockChannel = new MockRequestChannel(); var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() }; mockChannel.AddReturnObject(testCloud); var vmToCreate = new VirtualMachine { VMTemplateId = Guid.NewGuid(), Name = "Test" }; var vmToReturn = new VirtualMachine { ID = Guid.NewGuid(), Name = vmToCreate.Name, CloudId = testCloud.ID, StampId = testCloud.StampId }; mockChannel.AddReturnObject(vmToReturn, new WebHeaderCollection { "x-ms-request-id:" + Guid.NewGuid() }); var vmOps = new VirtualMachineOperations(new WebClientFactory(new Subscription(), mockChannel)); Guid? jobOut; var resultVM = vmOps.Create(vmToCreate, out jobOut); //Check the results that client returns Assert.IsNotNull(resultVM); Assert.IsInstanceOfType(resultVM, typeof(VirtualMachine)); Assert.AreEqual(resultVM.ID, vmToReturn.ID); Assert.AreEqual(resultVM.Name, vmToReturn.Name); Assert.AreEqual(resultVM.CloudId, vmToReturn.CloudId); Assert.AreEqual(resultVM.StampId, vmToReturn.StampId); //Check the requests that the client made var requestList = mockChannel.ClientRequests; Assert.AreEqual(requestList.Count, 2); Assert.AreEqual(requestList[1].Item1.Method, HttpMethod.Post.ToString()); Assert.IsTrue(requestList[1].Item1.RequestUri.ToString().TrimEnd(new[] { '/' }).EndsWith("/VirtualMachines")); var sentVM = mockChannel.DeserializeClientPayload<VirtualMachine>(requestList[1].Item2); Assert.IsNotNull(sentVM); Assert.IsTrue(sentVM.Count == 1); Assert.AreEqual(sentVM[0].CloudId, testCloud.ID); Assert.AreEqual(sentVM[0].StampId, testCloud.StampId); Assert.AreEqual(sentVM[0].Name, vmToCreate.Name); Assert.AreEqual(sentVM[0].VMTemplateId, vmToCreate.VMTemplateId); }
public void ShouldReturnOneVMNetworkByName() { var mockChannel = new MockRequestChannel(); var vmNetworkToReturn = new VMNetwork() { Name = vNetName, Description = vNetDescription, LogicalNetworkId = Guid.Empty, StampId = Guid.Empty, }; mockChannel.AddReturnObject(vmNetworkToReturn); var filter = new Dictionary<string, string>() { {"Name", vNetName} }; var VMNetworkOperations = new VMNetworkOperations(new WebClientFactory(new Subscription(), mockChannel)); var readVMNetwork = VMNetworkOperations.Read(filter); Assert.AreEqual(1, readVMNetwork.Count); Assert.AreEqual(vNetName, readVMNetwork.First().Name); // Check the URI var requestList = mockChannel.ClientRequests; Assert.AreEqual(1, requestList.Count); Assert.AreEqual(baseURI, mockChannel.ClientRequests[0].Item1.Address.AbsolutePath.Substring(1)); }
public void VmCreateShouldThrowIfNoVhdAndNoTemplateSupplied() { var channel = new MockRequestChannel(); var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() }; channel.AddReturnObject(testCloud); var sub = new Subscription(); var vmOps = new VirtualMachineOperations(new WebClientFactory(sub, channel)); var vmToCreate = new VirtualMachine {Name = "Test"}; Guid? jobOut; vmOps.Create(vmToCreate, out jobOut); }