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_merge_models_with_nulls() { var model1 = new YamlOctopusModel { Lifecycles = new[] { new YamlLifecycle { Name = "N1" } }, Projects = new[] { new YamlProject { Name = "N1" } }, Templates = new YamlTemplates { DeploymentActions = new[] { new YamlDeploymentActionTemplate { Name = "PA1" } } }, UserRoles = new[] { new YamlUserRole { Name = "N1" } } }; var model2 = new YamlOctopusModel { ProjectGroups = new[] { new YamlProjectGroup { Name = "N2" } }, Templates = new YamlTemplates { Projects = new[] { new YamlProjectTemplate { Name = "PT2" } }, }, Teams = new[] { new YamlTeam { Name = "N2" } } }; model1.MergeIn(model2); Assert.That(model1.MachinePolicies, Is.Null); Assert.That(model1.LibraryVariableSets, Is.Null); Assert.That(model1.ProjectGroups.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N2" })); Assert.That(model1.Lifecycles.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1" })); Assert.That(model1.Projects.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1" })); Assert.That(model1.Templates.Projects.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "PT2" })); Assert.That(model1.Templates.DeploymentActions.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "PA1" })); Assert.That(model1.Templates.DeploymentSteps, Is.Null); Assert.That(model1.UserRoles.Select(s => s.Name), Is.EqualTo(new[] { "N1" })); Assert.That(model1.Teams.Select(s => s.Name), Is.EqualTo(new[] { "N2" })); }
public void It_should_merge_models() { var model1 = new YamlOctopusModel { MachinePolicies = new[] { new YamlMachinePolicy { Name = "N1" } }, LibraryVariableSets = new[] { new YamlLibraryVariableSet { Name = "N1" } }, ProjectGroups = new[] { new YamlProjectGroup { Name = "N1" } }, Lifecycles = new[] { new YamlLifecycle { Name = "N1" } }, Projects = new[] { new YamlProject { Name = "N1" } }, Templates = new YamlTemplates { Projects = new[] { new YamlProjectTemplate { Name = "PT1" } }, DeploymentSteps = new[] { new YamlDeploymentStepTemplate { Name = "PS1" } }, DeploymentActions = new[] { new YamlDeploymentActionTemplate { Name = "PA1" } } }, UserRoles = new[] { new YamlUserRole { Name = "N1" } }, Teams = new[] { new YamlTeam { Name = "N1" } }, Tenants = new[] { new YamlTenant { Name = "T1" } }, TagSets = new[] { new YamlTagSet { Name = "TS1" } } }; var model2 = new YamlOctopusModel { MachinePolicies = new[] { new YamlMachinePolicy { Name = "N2" } }, LibraryVariableSets = new[] { new YamlLibraryVariableSet { Name = "N2" } }, ProjectGroups = new[] { new YamlProjectGroup { Name = "N2" } }, Lifecycles = new[] { new YamlLifecycle { Name = "N2" } }, Projects = new[] { new YamlProject { Name = "N2" } }, Templates = new YamlTemplates { Projects = new[] { new YamlProjectTemplate { Name = "PT2" } }, DeploymentSteps = new[] { new YamlDeploymentStepTemplate { Name = "PS2" } }, DeploymentActions = new[] { new YamlDeploymentActionTemplate { Name = "PA2" } } }, UserRoles = new[] { new YamlUserRole { Name = "N2" } }, Teams = new[] { new YamlTeam { Name = "N2" } }, Tenants = new[] { new YamlTenant { Name = "T2" } }, TagSets = new[] { new YamlTagSet { Name = "TS2" } } }; model1.MergeIn(model2); Assert.That(model1.MachinePolicies.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.LibraryVariableSets.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.ProjectGroups.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.Lifecycles.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.Projects.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.Templates.Projects.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "PT1", "PT2" })); Assert.That(model1.Templates.DeploymentActions.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "PA1", "PA2" })); Assert.That(model1.Templates.DeploymentSteps.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "PS1", "PS2" })); Assert.That(model1.UserRoles.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.Teams.Select(s => s.Name).ToArray(), Is.EqualTo(new[] { "N1", "N2" })); Assert.That(model1.Tenants.Select(t => t.Name).ToArray(), Is.EqualTo(new[] { "T1", "T2" })); Assert.That(model1.TagSets.Select(t => t.Name).ToArray(), Is.EqualTo(new[] { "TS1", "TS2" })); }