public static void AzureServiceExists(string serviceRootPath, string scaffoldFilePath, string serviceName, ServiceSettings settings = null, WebRoleInfo[] webRoles = null, WorkerRoleInfo[] workerRoles = null, string webScaff = null, string workerScaff = null, RoleInfo[] roles = null) { ServiceComponents components = new Microsoft.WindowsAzure.Management.CloudService.Model.ServiceComponents(new Microsoft.WindowsAzure.Management.CloudService.Model.ServicePathInfo(serviceRootPath)); ScaffoldingExists(serviceRootPath, scaffoldFilePath); if (webRoles != null) { for (int i = 0; i < webRoles.Length; i++) { ScaffoldingExists(Path.Combine(serviceRootPath, webRoles[i].Name), webScaff); } } if (workerRoles != null) { for (int i = 0; i < workerRoles.Length; i++) { ScaffoldingExists(Path.Combine(serviceRootPath, workerRoles[i].Name), workerScaff); } } AreEqualServiceConfiguration(components.LocalConfig, serviceName, roles); AreEqualServiceConfiguration(components.CloudConfig, serviceName, roles); IsValidServiceDefinition(components.Definition, serviceName, webRoles, workerRoles); AreEqualServiceSettings(settings ?? new ServiceSettings(), components.Settings); }
public static void AreEqualServiceComponents(ServiceComponents actual) { Assert.IsNotNull(actual.CloudConfig); Assert.IsNotNull(actual.Definition); Assert.IsNotNull(actual.LocalConfig); Assert.IsNotNull(actual.Settings); }
public AzureService(string serviceParentDirectory, string name, string scaffoldingPath) : this() { Validate.ValidateDirectoryFull(serviceParentDirectory, Resources.ServiceParentDirectory); Validate.ValidateStringIsNullOrEmpty(name, "Name"); Validate.ValidateFileName(name, string.Format(Resources.InvalidFileName, "Name")); Validate.ValidateDnsName(name, "Name"); string newServicePath = Path.Combine(serviceParentDirectory, name); if (Directory.Exists(newServicePath)) { throw new ArgumentException(string.Format(Resources.ServiceAlreadyExistsOnDisk, name, newServicePath)); } SetScaffolding(scaffoldingPath); Paths = new ServicePathInfo(newServicePath); CreateNewService(Paths.RootPath, name); Components = new ServiceComponents(Paths); ConfigureNewService(Components, Paths, name); }
/// <summary> /// Creates a role name, ensuring it doesn't already exist. If null is passed in, a number will be appended to the defaultRoleName. /// </summary> /// <param name="name"></param> /// <param name="defaultName"></param> /// <param name="existingNames"></param> /// <returns></returns> private string GetRoleName(string name, string defaultName, IEnumerable <string> existingNames) { if (!string.IsNullOrEmpty(name)) { if (existingNames.Contains(name.ToLower())) { // Role does exist, user should pick a unique name // throw new ArgumentException(string.Format(Resources.AddRoleMessageRoleExists, name)); } if (!ServiceComponents.ValidRoleName(name)) { // The provided name is invalid role name // throw new ArgumentException(string.Format(Resources.InvalidRoleNameMessage, name)); } } if (name == null) { name = defaultName; } else { return(name); } int index = 1; string curName = name + index.ToString(); while (existingNames.Contains(curName.ToLower())) { curName = name + (++index).ToString(); } return(curName); }
private void ConfigureNewService(ServiceComponents components, ServicePathInfo paths, string serviceName) { Components.Definition.name = serviceName; Components.CloudConfig.serviceName = serviceName; Components.LocalConfig.serviceName = serviceName; Components.Save(paths); }
public AzureService(string rootPath, string scaffoldingPath) { SetScaffolding(scaffoldingPath); Paths = new ServicePathInfo(rootPath); Components = new ServiceComponents(Paths); }
public void ServiceComponentsTestSettingsDoesNotExistFail() { new NewAzureServiceProjectCommand().NewAzureServiceProcess(Directory.GetCurrentDirectory(), serviceName); ServicePathInfo paths = new ServicePathInfo(serviceName); try { File.Delete(paths.Settings); ServiceComponents components = new ServiceComponents(paths); Assert.Fail("No exception was thrown"); } catch (Exception ex) { Assert.IsTrue(ex is FileNotFoundException); Assert.AreEqual<string>(string.Format(Resources.PathDoesNotExistForElement, Resources.ServiceSettings, paths.Settings), ex.Message); } }
public void ServiceComponentsTestNullPathsFail() { try { ServiceComponents components = new ServiceComponents(null); Assert.Fail("No exception was thrown"); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); Assert.AreEqual<string>(ex.Message, string.Format(Resources.NullObjectMessage, "paths")); } }
public void ServiceComponentsTest() { new NewAzureServiceProjectCommand().NewAzureServiceProcess(Directory.GetCurrentDirectory(), serviceName); ServiceComponents components = new ServiceComponents(new ServicePathInfo(serviceName)); AzureAssert.AreEqualServiceComponents(components); }