private static void ProcessParameters(IParameterSet parameters) { ParameterSet p = (ParameterSet)parameters; ITemplateParameter safeProjectName = new Parameter("safeprojectname", TemplateParameterPriority.Required, "string"); p.AddParameter(safeProjectName); ITemplateParameter itemName = new Parameter("itemname", TemplateParameterPriority.Required, "string"); p.AddParameter(itemName); ITemplateParameter safeItemName = new Parameter("safeitemname", TemplateParameterPriority.Required, "string"); p.AddParameter(safeItemName); ITemplateParameter fileInputName = new Parameter("fileinputname", TemplateParameterPriority.Required, "string"); p.AddParameter(fileInputName); ITemplateParameter projectName; p.TryGetParameter("projectname", out projectName); p.ParameterValues[safeProjectName] = p.ParameterValues[projectName]; p.ParameterValues[itemName] = p.ParameterValues[projectName]; p.ParameterValues[safeItemName] = p.ParameterValues[projectName]; p.ParameterValues[fileInputName] = p.ParameterValues[projectName]; }
public void CanGenerateFileRenamesForSymbolBasedRenames_NonString() { //environment IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); //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("date_name.txt", null); templateSourceFiles.Add("other_name.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 intDateParameter = new Parameter() { Name = "date" }; Parameter otherParameter = new Parameter() { Name = "other" }; parameters.AddParameter(nameParameter); parameters.AddParameter(intDateParameter); parameters.AddParameter(otherParameter); parameters.ResolvedValues[nameParameter] = "testName"; parameters.ResolvedValues[intDateParameter] = 20210429; parameters.ResolvedValues[otherParameter] = new TestParameterValueClass { A = "foo", B = "bar" }; //prepare renames configuration List <IReplacementTokens> symbolBasedRenames = new List <IReplacementTokens>(); symbolBasedRenames.Add(new ReplacementTokens("date", TokenConfig.FromValue("date"))); symbolBasedRenames.Add(new ReplacementTokens("other", TokenConfig.FromValue("other"))); symbolBasedRenames.Add(new ReplacementTokens("name", TokenConfig.FromValue("name"))); IReadOnlyDictionary <string, string> allChanges = setup.GetRenames("./", targetDir, parameters, symbolBasedRenames); Assert.Equal(2, allChanges.Count); Assert.Equal("20210429_testName.txt", allChanges["date_name.txt"]); Assert.Equal("foo-bar_testName.txt", allChanges["other_name.txt"]); }
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 CanGenerateFileRenamesForSymbolBasedRenames_Multiple() { //environment IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); //simulate template files string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.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(A.Fake <IRunnableProjectConfig>()); Parameter nameParameter = new Parameter() { Name = "name" }; Parameter testParameter = new Parameter() { Name = "test" }; parameters.AddParameter(nameParameter); parameters.AddParameter(testParameter); parameters.ResolvedValues[nameParameter] = "testName"; parameters.ResolvedValues[testParameter] = "ReplaceValue"; //prepare renames configuration List <IReplacementTokens> symbolBasedRenames = new List <IReplacementTokens>(); symbolBasedRenames.Add(new ReplacementTokens("test", TokenConfig.FromValue("Replace"))); IReadOnlyDictionary <string, string> allChanges = setup.GetRenames("./", targetDir, parameters, symbolBasedRenames); Assert.Equal(2, allChanges.Count); Assert.Equal("ReplaceValue1_file.txt", allChanges["Replace1_file.txt"]); Assert.Equal("ReplaceValue2_file.txt", allChanges["Replace2_file.txt"]); }
public IParameterSet GetParametersForTemplate(ITemplate template) { ParameterSet result = new ParameterSet(); VsTemplate tmplt = (VsTemplate)template; foreach (CustomParameter param in tmplt.CustomParameters) { result.AddParameter(new Parameter(param.Name, TemplateParameterPriority.Optional, "string", defaultValue: param.DefaultValue)); } return(result); }