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 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 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 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 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 NewAzureSBNamespaceWithInvalidLocation() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; string location = "Invalid location"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime }; channel.ListServiceBusRegionsThunk = lsbr => { List<ServiceBusRegion> list = new List<ServiceBusRegion>(); list.Add(new ServiceBusRegion { Code = "West US" }); return list; }; string expected = string.Format("{0}\r\nParameter name: Location", string.Format(Resources.InvalidServiceBusLocation, location)); Testing.AssertThrows<ArgumentException>(() => cmdlet.ExecuteCmdlet(), expected); }
public void NewAzureSBNamespaceWithInternalServerError() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; string location = "West US"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime }; channel.CreateServiceBusNamespaceThunk = csbns => { throw new Exception(Resources.InternalServerErrorMessage); }; channel.ListServiceBusRegionsThunk = lsbr => { List<ServiceBusRegion> list = new List<ServiceBusRegion>(); list.Add(new ServiceBusRegion { Code = location }); return list; }; string expected = Resources.NewNamespaceErrorMessage; Testing.AssertThrows<Exception>(() => cmdlet.ExecuteCmdlet(), expected); }
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 NewAzureSBNamespaceSuccessfull() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; string location = "West US"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, CommandRuntime = mockCommandRuntime }; ServiceBusNamespace expected = new ServiceBusNamespace { Name = name, Region = location }; channel.CreateServiceBusNamespaceThunk = csbn => { return expected; }; channel.ListServiceBusRegionsThunk = lsbr => { List<ServiceBusRegion> list = new List<ServiceBusRegion>(); list.Add(new ServiceBusRegion { Code = location }); return list; }; // Test cmdlet.ExecuteCmdlet(); // Assert ServiceBusNamespace actual = mockCommandRuntime.OutputPipeline[0] as ServiceBusNamespace; Assert.AreEqual<ServiceBusNamespace>(expected, actual); }
public void ExecuteTestCase(MoveAzureDeploymentTestInputParameters parameters) { var channel = new SimpleServiceManagement { GetDeploymentBySlotThunk = ar => { if (ar.Values["deploymentSlot"].ToString() == DeploymentSlotType.Production) { if (parameters.ProductionDeployment == null) { throw new EndpointNotFoundException("No deployment exists"); } return parameters.ProductionDeployment; } if (ar.Values["deploymentSlot"].ToString() == DeploymentSlotType.Staging) { if (parameters.StagingDeployment == null) { throw new EndpointNotFoundException("No deployment exists"); } 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 SetupTest() { Management.Extensions.CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); channel = new SimpleServiceManagement(); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new GetAzureSBNamespaceCommand(channel) { CommandRuntime = mockCommandRuntime }; }