public void SetAzureAffinityGroupTest() { const string affinityGroupName = "myAffinity"; // Setup bool updated = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.UpdateAffinityGroupThunk = ar => { Assert.AreEqual(affinityGroupName, ar.Values["affinityGroupName"]); updated = true; }; // Test SetAzureAffinityGroup removeAzureAffinityGroupCommand = new SetAzureAffinityGroup(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = affinityGroupName, Label = affinityGroupName }; removeAzureAffinityGroupCommand.ExecuteCommand(); Assert.IsTrue(updated); }
public void GetAzureAffinityGroupMultipleTest() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); channel.ListAffinityGroupsThunk = ar => new AffinityGroupList(new[] { new AffinityGroup { Name = "affinity2" }, new AffinityGroup { Name = "affinity3" } }); // Test GetAzureAffinityGroup getAzureAffinityGroupCommand = new GetAzureAffinityGroup(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; getAzureAffinityGroupCommand.ExecuteCommand(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureAffinityGroupCommand.CommandRuntime).OutputPipeline.Count); IEnumerator enumerator = LanguagePrimitives.GetEnumerator(((MockCommandRuntime)getAzureAffinityGroupCommand.CommandRuntime).OutputPipeline.First()); Assert.IsNotNull(enumerator); enumerator.MoveNext(); Assert.IsTrue(((AffinityGroup)enumerator.Current).Name.Equals("affinity2")); enumerator.MoveNext(); Assert.IsTrue(((AffinityGroup)enumerator.Current).Name.Equals("affinity3")); }
public void NewAzureAffinityGroupTest() { const string affinityGroupName = "myAffinity"; CreateAffinityGroupInput affinityGroup = new CreateAffinityGroupInput { Name = affinityGroupName }; // Setup bool created = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.CreateAffinityGroupThunk = ar => { CreateAffinityGroupInput createAffinityGroupInput = (CreateAffinityGroupInput)ar.Values["input"]; Assert.AreEqual(affinityGroup.Name, createAffinityGroupInput.Name); created = true; }; // Test NewAzureAffinityGroup newAzureAffinityGroupCommand = new NewAzureAffinityGroup(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = affinityGroupName }; newAzureAffinityGroupCommand.ExecuteCommand(); Assert.IsTrue(created); }
public void SetDeploymentStatusProcessSetStatusToActualStatusTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Suspended; string currentStatus = DeploymentStatus.Suspended; string resultMessage; string expectedMessage = string.Format(Resources.DeploymentAlreadyInState, slot, serviceName, currentStatus); bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment{Name = serviceName, DeploymentSlot = slot, Status = newStatus}; }; channel.GetDeploymentBySlotThunk = ar => new Deployment{Name = serviceName, DeploymentSlot = slot, Status = currentStatus}; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); var deploymentManager = new DeploymentStatusManager(channel); deploymentManager.ShareChannel = true; deploymentManager.CommandRuntime = new MockCommandRuntime(); deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); resultMessage = ((MockCommandRuntime)deploymentManager.CommandRuntime).WarningStream[0]; Assert.IsFalse(statusUpdated); Assert.IsTrue(resultMessage.Contains(expectedMessage)); } }
public void SetDeploymentStatusProcessDeploymentDoesNotExistTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Running; string resultMessage; string expectedMessage = string.Format(Resources.ServiceSlotDoesNotExist, slot, serviceName); bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment{Name = serviceName, DeploymentSlot = slot, Status = newStatus}; }; channel.GetDeploymentBySlotThunk = ar => { throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError(), string.Empty); }; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); var deploymentManager = new DeploymentStatusManager(channel); deploymentManager.ShareChannel = true; deploymentManager.CommandRuntime = new MockCommandRuntime(); deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); resultMessage = ((MockCommandRuntime)deploymentManager.CommandRuntime).WarningStream[0]; Assert.IsFalse(statusUpdated); Assert.IsTrue(resultMessage.Contains(expectedMessage)); Assert.IsTrue(((MockCommandRuntime)deploymentManager.CommandRuntime).OutputPipeline.Count.Equals(0)); } }
public void SetupTest() { channel = new SimpleServiceManagement(); serviceBusChannel = new SimpleServiceBusManagement(); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new TestAzureNameCommand(channel, serviceBusChannel) { CommandRuntime = mockCommandRuntime }; CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); }
public void RemoveAzureCertificateTest() { // Setup bool deleted = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.DeleteCertificateThunk = ar => { deleted = true; }; // Test RemoveAzureCertificate removeAzureCertificate = new RemoveAzureCertificate(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; removeAzureCertificate.ExecuteCommand(); Assert.IsTrue(deleted); }
public void GetAzureCertificateMultipleTest() { const string thumbprint1 = "thumb1"; const string thumbprintAlgorithm1 = "alg1"; const string thumbprint2 = "thumb2"; const string thumbprintAlgorithm2 = "alg2"; // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); channel.ListCertificatesThunk = ar => new CertificateList(new[] { new Certificate { Thumbprint = thumbprint1, ThumbprintAlgorithm = thumbprintAlgorithm1 }, new Certificate { Thumbprint = thumbprint2, ThumbprintAlgorithm = thumbprintAlgorithm2 } }); // Test GetAzureCertificate getAzureCertificate = new GetAzureCertificate(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; getAzureCertificate.ExecuteCommand(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureCertificate.CommandRuntime).OutputPipeline.Count); IEnumerator enumerator = LanguagePrimitives.GetEnumerator(((MockCommandRuntime)getAzureCertificate.CommandRuntime).OutputPipeline.First()); Assert.IsNotNull(enumerator); enumerator.MoveNext(); Assert.IsTrue(((Certificate)enumerator.Current).Thumbprint.Equals(thumbprint1) && ((Certificate)enumerator.Current).ThumbprintAlgorithm.Equals(thumbprintAlgorithm1)); enumerator.MoveNext(); Assert.IsTrue(((Certificate)enumerator.Current).Thumbprint.Equals(thumbprint2) && ((Certificate)enumerator.Current).ThumbprintAlgorithm.Equals(thumbprintAlgorithm2)); }
public void AddAzureCertificateTest() { // Setup bool created = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.AddCertificatesThunk = ar => { created = true; }; // Test AddAzureCertificate addAzureCertificate = new AddAzureCertificate(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; const string certificateData = "MIIC7TCCAdmgAwIBAgIQbT6PtZgKY6hE3eW/9rU3LTAJBgUrDgMCHQUAMBIxEDAOBgNVBAMTB2RlcGxveTMwHhcNMTExMTAxMTk0MDAyWhcNMzkxMjMxMjM1OTU5WjASMRAwDgYDVQQDEwdkZXBsb3kzMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxCOGSNPr/okaNeSMaL8faNNTsIc0rNDH+dOLYN45A8xPB8hcRe0EdpyXDN8L5cgtW9/nkuU6Ra27oDD+s4xdbkmqlurjpO0QoSAo7+ifcZUJ8ZUpGf9qYpnFkSgViO6uRZOW6c+HAOfRDSavRvqcoEKtDGScPcx74sFC0In12AiznZgThBmO6PUveSvKzbvdeDHUPeDwcnPo/UeOR6cf5Go1yiD3QSm63JMB1SG4uBlVEdiV3dFD6lYsJP4A+8phAxlSvfK2tNgkfdEC0VX2FAP8G6hRKI9s0JTdWDdFAYn2WCYqswsqmmyOYfaXLTtk4aseoRYPeIE6yTYkIFuDIwIDAQABo0cwRTBDBgNVHQEEPDA6gBCtYSe/k41tbXAWrmFYlPaVoRQwEjEQMA4GA1UEAxMHZGVwbG95M4IQbT6PtZgKY6hE3eW/9rU3LTAJBgUrDgMCHQUAA4IBAQAFkmz/ALFf1FpVKQzT1zRKh8aNQlfKksfPFuXcfqOcYEW1HW5ll3yeSvM5PmPtRGIBYa5HCdDrq2GsrdmcpcZpwS/NKO4WX0FmX9raZ+EjR71BwpyW17qjHC2hPA21kry1wpWFr9vgaRpp8OIKIXvXUMCBTuXNa3wp9KdopLSYVegJo9iLsL94UVXkHqmysOelwasA1gUuUUjpAPlmxtco1jFdEdwCVjSBEshvdrxcFXGTQ0FRGGKD94kwkGNq48kgqNqLB7wRxSt7LMiBVRXdhITjNdO3aRryrKHUFr2lfMyDh0jsv6H9MDCvrjD46BJUptEnzNvMdd0PQ3Dl9w56"; byte[] rawData = new UTF8Encoding().GetBytes(certificateData); X509Certificate2 certificate = new X509Certificate2(rawData); addAzureCertificate.CertToDeploy = new PSObject(certificate); addAzureCertificate.ExecuteCommand(); Assert.IsTrue(created); }
public void ExecuteTestCase(MoveAzureDeploymentTestInputParameters parameters) { var channel = new SimpleServiceManagement { GetDeploymentBySlotThunk = ar => { if (ar.Values["deploymentSlot"].ToString() == DeploymentSlotType.Production) { if (parameters.ProductionDeployment == null) { throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError(), String.Empty); } return parameters.ProductionDeployment; } if (ar.Values["deploymentSlot"].ToString() == DeploymentSlotType.Staging) { if (parameters.StagingDeployment == null) { throw new ServiceManagementClientException(HttpStatusCode.NotFound, new ServiceManagementError(), String.Empty); } return parameters.StagingDeployment; } return null; }, SwapDeploymentThunk = ar => { var input = (SwapDeploymentInput)ar.Values["input"]; if (input.Production == null && parameters.ProductionDeployment == null) { if (input.SourceDeployment != parameters.StagingDeployment.Name) { Assert.Fail("Expected values Staging/Prod'{0},{1}', found '{2},{3}'", parameters.StagingDeployment.Name, null, input.SourceDeployment, null); } } else if (input.Production != parameters.ProductionDeployment.Name || input.SourceDeployment != parameters.StagingDeployment.Name) { Assert.Fail("Expected values Staging/Prod'{0},{1}', found '{2},{3}'", parameters.StagingDeployment.Name, parameters.ProductionDeployment.Name, input.SourceDeployment, input.Production); } } }; // Test var moveAzureDeployment = new MoveAzureDeploymentCommand(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime(), ServiceName = "testService", CurrentSubscription = new SubscriptionData { SubscriptionId = "testId" } }; try { moveAzureDeployment.ExecuteCommand(); if(parameters.ThrowsException) { Assert.Fail(parameters.Description); } } catch (Exception e) { if(e.GetType() != parameters.ExceptionType) { Assert.Fail("Expected exception type is {0}, however found {1}", parameters.ExceptionType, e.GetType()); } if(!parameters.ThrowsException) { Assert.Fail("{0} fails unexpectedly: {1}", parameters.Description, e); } } }
public void GetAzureCertificateSingleTest() { const string thumbprint = "thumb"; const string thumbprintAlgorithm = "alg"; // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); channel.GetCertificateThunk = ar => new Certificate { Thumbprint = thumbprint, ThumbprintAlgorithm = thumbprintAlgorithm }; // Test GetAzureCertificate getAzureCertificate = new GetAzureCertificate(channel) { ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; getAzureCertificate.Thumbprint = thumbprint; getAzureCertificate.ThumbprintAlgorithm = thumbprintAlgorithm; getAzureCertificate.ExecuteCommand(); Assert.AreEqual(1, ((MockCommandRuntime)getAzureCertificate.CommandRuntime).OutputPipeline.Count); IEnumerator enumerator = LanguagePrimitives.GetEnumerator(((MockCommandRuntime)getAzureCertificate.CommandRuntime).OutputPipeline); Assert.IsNotNull(enumerator); enumerator.MoveNext(); Assert.IsTrue(((Certificate)enumerator.Current).Thumbprint.Equals(thumbprint) && ((Certificate)enumerator.Current).ThumbprintAlgorithm.Equals(thumbprintAlgorithm)); }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); mockCommandRuntime = new MockCommandRuntime(); channel = new SimpleServiceManagement(); startServiceCmdlet = new StartAzureServiceCommand(channel) { ShareChannel = true }; startServiceCmdlet.CommandRuntime = mockCommandRuntime; }
public void SetDeploymentStatusProcessTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Suspended; string currentStatus = DeploymentStatus.Running; bool statusUpdated = false; Deployment expectedDeployment = new Deployment{Name = serviceName, DeploymentSlot = slot, Status = newStatus}; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => expectedDeployment; }; channel.GetDeploymentBySlotThunk = ar => new Deployment{Name = serviceName, DeploymentSlot = slot, Status = currentStatus}; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); var deploymentManager = new DeploymentStatusManager(channel); deploymentManager.ShareChannel = true; deploymentManager.CommandRuntime = new MockCommandRuntime(); deploymentManager.PassThru = true; deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsTrue(statusUpdated); Deployment actual = ((MockCommandRuntime)deploymentManager.CommandRuntime).OutputPipeline[0] as Deployment; Assert.AreEqual<string>(expectedDeployment.Name, actual.Name); Assert.AreEqual<string>(expectedDeployment.Status, actual.Status); Assert.AreEqual<string>(expectedDeployment.DeploymentSlot, actual.DeploymentSlot); } }