public void InstantiateTemplate(string targetBaseDir, IParameterSet parameters = null, IVariableCollection variables = null) { if (parameters == null) { parameters = new MockParameterSet(); } if (variables == null) { variables = new VariableCollection(); } IRunnableProjectConfig runnableConfig = TemplateConfigTestHelpers.ConfigFromSource(_environment, SourceMountPoint); IFileSystemInfo configFileInfo = TemplateConfigTestHelpers.ConfigFileSystemInfo(SourceMountPoint, _configFile); runnableConfig.Evaluate(parameters, variables, configFileInfo); MockGlobalRunSpec runSpec = new MockGlobalRunSpec(); runSpec.RootVariableCollection = variables; IDirectory sourceDir = SourceMountPoint.DirectoryInfo("/"); IOrchestrator2 basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); foreach (FileSourceMatchInfo source in runnableConfig.Sources) { TemplateConfigTestHelpers.SetupFileSourceMatchersOnGlobalRunSpec(runSpec, source); string targetDirForSource = Path.Combine(targetBaseDir, source.Target); orchestrator.Run(runSpec, sourceDir, targetDirForSource); } }
public IReadOnlyDictionary <string, IReadOnlyList <IFileChange2> > GetFileChanges(string targetBaseDir, IParameterSet parameters = null, IVariableCollection variables = null) { if (parameters == null) { parameters = new MockParameterSet(); } if (variables == null) { variables = new VariableCollection(); } IRunnableProjectConfig runnableConfig = TemplateConfigTestHelpers.ConfigFromSource(_environment, SourceMountPoint); IFileSystemInfo configFileInfo = TemplateConfigTestHelpers.ConfigFileSystemInfo(SourceMountPoint, _configFile); runnableConfig.Evaluate(parameters, variables, configFileInfo); MockGlobalRunSpec runSpec = new MockGlobalRunSpec(); IDirectory sourceDir = SourceMountPoint.DirectoryInfo("/"); IOrchestrator2 basicOrchestrator = new Core.Util.Orchestrator(); RunnableProjectOrchestrator orchestrator = new RunnableProjectOrchestrator(basicOrchestrator); Dictionary <string, IReadOnlyList <IFileChange2> > changesByTarget = new Dictionary <string, IReadOnlyList <IFileChange2> >(); foreach (FileSourceMatchInfo source in runnableConfig.Sources) { TemplateConfigTestHelpers.SetupFileSourceMatchersOnGlobalRunSpec(runSpec, source); string targetDirForSource = Path.Combine(targetBaseDir, source.Target); IReadOnlyList <IFileChange2> changes = orchestrator.GetFileChanges(runSpec, sourceDir, targetDirForSource); changesByTarget[source.Target] = changes; } return(changesByTarget); }
public void ExcludeModifierOverridesPreviousIncludeModifierTemplateTest() { IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestTemplateSetup setup = SetupXYZFilesForModifierOverrideTestsTemplate(environment, sourceBasePath, ExcludeModifierOverridesPreviousIncludeModifierConfigText); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); IReadOnlyDictionary <string, IReadOnlyList <IFileChange> > allChanges = setup.GetFileChanges(targetDir); Assert.Equal(1, allChanges.Count); if (!allChanges.TryGetValue("./", out IReadOnlyList <IFileChange> changes)) { Assert.True(false, "no changes for source './'"); } Assert.Equal(2, changes.Count); IFileChange includeXyzChangeInfo = changes.FirstOrDefault(x => string.Equals(x.TargetRelativePath, "include.xyz")); Assert.NotNull(includeXyzChangeInfo); Assert.Equal(ChangeKind.Create, includeXyzChangeInfo.ChangeKind); IFileChange otherXyzChangeInfo = changes.FirstOrDefault(x => string.Equals(x.TargetRelativePath, "other.xyz")); Assert.NotNull(otherXyzChangeInfo); Assert.Equal(ChangeKind.Create, otherXyzChangeInfo.ChangeKind); }
public IReadOnlyDictionary <string, string> GetRenames(string sourceDir, string targetBaseDir, IParameterSet parameters, IReadOnlyList <IReplacementTokens> symbolBasedRenames) { IFileSystemInfo configFileInfo = TemplateConfigTestHelpers.ConfigFileSystemInfo(SourceMountPoint, _configFile); parameters.TryGetParameterDefinition("name", out ITemplateParameter nameParam); object resolvedNameValue = parameters.ResolvedValues[nameParam]; return(FileRenameGenerator.AugmentFileRenames(_environment, _sourceBaseDir, configFileInfo, sourceDir, ref targetBaseDir, resolvedNameValue, parameters, new Dictionary <string, string>(), symbolBasedRenames)); }
public void CanGenerateFileRenamesForSymbolBasedRenames_WhenFormsResultInSameValue() { //environment IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); //simulate template files string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); // template.json templateSourceFiles.Add(TemplateConfigTestHelpers.DefaultConfigRelativePath, String.Empty); // content templateSourceFiles.Add("replace1_file.txt", null); templateSourceFiles.Add("replace2_file.txt", null); TestTemplateSetup setup = new TestTemplateSetup(environment, sourceBasePath, templateSourceFiles); setup.WriteSource(); //get target directory string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); //prepare parameters ParameterSet parameters = new ParameterSet(SimpleConfigModel.FromJObject(environment, JObject.Parse("{}"))); Parameter nameParameter = new Parameter() { Name = "name" }; Parameter testParameterIdentity = new Parameter() { Name = "test{-VALUE-FORMS-}identity" }; Parameter testParameterLC = new Parameter() { Name = "test{-VALUE-FORMS-}lc" }; parameters.AddParameter(nameParameter); parameters.AddParameter(testParameterIdentity); parameters.AddParameter(testParameterLC); parameters.ResolvedValues[nameParameter] = "testName"; parameters.ResolvedValues[testParameterIdentity] = "testproject"; parameters.ResolvedValues[testParameterLC] = "testproject"; //prepare renames configuration List <IReplacementTokens> symbolBasedRenames = new List <IReplacementTokens>(); symbolBasedRenames.Add(new ReplacementTokens("test{-VALUE-FORMS-}identity", TokenConfig.FromValue("replace"))); symbolBasedRenames.Add(new ReplacementTokens("test{-VALUE-FORMS-}lc", TokenConfig.FromValue("replace"))); IReadOnlyDictionary <string, string> allChanges = setup.GetRenames("./", targetDir, parameters, symbolBasedRenames); Assert.Equal(2, allChanges.Count); Assert.Equal("testproject1_file.txt", allChanges["replace1_file.txt"]); Assert.Equal("testproject2_file.txt", allChanges["replace2_file.txt"]); }
public void CanReadFilenameReplacementConfigWithForms() { string configContent = @" { ""symbols"": { ""testparam"": { ""type"": ""parameter"", ""datatype"": ""string"", ""fileRename"": ""TestParamFileReplacement"", ""forms"": { ""global"" : [ ""identity"", ""lc"", ""uc""] } }, ""testgenerated"": { ""type"": ""generated"", ""generator"": ""casing"", ""parameters"": { ""source"": ""name"", ""toLower"": true }, ""fileRename"": ""testgeneratedfilereplacement"" }, ""testgenerated2"": { ""type"": ""generated"", ""generator"": ""casing"", ""parameters"": { ""source"": ""name"", ""toLower"": true }, ""replace"": ""testgeneratedreplacement"" }, }, ""forms"": { ""lc"": { ""identifier"": ""lowercase"" }, ""uc"": { ""identifier"": ""uppercase"" } } }"; IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); JObject configJson = JObject.Parse(configContent); SimpleConfigModel config = SimpleConfigModel.FromJObject(environment, configJson); Assert.Equal(4, config.SymbolFilenameReplacements.Count); Assert.Equal(3, config.SymbolFilenameReplacements.Count(x => x.VariableName.Contains("testparam"))); Assert.Equal("TestParamFileReplacement", config.SymbolFilenameReplacements.Single(x => x.VariableName == "testparam{-VALUE-FORMS-}identity").OriginalValue.Value); Assert.Equal("TESTPARAMFILEREPLACEMENT", config.SymbolFilenameReplacements.Single(x => x.VariableName == "testparam{-VALUE-FORMS-}uc").OriginalValue.Value); Assert.Equal("testparamfilereplacement", config.SymbolFilenameReplacements.Single(x => x.VariableName == "testparam{-VALUE-FORMS-}lc").OriginalValue.Value); Assert.Equal("testgeneratedfilereplacement", config.SymbolFilenameReplacements.Single(x => x.VariableName == "testgenerated").OriginalValue.Value); }
public void SplitConfigReadFailsIfAReferencedFileIsMissing() { string sourcePath = TemplateConfigTestHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); TestTemplateSetup setup = SetupSplitConfigWithAMissingReferencedFile(EngineEnvironmentSettings, sourcePath); IGenerator generator = new RunnableProjectGenerator(); IFileSystemInfo templateConfigFileInfo = setup.InfoForSourceFile(TemplateConfigTestHelpers.DefaultConfigRelativePath); bool result = generator.TryGetTemplateFromConfigInfo(templateConfigFileInfo, out ITemplate template, null, null); Assert.False(result, "Template config should not be readable - missing additional file."); Assert.Null(template); }
public void SourceConfigExcludesAreOverriddenByIncludes() { IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestTemplateSetup setup = SetupTwoFilesWithConfigExtensionTemplate(environment, sourceBasePath); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); setup.InstantiateTemplate(targetDir); Assert.True(environment.Host.FileSystem.FileExists(Path.Combine(targetDir, "core.config"))); Assert.False(environment.Host.FileSystem.FileExists(Path.Combine(targetDir, "full.config"))); }
public void SourceModifierRenameIsCaseSensitive() { IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestTemplateSetup setup = SetupSourceModifierRenameIsCaseSensitiveTestTemplate(environment, sourceBasePath); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); IReadOnlyDictionary <string, IReadOnlyList <IFileChange2> > allChanges = setup.GetFileChanges(targetDir); Assert.Equal(1, allChanges.Count); // one source had changes Assert.True(allChanges.TryGetValue("./", out IReadOnlyList <IFileChange2> changes), "No changes for source './'"); Assert.Equal(2, changes.Count); Assert.Equal(1, changes.Count(x => string.Equals(x.TargetRelativePath, "YesNewName.txt", StringComparison.Ordinal))); Assert.Equal(1, changes.Count(x => string.Equals(x.TargetRelativePath, "dontrenameme.txt", StringComparison.Ordinal))); Assert.Equal(0, changes.Count(x => string.Equals(x.TargetRelativePath, "NoNewName.txt", StringComparison.Ordinal))); }
public void SplitConfigTest() { string sourcePath = TemplateConfigTestHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); TestTemplateSetup setup = SetupSplitConfigTestTemplate(EngineEnvironmentSettings, sourcePath); IGenerator generator = new RunnableProjectGenerator(); IFileSystemInfo templateConfigFileInfo = setup.InfoForSourceFile(TemplateConfigTestHelpers.DefaultConfigRelativePath); generator.TryGetTemplateFromConfigInfo(templateConfigFileInfo, out ITemplate template, null, null); IDictionary <string, ITemplateParameter> parameters = template.Parameters.ToDictionary(p => p.Name, p => p); Assert.Equal(5, parameters.Count); Assert.True(parameters.ContainsKey("type")); Assert.True(parameters.ContainsKey("language")); Assert.True(parameters.ContainsKey("RuntimeFrameworkVersion")); Assert.True(parameters.ContainsKey("Framework")); Assert.True(parameters.ContainsKey("MyThing")); }
public void IncludeModifierOverridesPreviousExcludeModifierTemplateTest() { IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestTemplateSetup setup = SetupXYZFilesForModifierOverrideTestsTemplate(environment, sourceBasePath, IncludeModifierOverridesPreviousExcludeModifierConfigText); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); IReadOnlyDictionary <string, IReadOnlyList <IFileChange> > allChanges = setup.GetFileChanges(targetDir); Assert.Equal(1, allChanges.Count); if (!allChanges.TryGetValue("./", out IReadOnlyList <IFileChange> changes)) { Assert.True(false, "no changes for source './'"); } Assert.Equal(1, changes.Count); Assert.Equal(ChangeKind.Create, changes[0].ChangeKind); Assert.True(string.Equals(changes[0].TargetRelativePath, "include.xyz"), "include modifier didn't properly override exclude modifier"); }
public void CopyOnlyWithWildcardAndParentIncludeActuallyCopiesFile() { IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestTemplateSetup setup = SetupCopyOnlyWithWildcardAndParentInclude(environment, sourceBasePath); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); IReadOnlyDictionary <string, IReadOnlyList <IFileChange2> > allChanges = setup.GetFileChanges(targetDir); Assert.Equal(1, allChanges.Count); if (!allChanges.TryGetValue("./", out IReadOnlyList <IFileChange2> changes)) { Assert.True(false, "no changes for source './'"); } Assert.Equal(1, changes.Count); Assert.Equal(ChangeKind.Create, changes[0].ChangeKind); Assert.True(string.Equals(changes[0].TargetRelativePath, "copy.me"), "didn't copy the correct file"); }
public void CopyOnlyWithoutIncludeDoesntHappen() { IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestTemplateSetup setup = SetupCopyOnlyTemplate(environment, sourceBasePath); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); IReadOnlyDictionary <string, IReadOnlyList <IFileChange> > allChanges = setup.GetFileChanges(targetDir); // one source, should cause one set of changes Assert.Equal(1, allChanges.Count); if (!allChanges.TryGetValue("./", out IReadOnlyList <IFileChange> changes)) { Assert.True(false, "no changes for source './'"); } Assert.Equal(1, changes.Count); Assert.Equal(ChangeKind.Create, changes[0].ChangeKind); Assert.True(string.Equals(changes[0].TargetRelativePath, "something.txt"), "didn't copy the correct file"); }
public void CanReadFilenameReplacementConfig() { string configContent = @" { ""symbols"": { ""testparam"": { ""type"": ""parameter"", ""datatype"": ""string"", ""fileRename"": ""testparamfilereplacement"" }, ""testgenerated"": { ""type"": ""generated"", ""generator"": ""casing"", ""parameters"": { ""source"": ""name"", ""toLower"": true }, ""fileRename"": ""testgeneratedfilereplacement"" }, ""testgenerated2"": { ""type"": ""generated"", ""generator"": ""casing"", ""parameters"": { ""source"": ""name"", ""toLower"": true }, ""replace"": ""testgeneratedreplacement"" }, } } "; IEngineEnvironmentSettings environment = TemplateConfigTestHelpers.GetTestEnvironment(); JObject configJson = JObject.Parse(configContent); SimpleConfigModel config = SimpleConfigModel.FromJObject(environment, configJson); Assert.Equal(2, config.SymbolFilenameReplacements.Count); Assert.Equal("testparamfilereplacement", config.SymbolFilenameReplacements.Single(x => x.VariableName.Contains("testparam")).OriginalValue.Value); Assert.Equal("testgeneratedfilereplacement", config.SymbolFilenameReplacements.Single(x => x.VariableName == "testgenerated").OriginalValue.Value); }