public SystemModel Load(string modelDirectory) { var model = new YamlOctopusModel(); var files = FindFiles(modelDirectory); foreach (var subModel in files.SelectMany(LoadModels)) { model.MergeIn(subModel); } return(model.ApplyTemplates().BuildWith(new SystemModelBuilder()).Build()); }
public void It_should_apply_templates_on_model_convertion() { var yamlModel = new YamlOctopusModel { Templates = new YamlTemplates { DeploymentActions = new[] { new YamlDeploymentActionTemplate { TemplateName = "templateAction", TemplateParameters = new[] { "name" }, Name = "${name}" } }, DeploymentSteps = new[] { new YamlDeploymentStepTemplate { TemplateName = "templateStep", TemplateParameters = new[] { "name" }, Name = "${name}", Actions = new[] { new YamlDeploymentAction { UseTemplate = new YamlTemplateReference { Name = "templateAction", Arguments = new Dictionary <string, string> { { "name", "${name}_action" } } } } } } }, Projects = new[] { new YamlProjectTemplate { TemplateName = "templateProject", TemplateParameters = new[] { "name" }, Name = "${name}", DeploymentProcess = new YamlDeploymentProcess { Steps = new[] { new YamlDeploymentStep { UseTemplate = new YamlTemplateReference { Name = "templateStep", Arguments = new Dictionary <string, string> { { "name", "${name}_step" } } } } } } } } }, Projects = new[] { new YamlProject { UseTemplate = new YamlTemplateReference { Name = "templateProject", Arguments = new Dictionary <string, string> { { "name", "My_project" } }, }, TenantedDeploymentMode = TenantedDeploymentMode.TenantedOrUntenanted.ToString(), } } }; var model = yamlModel.ApplyTemplates().BuildWith(new SystemModelBuilder()).Build(); Assert.That(model.Projects.First().Identifier.Name, Is.EqualTo("My_project")); Assert.That(model.Projects.First().DeploymentProcess.DeploymentSteps.First().Name, Is.EqualTo("My_project_step")); Assert.That(model.Projects.First().DeploymentProcess.DeploymentSteps.First().Actions.First().Name, Is.EqualTo("My_project_step_action")); }
public void It_should_not_attempt_to_apply_templates_when_no_projects() { var yamlModel = new YamlOctopusModel { Templates = new YamlTemplates { DeploymentActions = new[] { new YamlDeploymentActionTemplate { TemplateName = "templateAction", TemplateParameters = new[] { "name" }, Name = "${name}" } }, DeploymentSteps = new[] { new YamlDeploymentStepTemplate { TemplateName = "templateStep", TemplateParameters = new[] { "name" }, Name = "${name}", Actions = new[] { new YamlDeploymentAction { UseTemplate = new YamlTemplateReference { Name = "templateAction", Arguments = new Dictionary <string, string> { { "name", "${name}_action" } } } } } } }, Projects = new[] { new YamlProjectTemplate { TemplateName = "templateProject", TemplateParameters = new[] { "name" }, Name = "${name}", DeploymentProcess = new YamlDeploymentProcess { Steps = new[] { new YamlDeploymentStep { UseTemplate = new YamlTemplateReference { Name = "templateStep", Arguments = new Dictionary <string, string> { { "name", "${name}_step" } } } } } } } } } }; var model = yamlModel.ApplyTemplates().BuildWith(new SystemModelBuilder()).Build(); Assert.That(model.Projects, Has.Length.EqualTo(0)); }