public void SetupTest() { channel = new SimpleServiceManagement(); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new TestAzureNameCommand (channel) { CommandRuntime = mockCommandRuntime }; Management.Extensions.CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); }
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(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, 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; resultMessage = deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsFalse(statusUpdated); Assert.AreEqual <string>(expectedMessage, resultMessage); } }
public void SetDeploymentStatusProcessTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Suspended; string currentStatus = DeploymentStatus.Running; bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, 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.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsTrue(statusUpdated); } }
//[TestMethod] 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 = 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() { channel = new SimpleServiceManagement(); writer = new FakeWriter(); cmdlet = new TestAzureNameCommand (channel) { Writer = writer }; Management.Extensions.CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); }
//[TestMethod] 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 = 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 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(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, 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; resultMessage = deploymentManager.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsFalse(statusUpdated); Assert.AreEqual<string>(expectedMessage, resultMessage); } }
//[TestMethod] public void AddAzureCertificateTest() { // Setup bool created = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.AddCertificatesThunk = ar => { created = true; }; // Test AddAzureCertificate addAzureCertificate = new AddAzureCertificate() { Channel = 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 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(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => { throw new EndpointNotFoundException(); }; 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.ValidSubscriptionNames[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)); } }
//[TestMethod] public void RemoveAzureAffinityGroupTest() { const string affinityGroupName = "myAffinity"; // Setup bool deleted = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.DeleteAffinityGroupThunk = ar => { Assert.AreEqual(affinityGroupName, ar.Values["affinityGroupName"]); deleted = true; }; // Test RemoveAzureAffinityGroup removeAzureAffinityGroupCommand = new RemoveAzureAffinityGroup() { Channel = channel, ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = affinityGroupName }; removeAzureAffinityGroupCommand.ExecuteCommand(); Assert.IsTrue(deleted); }
public void RemoveAzureServiceProcessTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); bool serviceDeleted = false; bool deploymentDeleted = false; channel.GetDeploymentBySlotThunk = ar => { if (deploymentDeleted) throw new EndpointNotFoundException(); return new Deployment(serviceName, ArgumentConstants.Slots[Slot.Production], DeploymentStatus.Suspended); }; channel.DeleteHostedServiceThunk = ar => serviceDeleted = true; channel.DeleteDeploymentBySlotThunk = ar => { deploymentDeleted = true; }; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); new RemoveAzureServiceCommand(channel).RemoveAzureServiceProcess(service.Paths.RootPath, string.Empty); Assert.IsTrue(deploymentDeleted); Assert.IsTrue(serviceDeleted); } }
//[TestMethod] 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 = channel, ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = affinityGroupName, Label = affinityGroupName }; removeAzureAffinityGroupCommand.ExecuteCommand(); Assert.IsTrue(updated); }
public void PublishAzureServiceSimpleDeployTest() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new channel to mock the calls to Azure and // determine all of the results that we'll need. bool createdHostedService = false; bool createdOrUpdatedDeployment = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.GetStorageServiceThunk = ar => new StorageService(); channel.CreateHostedServiceThunk = ar => createdHostedService = true; channel.GetHostedServiceWithDetailsThunk = ar => { throw new EndpointNotFoundException(); }; channel.GetStorageKeysThunk = ar => new StorageService() { StorageServiceKeys = new StorageServiceKeys() { Primary = "VGVzdEtleSE=" } }; channel.CreateOrUpdateDeploymentThunk = ar => createdOrUpdatedDeployment = true; channel.GetDeploymentBySlotThunk = ar => new Deployment() { Status = DeploymentStatus.Starting, RoleInstanceList = new RoleInstanceList( new RoleInstance[] { new RoleInstance() { InstanceName = "Role_IN_0", InstanceStatus = RoleInstanceStatus.Ready } }) }; // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; NewAzureServiceCommand newService = new NewAzureServiceCommand(); newService.NewAzureServiceProcess(files.RootPath, serviceName); string servicePath = files.CreateDirectory(serviceName); // Get the publishing process started by creating the package PublishAzureServiceCommand publishService = new PublishAzureServiceCommand(channel); publishService.ShareChannel = true; publishService.SkipUpload = true; publishService.PublishService(servicePath); AzureService service = new AzureService(Path.Combine(files.RootPath, serviceName), null); // Verify the publish service attempted to create and update // the service through the mock. Assert.IsTrue(createdHostedService); Assert.IsTrue(createdOrUpdatedDeployment); Assert.AreEqual <string>(serviceName, service.ServiceName); } }
//[TestMethod] 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 = channel, ShareChannel = true, CommandRuntime = new MockCommandRuntime(), Name = affinityGroupName }; newAzureAffinityGroupCommand.ExecuteCommand(); Assert.IsTrue(created); }
public void SetDeploymentStatusProcessDeploymentDoesNotExistTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Running; string resultMessage; string expectedMessage = string.Format(Resources.ServiceSlotDoesNotExist, serviceName, slot); bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => { throw new EndpointNotFoundException(); }; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); resultMessage = new DeploymentStatusManager(channel).SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsFalse(statusUpdated); Assert.AreEqual <string>(expectedMessage, resultMessage); } }
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 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 RemoveAzureServiceProcessTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); bool serviceDeleted = false; bool deploymentDeleted = false; channel.GetDeploymentBySlotThunk = ar => { if (deploymentDeleted) { throw new EndpointNotFoundException(); } return(new Deployment(serviceName, ArgumentConstants.Slots[Slot.Production], DeploymentStatus.Suspended)); }; channel.DeleteHostedServiceThunk = ar => serviceDeleted = true; channel.DeleteDeploymentBySlotThunk = ar => { deploymentDeleted = true; }; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); var removeAzureServiceCommand = new RemoveAzureServiceCommand(channel); removeAzureServiceCommand.ShareChannel = true; removeAzureServiceCommand.RemoveAzureServiceProcess(service.Paths.RootPath, string.Empty, serviceName); Assert.IsTrue(deploymentDeleted); Assert.IsTrue(serviceDeleted); } }
public void PublishAzureServiceCreateBasicPackageTest() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new channel to mock the calls to Azure and // determine all of the results that we'll need. SimpleServiceManagement channel = new SimpleServiceManagement(); // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; NewAzureServiceCommand newService = new NewAzureServiceCommand(); newService.NewAzureServiceProcess(files.RootPath, serviceName); string servicePath = files.CreateDirectory(serviceName); // Get the publishing process started by creating the package PublishAzureServiceCommand publishService = new PublishAzureServiceCommand(channel); publishService.InitializeSettingsAndCreatePackage(servicePath); // Verify the generated files files.AssertFiles(new Dictionary <string, Action <string> >() { { serviceName + @"\deploymentSettings.json", null }, { serviceName + @"\ServiceDefinition.csdef", p => File.ReadAllText(p).Contains(serviceName) }, { serviceName + @"\ServiceConfiguration.Cloud.cscfg", p => File.ReadAllText(p).Contains(serviceName) }, { serviceName + @"\ServiceConfiguration.Local.cscfg", p => File.ReadAllText(p).Contains(serviceName) }, { serviceName + @"\cloud_package.cspkg", p => { using (Package package = Package.Open(p)) { Assert.AreEqual(5, package.GetParts().Count()); } } } }); } }
public void GetStorageAccountsTestEmptyList() { SimpleServiceManagement channel = new SimpleServiceManagement(); channel.ListStorageServicesThunk = ar => new StorageServiceList(); GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string result = cmd.GetStorageServicesProcess("TestSubscription1"); Assert.IsTrue(string.IsNullOrEmpty(result)); }
public void SetupTest() { channel = new SimpleServiceManagement(); serviceBusChannel = new SimpleServiceBusManagement(); mockCommandRuntime = new MockCommandRuntime(); cmdlet = new TestAzureNameCommand(channel, serviceBusChannel) { CommandRuntime = mockCommandRuntime }; CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); }
//[TestInitialize] public void SetupTest() { found = new TestData(); channel = new SimpleServiceManagement { UpdateStorageServiceThunk = ar => { found.SubscriptionId = (string)ar.Values["subscriptionId"]; found.StorageServiceName = (string)ar.Values["StorageServiceName"]; found.UpdateStorageServiceInput = (UpdateStorageServiceInput)ar.Values["updateStorageServiceInput"]; } }; }
public void GetStorageAccountsTestManyEntriesList() { SimpleServiceManagement channel = new SimpleServiceManagement(); string expectedResult = CreateExpectedResult(Data.ValidStorageService); channel.ListStorageServicesThunk = ar => Data.ValidStorageService; channel.GetStorageKeysThunk = ar => Data.ValidStorageService[0]; GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string actualResult = cmd.GetStorageServicesProcess("TestSubscription1"); Assert.AreEqual <string>(expectedResult, actualResult); }
public void GetStorageAccountsTestManyEntriesList() { SimpleServiceManagement channel = new SimpleServiceManagement(); string expectedResult = CreateExpectedResult(Data.ValidStorageService); channel.ListStorageServicesThunk = ar => Data.ValidStorageService; channel.GetStorageKeysThunk = ar => Data.ValidStorageService[0]; GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string actualResult = cmd.GetStorageServicesProcess("TestSubscription1"); Assert.AreEqual<string>(expectedResult, actualResult); }
public void RemoveAzureSBNamespaceSuccessfull() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, CommandRuntime = mockCommandRuntime, PassThru = true }; bool deleted = false; channel.DeleteServiceBusNamespaceThunk = dsbn => { deleted = true; }; // Test cmdlet.ExecuteCmdlet(); // Assert Assert.IsTrue(deleted); Assert.IsTrue((bool)mockCommandRuntime.OutputPipeline[0]); }
public void RemoveAzureSBNamespaceWithInternalServerError() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); FakeWriter writer = new FakeWriter(); string name = "test"; RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, Writer = writer }; string expected = Resources.RemoveNamespaceErrorMessage; channel.DeleteServiceBusNamespaceThunk = dsbn => { throw new Exception(Resources.InternalServerErrorMessage); }; // Test cmdlet.ExecuteCmdlet(); // Assert ErrorRecord actual = writer.ErrorChannel[0]; Assert.AreEqual<string>(expected, actual.Exception.Message); }
//[TestMethod] 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 = 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)); }
//[TestMethod] public void RemoveAzureCertificateTest() { // Setup bool deleted = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.DeleteCertificateThunk = ar => { deleted = true; }; // Test RemoveAzureCertificate removeAzureCertificate = new RemoveAzureCertificate() { Channel = channel, ShareChannel = true, CommandRuntime = new MockCommandRuntime() }; removeAzureCertificate.ExecuteCommand(); Assert.IsTrue(deleted); }
public void NewAzureSBNamespaceWithInvalidLocation() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); FakeWriter writer = new FakeWriter(); string name = "test"; string location = "Invalid location"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, Writer = writer }; 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 RemoveAzureSBNamespaceSuccessfull() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); FakeWriter writer = new FakeWriter(); string name = "test"; RemoveAzureSBNamespaceCommand cmdlet = new RemoveAzureSBNamespaceCommand(channel) { Name = name, Writer = writer }; bool deleted = false; string expectedVerbose = string.Format(Resources.RemovingNamespaceMessage, name); channel.DeleteServiceBusNamespaceThunk = dsbn => { deleted = true; }; // Test cmdlet.ExecuteCmdlet(); // Assert string actual = writer.VerboseChannel[0] as string; Assert.IsTrue(deleted); Assert.AreEqual<string>(expectedVerbose, actual); }
public void NewAzureSBNamespaceWithInternalServerError() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); FakeWriter writer = new FakeWriter(); string name = "test"; string location = "West US"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, Writer = writer }; 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 GetStorageAccountsTestEmptySubscriptionFail() { string doesNotExistSubscription = "DoesNotExistSubscription"; string argumentErrorExpectedMsg = string.Format(Resources.SubscriptionIdNotFoundMessage, doesNotExistSubscription, Path.Combine(Data.AzureSdkAppDir, Resources.PublishSettingsFileName)); try { new ImportAzurePublishSettingsCommand().ImportAzurePublishSettingsProcess(Resources.PublishSettingsFileName, Data.AzureSdkAppDir); SimpleServiceManagement channel = new SimpleServiceManagement(); channel.ListStorageServicesThunk = ar => new StorageServiceList(); GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string result = cmd.GetStorageServicesProcess("DoesNotExistSubscription"); Assert.Fail("No exception was thrown"); } catch (Exception ex) { Assert.AreEqual<string>(argumentErrorExpectedMsg, ex.Message); } }
public void GetStorageAccountsTestEmptySubscriptionFail() { string doesNotExistSubscription = "DoesNotExistSubscription"; string argumentErrorExpectedMsg = string.Format(Resources.SubscriptionIdNotFoundMessage, doesNotExistSubscription, Path.Combine(Data.AzureSdkAppDir, Resources.PublishSettingsFileName)); try { new ImportAzurePublishSettingsCommand().ImportAzurePublishSettingsProcess(Resources.PublishSettingsFileName, Data.AzureSdkAppDir); SimpleServiceManagement channel = new SimpleServiceManagement(); channel.ListStorageServicesThunk = ar => new StorageServiceList(); GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string result = cmd.GetStorageServicesProcess("DoesNotExistSubscription"); Assert.Fail("No exception was thrown"); } catch (Exception ex) { Assert.AreEqual <string>(argumentErrorExpectedMsg, ex.Message); } }
public void GetStorageAccountsTestOneEntryList() { SimpleServiceManagement channel = new SimpleServiceManagement(); StorageServiceList list = new StorageServiceList(); list.Add(Data.ValidStorageService[0]); StringBuilder expectedResult = new StringBuilder(); expectedResult.AppendFormat("{0, -16}{1}", Resources.StorageAccountName, list[0].ServiceName); expectedResult.AppendLine(); expectedResult.AppendFormat("{0, -16}{1}", Resources.StoragePrimaryKey, list[0].StorageServiceKeys.Primary); expectedResult.AppendLine(); expectedResult.AppendFormat("{0, -16}{1}", Resources.StorageSecondaryKey, list[0].StorageServiceKeys.Secondary); channel.ListStorageServicesThunk = ar => list; channel.GetStorageKeysThunk = ar => list[0]; GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string actualResult = cmd.GetStorageServicesProcess("TestSubscription1"); Assert.AreEqual <string>(expectedResult.ToString(), actualResult); }
public void SetDeploymentStatusProcessTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Running; string currentStatus = DeploymentStatus.Suspended; bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, currentStatus); using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); string result = new StartAzureService(channel).SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsTrue(statusUpdated); } }
public void SetDeploymentStatusProcessDeploymentDoesNotExistTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Running; string resultMessage; string expectedMessage = string.Format(Resources.ServiceSlotDoesNotExist, serviceName, slot); bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => { throw new EndpointNotFoundException(); }; using (FileSystemHelper files = new FileSystemHelper(this)) { files.CreateAzureSdkDirectoryAndImportPublishSettings(); AzureService service = new AzureService(files.RootPath, serviceName, null); resultMessage = new DeploymentStatusManager(channel).SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsFalse(statusUpdated); Assert.AreEqual<string>(expectedMessage, resultMessage); } }
public void NewAzureSBNamespaceSuccessfull() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); FakeWriter writer = new FakeWriter(); string name = "test"; string location = "West US"; NewAzureSBNamespaceCommand cmdlet = new NewAzureSBNamespaceCommand(channel) { Name = name, Location = location, Writer = writer }; 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 = writer.OutputChannel[0] as ServiceBusNamespace; Assert.AreEqual<ServiceBusNamespace>(expected, actual); }
public void GetAzureSBLocationSuccessfull() { // Setup SimpleServiceManagement channel = new SimpleServiceManagement(); MockCommandRuntime mockCommandRuntime = new MockCommandRuntime(); string name = "test"; GetAzureSBLocationCommand cmdlet = new GetAzureSBLocationCommand(channel) { CommandRuntime = mockCommandRuntime }; List<ServiceBusRegion> expected = new List<ServiceBusRegion>(); expected.Add(new ServiceBusRegion { Code = name, FullName = name }); channel.ListServiceBusRegionsThunk = gn => { return expected; }; // Test cmdlet.ExecuteCmdlet(); // Assert List<ServiceBusRegion> actual = mockCommandRuntime.OutputPipeline[0] as List<ServiceBusRegion>; Assert.AreEqual<int>(expected.Count, actual.Count); for (int i = 0; i < expected.Count; i++) { Assert.AreEqual<string>(expected[i].Code, actual[i].Code); Assert.AreEqual<string>(expected[i].FullName, actual[i].FullName); } }
public void PublishAzureServiceManifestTest() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new channel to mock the calls to Azure and // determine all of the results that we'll need. SimpleServiceManagement channel = new SimpleServiceManagement(); // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; NewAzureServiceProjectCommand newService = new NewAzureServiceProjectCommand(); newService.NewAzureServiceProcess(files.RootPath, serviceName); string servicePath = files.CreateDirectory(serviceName); // Add web and worker roles AddAzureNodeWebRoleCommand newWebRole = new AddAzureNodeWebRoleCommand(); string defaultWebRoleName = "WebRoleDefault"; string defaultWebRolePath = newWebRole.AddAzureNodeWebRoleProcess(defaultWebRoleName, 2, servicePath); AddAzureNodeWorkerRoleCommand newWorkerRole = new AddAzureNodeWorkerRoleCommand(); string defaultWorkerRoleName = "WorkerRoleDefault"; string defaultWorkerRolePath = newWorkerRole.AddAzureNodeWorkerRoleProcess(defaultWorkerRoleName, 2, servicePath); AddAzureNodeWebRoleCommand matchWebRole = new AddAzureNodeWebRoleCommand(); string matchWebRoleName = "WebRoleExactMatch"; string matchWebRolePath = matchWebRole.AddAzureNodeWebRoleProcess(matchWebRoleName, 2, servicePath); AddAzureNodeWorkerRoleCommand matchWorkerRole = new AddAzureNodeWorkerRoleCommand(); string matchWorkerRoleName = "WorkerRoleExactMatch"; string matchWorkerRolePath = matchWorkerRole.AddAzureNodeWorkerRoleProcess(matchWorkerRoleName, 2, servicePath); AddAzureNodeWebRoleCommand overrideWebRole = new AddAzureNodeWebRoleCommand(); string overrideWebRoleName = "WebRoleOverride"; string overrideWebRolePath = overrideWebRole.AddAzureNodeWebRoleProcess(overrideWebRoleName, 2, servicePath); AddAzureNodeWorkerRoleCommand overrideWorkerRole = new AddAzureNodeWorkerRoleCommand(); string overrideWorkerRoleName = "WorkerRoleOverride"; string overrideWorkerRolePath = matchWorkerRole.AddAzureNodeWorkerRoleProcess(overrideWorkerRoleName, 2, servicePath); AzureService testService = new AzureService(Path.Combine(files.RootPath, serviceName), null); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWebRoleName, testService.Paths, version: "0.8.2"); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, matchWorkerRoleName, testService.Paths, version: "0.8.2"); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWebRoleName, testService.Paths, overrideUrl: "http://OVERRIDE"); RuntimePackageHelper.SetRoleRuntime(testService.Components.Definition, overrideWorkerRoleName, testService.Paths, overrideUrl: "http://OVERRIDE"); testService.Components.Save(testService.Paths); // Get the publishing process started by creating the package PublishAzureServiceProjectCommand publishService = new PublishAzureServiceProjectCommand(channel); publishService.InitializeSettingsAndCreatePackage(servicePath, RuntimePackageHelper.GetTestManifest(files)); AzureService updatedService = new AzureService(testService.Paths.RootPath, null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWebRoleName, "http://DATACENTER/node/default.exe;http://DATACENTER/iisnode/default.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, defaultWorkerRoleName, "http://DATACENTER/node/default.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWorkerRoleName, "http://DATACENTER/node/foo.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, matchWebRoleName, "http://DATACENTER/node/foo.exe;http://DATACENTER/iisnode/default.exe", null); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWebRoleName, null, "http://OVERRIDE"); RuntimePackageHelper.ValidateRoleRuntime(updatedService.Components.Definition, overrideWorkerRoleName, null, "http://OVERRIDE"); } }
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() { ShareChannel = true, Channel = channel, CommandRuntime = new MockCommandRuntime(), ServiceName = "testService", CurrentSubscription = new WindowsAzureSubscription { 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 PublishAzureServiceCreateWorkersPackageTest() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new channel to mock the calls to Azure and // determine all of the results that we'll need. SimpleServiceManagement channel = new SimpleServiceManagement(); // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; NewAzureServiceCommand newService = new NewAzureServiceCommand(); newService.NewAzureServiceProcess(files.RootPath, serviceName); string servicePath = files.CreateDirectory(serviceName); // Add web and worker roles AddAzureNodeWebRoleCommand newWebRole = new AddAzureNodeWebRoleCommand(); string webRoleName = "NODE_WEB_ROLE"; string webRolePath = newWebRole.AddAzureNodeWebRoleProcess(webRoleName, 2, servicePath); AddAzureNodeWorkerRoleCommand newWorkerRole = new AddAzureNodeWorkerRoleCommand(); string workerRoleName = "NODE_WORKER_ROLE"; string workerRolePath = newWorkerRole.AddAzureNodeWorkerRoleProcess(workerRoleName, 2, servicePath); // Get the publishing process started by creating the package PublishAzureServiceCommand publishService = new PublishAzureServiceCommand(channel); publishService.InitializeSettingsAndCreatePackage(servicePath); // Verify the generated files Action <string> verifyContainsNames = p => { string contents = File.ReadAllText(p); Assert.IsTrue(contents.Contains(webRoleName)); Assert.IsTrue(contents.Contains(workerRoleName)); }; files.AssertFiles(new Dictionary <string, Action <string> >() { { serviceName + @"\deploymentSettings.json", null }, { serviceName + '\\' + webRoleName + @"\server.js", null }, { serviceName + '\\' + workerRoleName + @"\server.js", null }, { serviceName + @"\ServiceDefinition.csdef", verifyContainsNames }, { serviceName + @"\ServiceConfiguration.Cloud.cscfg", verifyContainsNames }, { serviceName + @"\ServiceConfiguration.Local.cscfg", verifyContainsNames }, { serviceName + @"\cloud_package.cspkg", p => { using (Package package = Package.Open(p)) { Assert.AreEqual(7, package.GetParts().Count()); } } } }); } }
public void SetupTest() { GlobalPathInfo.GlobalSettingsDirectory = Data.AzureSdkAppDir; CmdletSubscriptionExtensions.SessionManager = new InMemorySessionManager(); mockCommandRuntime = new MockCommandRuntime(); channel = new SimpleServiceManagement(); stopServiceCmdlet = new StopAzureServiceCommand(channel) { ShareChannel = true }; stopServiceCmdlet.CommandRuntime = mockCommandRuntime; }
public void GetStorageAccountsTestOneEntryList() { SimpleServiceManagement channel = new SimpleServiceManagement(); StorageServiceList list = new StorageServiceList(); list.Add(Data.ValidStorageService[0]); StringBuilder expectedResult = new StringBuilder(); expectedResult.AppendFormat("{0, -16}{1}", Resources.StorageAccountName, list[0].ServiceName); expectedResult.AppendLine(); expectedResult.AppendFormat("{0, -16}{1}", Resources.StoragePrimaryKey, list[0].StorageServiceKeys.Primary); expectedResult.AppendLine(); expectedResult.AppendFormat("{0, -16}{1}", Resources.StorageSecondaryKey, list[0].StorageServiceKeys.Secondary); channel.ListStorageServicesThunk = ar => list; channel.GetStorageKeysThunk = ar => list[0]; GetAzureStorageAccountsCommand cmd = new GetAzureStorageAccountsCommand(channel); string actualResult = cmd.GetStorageServicesProcess("TestSubscription1"); Assert.AreEqual<string>(expectedResult.ToString(), actualResult); }
public void SetDeploymentStatusProcessTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Suspended; string currentStatus = DeploymentStatus.Running; bool statusUpdated = false; Deployment expectedDeployment = new Deployment(serviceName, slot, newStatus); channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => expectedDeployment; }; channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, 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.ValidSubscriptionNames[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); } }
public void SetDeploymentStatusProcessSetTransitioningServiceTest() { SimpleServiceManagement channel = new SimpleServiceManagement(); string newStatus = DeploymentStatus.Suspended; string currentStatus = DeploymentStatus.RunningTransitioning; string resultMessage; string expectedMessage = string.Format(Resources.ServiceIsInTransitionState, slot, serviceName, currentStatus); bool statusUpdated = false; channel.UpdateDeploymentStatusBySlotThunk = ar => { statusUpdated = true; channel.GetDeploymentBySlotThunk = ar2 => new Deployment(serviceName, slot, newStatus); }; channel.GetDeploymentBySlotThunk = ar => new Deployment(serviceName, slot, 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.ValidSubscriptionNames[0], serviceName); resultMessage = ((MockCommandRuntime)deploymentManager.CommandRuntime).WarningStream[0]; Assert.IsFalse(statusUpdated); Assert.IsTrue(resultMessage.Contains(expectedMessage)); } }
public void PublishAzureServiceUpgradeTest() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new channel to mock the calls to Azure and // determine all of the results that we'll need. bool createdHostedService = false; bool createdOrUpdatedDeployment = false; bool upgradedDeployment = false; SimpleServiceManagement channel = new SimpleServiceManagement(); channel.GetStorageServiceThunk = ar => new StorageService(); channel.CreateHostedServiceThunk = ar => createdHostedService = true; channel.GetHostedServiceWithDetailsThunk = ar => new HostedService { Deployments = new DeploymentList() { new Deployment { DeploymentSlot = "Production" } } }; channel.GetStorageKeysThunk = ar => new StorageService() { StorageServiceKeys = new StorageServiceKeys() { Primary = "VGVzdEtleSE=" } }; channel.CreateOrUpdateDeploymentThunk = ar => createdOrUpdatedDeployment = true; channel.UpgradeDeploymentThunk = ar => upgradedDeployment = true; channel.GetDeploymentBySlotThunk = ar => new Deployment() { Status = DeploymentStatus.Starting, RoleInstanceList = new RoleInstanceList( new RoleInstance[] { new RoleInstance() { InstanceName = "Role_IN_0", InstanceStatus = RoleInstanceStatus.Ready } }) }; channel.ListCertificatesThunk = ar => new CertificateList(); // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; NewAzureServiceCommand newService = new NewAzureServiceCommand(); newService.NewAzureServiceProcess(files.RootPath, serviceName); string servicePath = files.CreateDirectory(serviceName); // Get the publishing process started by creating the package PublishAzureServiceCommand publishService = new PublishAzureServiceCommand(channel); publishService.ShareChannel = true; publishService.SkipUpload = true; publishService.PublishService(servicePath); // Verify the publish service upgraded the deployment Assert.IsFalse(createdHostedService); Assert.IsFalse(createdOrUpdatedDeployment); Assert.IsTrue(upgradedDeployment); } }
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 PublishAzureServiceRemovesNodeLogs() { // Create a temp directory that we'll use to "publish" our service using (FileSystemHelper files = new FileSystemHelper(this) { EnableMonitoring = true }) { // Import our default publish settings files.CreateAzureSdkDirectoryAndImportPublishSettings(); // Create a new channel to mock the calls to Azure and // determine all of the results that we'll need. SimpleServiceManagement channel = new SimpleServiceManagement(); // Create a new service that we're going to publish string serviceName = "TEST_SERVICE_NAME"; NewAzureServiceCommand newService = new NewAzureServiceCommand(); newService.NewAzureServiceProcess(files.RootPath, serviceName); string servicePath = files.CreateDirectory(serviceName); // Add a web role AddAzureNodeWebRoleCommand newWebRole = new AddAzureNodeWebRoleCommand(); string webRoleName = "NODE_WEB_ROLE"; newWebRole.AddAzureNodeWebRoleProcess(webRoleName, 2, servicePath); string webRolePath = Path.Combine(servicePath, webRoleName); // Add a worker role AddAzureNodeWorkerRoleCommand newWorkerRole = new AddAzureNodeWorkerRoleCommand(); string workerRoleName = "NODE_WORKER_ROLE"; newWorkerRole.AddAzureNodeWorkerRoleProcess(workerRoleName, 2, servicePath); string workerRolePath = Path.Combine(servicePath, workerRoleName); // Add second web and worker roles that we won't add log // entries to new AddAzureNodeWebRoleCommand() .AddAzureNodeWebRoleProcess("SECOND_WEB_ROLE", 2, servicePath); new AddAzureNodeWorkerRoleCommand() .AddAzureNodeWorkerRoleProcess("SECOND_WORKER_ROLE", 2, servicePath); // Add fake logs directories for server.js string logName = "server.js.logs"; string logPath = Path.Combine(webRolePath, logName); Directory.CreateDirectory(logPath); File.WriteAllText(Path.Combine(logPath, "0.txt"), "secret web role debug details were logged here"); logPath = Path.Combine(Path.Combine(workerRolePath, "NestedDirectory"), logName); Directory.CreateDirectory(logPath); File.WriteAllText(Path.Combine(logPath, "0.txt"), "secret worker role debug details were logged here"); // Get the publishing process started by creating the package PublishAzureServiceCommand publishService = new PublishAzureServiceCommand(channel); publishService.InitializeSettingsAndCreatePackage(servicePath); // Rip open the package and make sure we can't find the log string packagePath = Path.Combine(servicePath, "cloud_package.cspkg"); using (Package package = Package.Open(packagePath)) { // Make sure the web role and worker role packages don't // have any files with server.js.logs in the name Action <string> validateRole = roleName => { PackagePart rolePart = package.GetParts().Where(p => p.Uri.ToString().Contains(roleName)).First(); using (Package rolePackage = Package.Open(rolePart.GetStream())) { Assert.IsFalse( rolePackage.GetParts().Any(p => p.Uri.ToString().Contains(logName)), "Found {0} part in {1} package!", logName, roleName); } }; validateRole(webRoleName); validateRole(workerRoleName); } } }