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 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); 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 SetAzureInstancesProcessTestsEmptyRoleNameFail() { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, string.Empty, 10), string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.RoleName)); } }
public void SetAzureInstancesProcessNegativeRoleInstanceFail() { string roleName = "WebRole1"; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, roleName, -1), string.Format(Resources.InvalidInstancesCount, roleName)); } }
public void GetNextPortAllNull() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultWebPort); AzureService service = new AzureService(files.RootPath, serviceName, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
public void TestGetRuntimes() { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWebRole(Resources.NodeScaffolding); string manifest = RuntimePackageHelper.GetTestManifest(files); CloudRuntimeCollection collection = service.GetCloudRuntimes(service.Paths, manifest); RuntimePackageHelper.ValidateRuntimesMatchManifest(manifest, collection); } }
public void GetNextPortNodeWebRoleNull() { using (FileSystemHelper files = new FileSystemHelper(this)) { int expectedPort = int.Parse(Resources.DefaultPort); AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWorkerRole(Resources.NodeScaffolding); service = new AzureService(service.Paths.RootPath, null); int nextPort = service.Components.GetNextPort(); Assert.AreEqual<int>(expectedPort, nextPort); } }
public void TestSetAzureRuntimeInvalidRuntimeVersion() { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWebRole(Resources.NodeScaffolding); new SetAzureServiceProjectRoleCommand().SetAzureRuntimesProcess("WebRole1", "node", "0.8.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); new SetAzureServiceProjectRoleCommand().SetAzureRuntimesProcess("WebRole1", "iisnode", "0.9.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); VerifyInvalidPackageJsonVersion(service.Paths.RootPath, "WebRole1", "node", "*"); VerifyInvalidPackageJsonVersion(service.Paths.RootPath, "WebRole1", "iisnode", "*"); } }
public void CreateLocalPackageWithNodeWorkerRoleTest() { using (FileSystemHelper files = new FileSystemHelper(this)) { string standardOutput; string standardError; AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWorkerRole(Resources.NodeScaffolding); service.CreatePackage(DevEnv.Local, out standardOutput, out standardError); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WorkerRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WorkerRole)); } }
public void SetAzureInstancesProcessTestsNode() { int newRoleInstances = 10; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWebRole(Resources.NodeScaffolding); new SetAzureServiceProjectRoleCommand().SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath); service = new AzureService(service.Paths.RootPath, null); Assert.AreEqual<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count); Assert.AreEqual<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count); } }
public static void VerifyRoleSettings(AzureService service) { IEnumerable<ServiceConfigurationSchema.RoleSettings> settings = Enumerable.Concat( service.Components.CloudConfig.Role, service.Components.LocalConfig.Role); foreach (ServiceConfigurationSchema.RoleSettings roleSettings in settings) { Assert.AreEqual( 1, roleSettings .Certificates .Where(c => c.name == "Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption") .Count()); } }
public void TestGetRuntimes() { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); string manifest = RuntimePackageHelper.GetTestManifest(files); CloudRuntimeCollection expected = service.GetCloudRuntimes(service.Paths, manifest); cmdlet.GetAzureRuntimesProcess(string.Empty, Path.Combine(files.RootPath, serviceName), manifest); List<CloudRuntimePackage> actual = writer.OutputChannel[0] as List<CloudRuntimePackage>; Assert.AreEqual<int>(expected.Count, actual.Count); Assert.IsTrue(expected.All<CloudRuntimePackage>( p => actual.Any<CloudRuntimePackage>(p2 => p2.PackageUri.Equals(p.PackageUri)))); } }
internal string AddAzureNodeWorkerRoleProcess(string workerRoleName, int instances, string rootPath) { string result; AzureService service = new AzureService(rootPath, null); RoleInfo workerRole = service.AddWorkerRole(Resources.NodeScaffolding, workerRoleName, instances); try { service.ChangeRolePermissions(workerRole); } catch (UnauthorizedAccessException) { SafeWriteObject(Resources.AddRoleMessageInsufficientPermissions); SafeWriteObject(Environment.NewLine); } result = string.Format(Resources.AddRoleMessageCreate, rootPath, workerRole.Name); return result; }
public void TestSetAzureRuntimeInvalidRuntimeType() { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.NodeWebRoleScaffoldingPath); RoleSettings roleSettings1 = cmdlet.SetAzureRuntimesProcess(roleName, "noide", "0.8.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); RoleSettings roleSettings2 = cmdlet.SetAzureRuntimesProcess(roleName, "iisnoide", "0.9.99", service.Paths.RootPath, RuntimePackageHelper.GetTestManifest(files)); VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "node", "*"); VerifyInvalidPackageJsonVersion(service.Paths.RootPath, roleName, "iisnode", "*"); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString()); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[1]).Members[Parameters.RoleName].Value.ToString()); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[1]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.AreEqual<string>(roleName, roleSettings1.name); Assert.AreEqual<string>(roleName, roleSettings2.name); } }
public void SetAzureVMSizeProcessTestsCaseInsensitiveVMSizeSize() { string newRoleVMSize = "ExTraLaRge"; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.NodeWebRoleScaffoldingPath); cmdlet.PassThru = false; RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath); service = new AzureService(service.Paths.RootPath, null); Assert.AreEqual<string>(newRoleVMSize.ToLower(), service.Components.Definition.WebRole[0].vmsize.ToString().ToLower()); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void CreateLocalPackageWithOneNodeWebRoleTest() { using (FileSystemHelper files = new FileSystemHelper(this)) { string standardOutput; string standardError; AzureService service = new AzureService(files.RootPath, serviceName, null); RoleInfo webRoleInfo = service.AddWebRole(Resources.NodeScaffolding); string logsDir = Path.Combine(service.Paths.RootPath, webRoleInfo.Name, "server.js.logs"); string logFile = Path.Combine(logsDir, "0.txt"); string targetLogsFile = Path.Combine(service.Paths.LocalPackage, "roles", webRoleInfo.Name, @"approot\server.js.logs\0.txt"); files.CreateDirectory(logsDir); files.CreateEmptyFile(logFile); service.CreatePackage(DevEnv.Local, out standardOutput, out standardError); AzureAssert.ScaffoldingExists(Path.Combine(service.Paths.LocalPackage, @"roles\WebRole1\approot"), Path.Combine(Resources.NodeScaffolding, Resources.WebRole)); Assert.IsTrue(File.Exists(targetLogsFile)); } }
public void SetAzureInstancesProcessTestsCaseInsensitive() { int newRoleInstances = 10; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.NodeWebRoleScaffoldingPath); cmdlet.PassThru = false; RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WeBrolE1", newRoleInstances, service.Paths.RootPath); service = new AzureService(service.Paths.RootPath, null); Assert.AreEqual<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count); Assert.AreEqual<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count); Assert.AreEqual<int>(0, mockCommandRuntime.OutputPipeline.Count); Assert.AreEqual<int>(newRoleInstances, roleSettings.Instances.count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void OnPublish(IServiceManagement channel, AzureService service, ServiceSettings publishSettings, string subscriptionId) { StorageService storageService = channel.GetStorageKeys(subscriptionId, publishSettings.StorageAccountName); string name = publishSettings.StorageAccountName; string key = storageService.StorageServiceKeys.Primary; ConfigConfigurationSetting connectionStringConfig = new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = string.Empty }; service.Components.ForEachRoleSettings( r => Array.Exists<ConfigConfigurationSetting>(r.ConfigurationSettings, c => c.Equals(connectionStringConfig)), delegate(RoleSettings r) { int index = Array.IndexOf<ConfigConfigurationSetting>(r.ConfigurationSettings, connectionStringConfig); r.ConfigurationSettings[index] = new ConfigConfigurationSetting { name = Resources.CachingConfigStoreConnectionStringSettingName, value = string.Format(Resources.CachingConfigStoreConnectionStringSettingValue, name, key) }; }); service.Components.Save(service.Paths); }
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); var startAzureService = new StartAzureService(channel) { ShareChannel = true }; startAzureService.SetDeploymentStatusProcess(service.Paths.RootPath, newStatus, slot, Data.ValidSubscriptionName[0], serviceName); Assert.IsTrue(statusUpdated); } }
public void SetAzureVMSizeProcessTestsLargeRoleInstanceFail() { string roleName = "WebRole1"; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, roleName, "Gigantic"), string.Format(Resources.InvalidVMSize, roleName)); } }
public void SetAzureVMSizeProcessTestsNodeRoleNameDoesNotExistServiceContainsWebRoleFail() { string roleName = "WebRole1"; string invalidRoleName = "foo"; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath, roleName, 1); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, invalidRoleName, RoleSize.Large.ToString()), string.Format(Resources.RoleNotFoundMessage, invalidRoleName)); } }
public void SetAzureServiceProjectRoleWithoutPassingRoleName() { string originalDirectory = Directory.GetCurrentDirectory(); string serviceName = "AzureService1"; AzureService service = new AzureService(Directory.GetCurrentDirectory(), serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); Directory.SetCurrentDirectory(Path.Combine(service.Paths.RootPath, "WebRole1")); cmdlet.RoleName = string.Empty; cmdlet.ExecuteCmdlet(); service = new AzureService(service.Paths.RootPath, null); Assert.AreEqual<string>("WebRole1", cmdlet.RoleName); Directory.SetCurrentDirectory(originalDirectory); }
public void SetAzureServiceProjectRoleInServiecRootDirectoryFail() { string serviceName = "AzureService3"; AzureService service = new AzureService(Directory.GetCurrentDirectory(), serviceName, null); service.AddWebRole(Data.NodeWebRoleScaffoldingPath); cmdlet.RoleName = string.Empty; Testing.AssertThrows<InvalidOperationException>(() => cmdlet.ExecuteCmdlet(), Resources.CannotFindServiceRoot); }
public void SetAzureInstancesProcessTestsRoleNameDoesNotExistFail() { string roleName = "WebRole1"; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, roleName, 10), string.Format(Resources.RoleNotFoundMessage, roleName)); } }
public void SetAzureInstancesProcessTestsPHPRoleNameDoesNotExistServiceContainsWorkerRoleFail() { string roleName = "WorkerRole1"; string invalidRoleName = "foo"; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); service.AddWorkerRole(Data.PHPWorkerRoleScaffoldingPath, roleName, 1); Testing.AssertThrows<ArgumentException>(() => service.SetRoleInstances(service.Paths, invalidRoleName, 10), string.Format(Resources.RoleNotFoundMessage, invalidRoleName)); } }
public void SetAzureInstancesProcessTestsPHP() { int newRoleInstances = 10; using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.PHPWebRoleScaffoldingPath); RoleSettings roleSettings = cmdlet.SetAzureInstancesProcess("WebRole1", newRoleInstances, service.Paths.RootPath); service = new AzureService(service.Paths.RootPath, null); Assert.AreEqual<int>(newRoleInstances, service.Components.CloudConfig.Role[0].Instances.count); Assert.AreEqual<int>(newRoleInstances, service.Components.LocalConfig.Role[0].Instances.count); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString()); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.AreEqual<int>(newRoleInstances, roleSettings.Instances.count); Assert.AreEqual<string>(roleName, roleSettings.name); } }
public void SetAzureVMSizeProcessTestsNullRoleNameFail() { using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); Testing.AssertThrows<ArgumentException>(() => service.SetRoleVMSize(service.Paths, null, RoleSize.Large.ToString()), string.Format(Resources.InvalidOrEmptyArgumentMessage, Resources.RoleName)); } }
/// <summary> /// Gets web role object from service definition. /// </summary> /// <param name="rootPath">The azure service rootPath path</param> /// <returns>The web role object</returns> internal static WebRole GetWebRole(string rootPath, string name) { AzureService service = new AzureService(rootPath, null); return service.Components.GetWebRole(name); }
/// <summary> /// Gets the role settings object from local service configuration. /// </summary> /// <param name="rootPath">The azure service rootPath path</param> /// <returns>The role settings object</returns> internal static RoleSettings GetLocalRole(string rootPath, string name) { AzureService service = new AzureService(rootPath, null); return service.Components.GetLocalConfigRole(name); }
public void SetAzureVMSizeProcessTestsPHP() { string newRoleVMSize = RoleSize.Medium.ToString(); using (FileSystemHelper files = new FileSystemHelper(this)) { AzureService service = new AzureService(files.RootPath, serviceName, null); string roleName = "WebRole1"; service.AddWebRole(Data.PHPWebRoleScaffoldingPath); RoleSettings roleSettings = cmdlet.SetAzureVMSizeProcess("WebRole1", newRoleVMSize, service.Paths.RootPath); service = new AzureService(service.Paths.RootPath, null); Assert.AreEqual<string>(newRoleVMSize, service.Components.Definition.WebRole[0].vmsize.ToString()); Assert.AreEqual<string>(roleName, ((PSObject)mockCommandRuntime.OutputPipeline[0]).Members[Parameters.RoleName].Value.ToString()); Assert.IsTrue(((PSObject)mockCommandRuntime.OutputPipeline[0]).TypeNames.Contains(typeof(RoleSettings).FullName)); Assert.AreEqual<string>(roleName, roleSettings.name); } }