public void UnknownFormNameForDerivedSymbolValueDoesNotThrow() { string templateJson = @" { ""name"": ""TestTemplate"", ""identity"": ""TestTemplate"", ""symbols"": { ""original"": { ""type"": ""parameter"", ""replaces"": ""whatever"", }, ""myDerivedSym"": { ""type"": ""derived"", ""valueSource"": ""original"", ""valueTransform"": ""fakeForm"", ""replaces"": ""something"" } } } "; JObject configObj = JObject.Parse(templateJson); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(configObj); IGlobalRunConfig runConfig = null; try { runConfig = new RunnableProjectConfig(_engineEnvironmentSettings, A.Fake <IGenerator>(), configModel).OperationConfig; } catch { Assert.True(false, "Should not throw on unknown value form name"); } Assert.NotNull(runConfig); }
public async void CreateAsyncTest_ConditionWithUnquotedChoiceLiteral(string templateConfig, string expectedResult) { // // Template content preparation // string sourceSnippet = @" //#if( ChoiceParam == FirstChoice ) FIRST //#elseif (ChoiceParam == SecondChoice ) SECOND //#elseif (ChoiceParam == ThirdChoice ) THIRD //#else UNKNOWN //#endif "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, templateConfig); //content templateSourceFiles.Add("sourcFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); ITemplateParameter choiceParameter; Assert.True(parameters.TryGetParameterDefinition("ChoiceParam", out choiceParameter), "ChoiceParam expected to be extracted from template config"); parameters.ResolvedValues[choiceParameter] = "SecondChoice"; IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, "sourcFile")).Trim(); Assert.Equal(expectedResult, resultContent); }
public void CheckTemplateRootRelativeToInstallPath(string pathToTemplateJson, bool shouldAllPathsBeValid) { SimpleConfigModel baseConfig = SimpleConfigModel.FromJObject(JObject.Parse(BasicTemplateConfig)); RunnableProjectGenerator generator = new RunnableProjectGenerator(); string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(pathToTemplateJson, BasicTemplateConfig); TestTemplateSetup setup = new TestTemplateSetup(_engineEnvironmentSettings, sourcePath, templateSourceFiles); setup.WriteSource(); IFile templateFile = setup.FileInfoForSourceFile(pathToTemplateJson); RunnableProjectConfig templateModel = new RunnableProjectConfig(_engineEnvironmentSettings, generator, baseConfig, templateFile); if (shouldAllPathsBeValid) { Assert.Empty(templateModel.ValidateTemplateSourcePaths()); } else { Assert.NotEmpty(templateModel.ValidateTemplateSourcePaths()); } }
public void CheckTemplateSourcesRelativeToTemplateRootMultipleDirsUnderMountPoint(bool shouldAllPathsBeValid, string source) { string templateConfig = string.Format(TemplateConfigWithSourcePlaceholder, source); SimpleConfigModel baseConfig = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); RunnableProjectGenerator generator = new RunnableProjectGenerator(); const string pathFromMountPointRootToTemplateRoot = "MountRoot/Stuff/TemplateRoot/"; string pathToTemplateConfig = pathFromMountPointRootToTemplateRoot + ".template.config/template.json"; string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(pathToTemplateConfig, templateConfig); string sampleContentDir = pathFromMountPointRootToTemplateRoot + "things/stuff/_._"; templateSourceFiles.Add(sampleContentDir, ""); // directories under the template root - valid source locations. templateSourceFiles.Add("ExistingDir/_._", ""); templateSourceFiles.Add("MountRoot/Subdir/_._", ""); TestTemplateSetup setup = new TestTemplateSetup(_engineEnvironmentSettings, sourcePath, templateSourceFiles); setup.WriteSource(); IFile templateFile = setup.FileInfoForSourceFile(pathToTemplateConfig); RunnableProjectConfig templateModel = new RunnableProjectConfig(_engineEnvironmentSettings, generator, baseConfig, templateFile); if (shouldAllPathsBeValid) { Assert.Empty(templateModel.ValidateTemplateSourcePaths()); } else { Assert.NotEmpty(templateModel.ValidateTemplateSourcePaths()); } }
public void CanValidatePostActionWithDefaultInstructionLocalization() { SimpleConfigModel baseConfig = new SimpleConfigModel() { Identity = "Test", PostActionModels = new List <PostActionModel> { new PostActionModel() { Id = "pa0", Description = "text", ActionId = Guid.NewGuid(), ManualInstructionInfo = new List <ManualInstructionModel>() { new ManualInstructionModel(null, "my text") } }, } }; IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true); string tempFolder = _environmentSettingsHelper.CreateTemporaryFolder(); string localizationFile = string.Format(DefaultLocalizeConfigRelativePath, "de-DE"); WriteFile(Path.Combine(tempFolder, localizationFile), "{ \"postActions/pa0/manualInstructions/default/text\": \"localized\" }", environmentSettings); using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings); var runnableProjectConfig = new RunnableProjectConfig(environmentSettings, A.Fake <IGenerator>(), baseConfig); var localizationModel = LocalizationModelDeserializer.Deserialize(mountPoint.FileInfo(localizationFile) !); Assert.True(runnableProjectConfig.VerifyLocalizationModel(localizationModel)); runnableProjectConfig.ConfigurationModel.Localize(localizationModel); runnableProjectConfig.PostActionModels.Single(model => model.Id == "pa0" && model.ManualInstructionInfo[0].Text == "localized"); }
public void CanReadFilenameReplacementConfigWithForms() { string configContent = @" { ""identity"": ""test"", ""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"" } } }"; SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(configContent)); IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); RunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, A.Fake <IGenerator>(), configModel); Assert.Equal(4, runnableConfig.SymbolFilenameReplacements.Count); Assert.Equal(3, runnableConfig.SymbolFilenameReplacements.Count(x => x.VariableName.Contains("testparam"))); Assert.Equal("TestParamFileReplacement", runnableConfig.SymbolFilenameReplacements.Single(x => x.VariableName == "testparam{-VALUE-FORMS-}identity").OriginalValue.Value); Assert.Equal("TESTPARAMFILEREPLACEMENT", runnableConfig.SymbolFilenameReplacements.Single(x => x.VariableName == "testparam{-VALUE-FORMS-}uc").OriginalValue.Value); Assert.Equal("testparamfilereplacement", runnableConfig.SymbolFilenameReplacements.Single(x => x.VariableName == "testparam{-VALUE-FORMS-}lc").OriginalValue.Value); Assert.Equal("testgeneratedfilereplacement", runnableConfig.SymbolFilenameReplacements.Single(x => x.VariableName == "testgenerated").OriginalValue.Value); }
public void CannotValidatePostActionWithExtraInstructionLocalization() { SimpleConfigModel baseConfig = new SimpleConfigModel() { Identity = "Test", PostActionModels = new List <PostActionModel> { new PostActionModel() { Id = "pa0", Description = "text", ActionId = Guid.NewGuid(), ManualInstructionInfo = new List <ManualInstructionModel>() { new ManualInstructionModel("first", "my text"), new ManualInstructionModel("second", "my text"), } }, } }; List <(LogLevel, string)> loggedMessages = new List <(LogLevel, string)>(); InMemoryLoggerProvider loggerProvider = new InMemoryLoggerProvider(loggedMessages); IEngineEnvironmentSettings environmentSettings = _environmentSettingsHelper.CreateEnvironment(virtualize: true, addLoggerProviders: new[] { loggerProvider }); string tempFolder = _environmentSettingsHelper.CreateTemporaryFolder(); string localizationFilename = string.Format(DefaultLocalizeConfigRelativePath, "de-DE"); WriteFile( Path.Combine(tempFolder, localizationFilename), "{ \"postActions/pa0/manualInstructions/first/text\": \"localized\", \"postActions/pa0/manualInstructions/extra/text\": \"extraLoc\" }", environmentSettings); using IMountPoint mountPoint = GetMountPointForPath(tempFolder, environmentSettings); var templateConfig = new RunnableProjectConfig(environmentSettings, A.Fake <IGenerator>(), baseConfig); var localizationFile = mountPoint.FileInfo(localizationFilename); var localizationModel = LocalizationModelDeserializer.Deserialize(localizationFile !); Assert.False(templateConfig.VerifyLocalizationModel(localizationModel, localizationFile)); var warningMessages = loggedMessages.Where(log => log.Item1 == LogLevel.Warning); Assert.Single(warningMessages); Assert.Contains( string.Format(LocalizableStrings.Authoring_InvalidManualInstructionLocalizationIndex, "extra", "pa0"), warningMessages.Single().Item2); Assert.Contains(localizationFilename, warningMessages.Single().Item2); }
public void CanReadFilenameReplacementConfig() { string configContent = @" { ""identity"": ""test"", ""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"" }, } } "; SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(configContent)); IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); RunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, A.Fake <IGenerator>(), configModel); Assert.Equal(2, runnableConfig.SymbolFilenameReplacements.Count); Assert.Equal("testparamfilereplacement", runnableConfig.SymbolFilenameReplacements.Single(x => x.VariableName.Contains("testparam")).OriginalValue.Value); Assert.Equal("testgeneratedfilereplacement", runnableConfig.SymbolFilenameReplacements.Single(x => x.VariableName == "testgenerated").OriginalValue.Value); }
public void UnknownFormNameOnParameterSymbolDoesNotThrow() { string templateJson = @" { ""name"": ""TestTemplate"", ""identity"": ""TestTemplate"", ""symbols"": { ""mySymbol"": { ""type"": ""parameter"", ""replaces"": ""whatever"", ""forms"": { ""global"": [ ""fakeName"" ], } } } } "; JObject configObj = JObject.Parse(templateJson); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(configObj); IGlobalRunConfig runConfig = null; try { runConfig = new RunnableProjectConfig(_engineEnvironmentSettings, A.Fake <IGenerator>(), configModel).OperationConfig; } catch { Assert.True(false, "Should not throw on unknown value form name"); } Assert.NotNull(runConfig); Assert.Equal(1, runConfig.Macros.Count(m => m.VariableName.StartsWith("mySymbol"))); var mySymbolMacro = runConfig.Macros.Single(m => m.VariableName.StartsWith("mySymbol")); Assert.True(mySymbolMacro is ProcessValueFormMacroConfig); ProcessValueFormMacroConfig identityFormConfig = mySymbolMacro as ProcessValueFormMacroConfig; Assert.Equal("identity", identityFormConfig.FormName); }
public async void CreateAsyncTest_MultiChoiceParamJoining() { // // Template content preparation // string templateConfig = @" { ""identity"": ""test.template"", ""symbols"": { ""Platform"": { ""type"": ""parameter"", ""description"": ""The target framework for the project."", ""datatype"": ""choice"", ""allowMultipleValues"": true, ""choices"": [ { ""choice"": ""Windows"", ""description"": ""Windows Desktop"" }, { ""choice"": ""WindowsPhone"", ""description"": ""Windows Phone"" }, { ""choice"": ""MacOS"", ""description"": ""Macintosh computers"" }, { ""choice"": ""iOS"", ""description"": ""iOS mobile"" }, { ""choice"": ""android"", ""description"": ""android mobile"" }, { ""choice"": ""nix"", ""description"": ""Linux distributions"" } ], ""defaultValue"": ""MacOS|iOS"" }, ""joinedRename"": { ""type"": ""generated"", ""generator"": ""join"", ""replaces"": ""SupportedPlatforms"", ""parameters"": { ""symbols"": [ { ""type"": ""ref"", ""value"": ""Platform"" } ], ""separator"": "", "", ""removeEmptyValues"": true, } } } } "; string sourceSnippet = @" // This file is generated for platfrom: SupportedPlatforms "; string expectedSnippet = @" // This file is generated for platfrom: MacOS, iOS "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, templateConfig); //content templateSourceFiles.Add("sourcFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); ITemplateParameter choiceParameter; Assert.True(parameters.TryGetParameterDefinition("Platform", out choiceParameter), "ChoiceParam expected to be extracted from template config"); parameters.ResolvedValues[choiceParameter] = new MultiValueParameter(new[] { "MacOS", "iOS" }); IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, "sourcFile")); Assert.Equal(expectedSnippet, resultContent); }
public async void CreateAsyncTest_GuidsMacroProcessingCaseSensitivity() { // // Template content preparation // Guid inputTestGuid = new Guid("12aa8f4e-a4aa-4ac1-927c-94cb99485ef1"); string contentFileNamePrefix = "content - "; SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Guids = new List <Guid>() { inputTestGuid } }; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); //content foreach (string guidFormat in GuidMacroConfig.DefaultFormats.Select(c => c.ToString())) { templateSourceFiles.Add(contentFileNamePrefix + guidFormat, inputTestGuid.ToString(guidFormat)); } // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint? sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, config, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // Guid expectedResultGuid = Guid.Empty; foreach (string guidFormat in GuidMacroConfig.DefaultFormats.Select(c => c.ToString())) { string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, contentFileNamePrefix + guidFormat)); Guid resultGuid; Assert.True( Guid.TryParseExact(resultContent, guidFormat, out resultGuid), $"Expected the result conent ({resultContent}) to be parseable by Guid format '{guidFormat}'"); if (expectedResultGuid == Guid.Empty) { expectedResultGuid = resultGuid; } else { Assert.Equal(expectedResultGuid, resultGuid); } } Assert.NotEqual(inputTestGuid, expectedResultGuid); }
public async void CreateAsyncTest_MultiChoiceParamReplacingAndCondition() { // // Template content preparation // string templateConfig = @" { ""identity"": ""test.template"", ""symbols"": { ""ChoiceParam"": { ""type"": ""parameter"", ""description"": ""sample switch"", ""datatype"": ""choice"", ""allowMultipleValues"": true, ""enableQuotelessLiterals"": true, ""choices"": [ { ""choice"": ""FirstChoice"", ""description"": ""First Sample Choice"" }, { ""choice"": ""SecondChoice"", ""description"": ""Second Sample Choice"" }, { ""choice"": ""ThirdChoice"", ""description"": ""Third Sample Choice"" } ], ""defaultValue"": ""ThirdChoice"", ""replaces"": ""REPLACE_VALUE"" } } } "; string sourceSnippet = @" MultiChoiceValue: REPLACE_VALUE //#if( ChoiceParam == FirstChoice ) FIRST //#endif //#if (ChoiceParam == SecondChoice ) SECOND //#endif //#if (ChoiceParam == ThirdChoice ) THIRD //#endif "; string expectedSnippet = @" MultiChoiceValue: SecondChoice|ThirdChoice SECOND THIRD "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, templateConfig); //content templateSourceFiles.Add("sourcFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(templateConfig)); IRunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); IParameterSet parameters = new ParameterSet(runnableConfig); ITemplateParameter choiceParameter; Assert.True(parameters.TryGetParameterDefinition("ChoiceParam", out choiceParameter), "ChoiceParam expected to be extracted from template config"); parameters.ResolvedValues[choiceParameter] = new MultiValueParameter(new[] { "SecondChoice", "ThirdChoice" }); IDirectory sourceDir = sourceMountPoint !.DirectoryInfo("/") !; // // Running the actual scenario: template files processing and generating output (including macros processing) // await rpg.CreateAsync(environment, runnableConfig, sourceDir, parameters, targetDir, CancellationToken.None); // // Veryfying the outputs // string resultContent = environment.Host.FileSystem.ReadAllText(Path.Combine(targetDir, "sourcFile")); Assert.Equal(expectedSnippet, resultContent); }
public void PerformTemplateValidation_ChoiceValuesValidation(string paramDefintion, bool isMultichoice, bool expectedToBeValid) { // // Template content preparation // Guid inputTestGuid = new Guid("12aa8f4e-a4aa-4ac1-927c-94cb99485ef1"); string contentFileNamePrefix = "content - "; JObject choiceParam = JObject.Parse(paramDefintion); choiceParam["AllowMultipleValues"] = isMultichoice; SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Name = "name", ShortNameList = new [] { "shortName" }, Symbols = new Dictionary <string, ISymbolModel>() { { "ParamA", new ParameterSymbol(choiceParam, null) } } }; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); //content foreach (string guidFormat in GuidMacroConfig.DefaultFormats.Select(c => c.ToString())) { templateSourceFiles.Add(contentFileNamePrefix + guidFormat, inputTestGuid.ToString(guidFormat)); } // // Dependencies preparation and mounting // List <(LogLevel, string)> loggedMessages = new List <(LogLevel, string)>(); InMemoryLoggerProvider loggerProvider = new InMemoryLoggerProvider(loggedMessages); IEngineEnvironmentSettings environment = _environmentSettingsHelper.CreateEnvironment(addLoggerProviders: new [] { loggerProvider }); string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(environment); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint? sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectConfig runnableConfig = new RunnableProjectConfig(environment, rpg, config, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); if (expectedToBeValid) { runnableConfig.PerformTemplateValidation(); Assert.Empty(loggedMessages.Where(l => l.Item1 >= LogLevel.Warning)); } else { var exc = Assert.Throws <TemplateValidationException>(runnableConfig.PerformTemplateValidation); Assert.Contains("The template configuration ", exc.Message); Assert.Contains(" is not valid.", exc.Message); Assert.Single(loggedMessages.Where(l => l.Item1 >= LogLevel.Warning)); string errorMessage = loggedMessages.First(l => l.Item1 >= LogLevel.Warning).Item2; Assert.Contains( "Choice parameter is invalid. It allows multiple values ('AllowMultipleValues=true'), while some of the configured choices contain separator characters ('|', ','). Invalid choices: {First|Choice}", errorMessage); } }
public async void InstantiateAsync_ParamsProperlyHonored(string?parameterValue, string expectedOutput, bool instantiateShouldFail) { // // Template content preparation // string sourceSnippet = @" //#if( ChoiceParam == FirstChoice ) FIRST //#elseif (ChoiceParam == SecondChoice ) SECOND //#elseif (ChoiceParam == ThirdChoice ) THIRD //#else UNKNOWN //#endif "; IDictionary <string, string?> templateSourceFiles = new Dictionary <string, string?>(); // template.json templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, TemplateConfigQuotelessLiteralsEnabled); //content templateSourceFiles.Add("sourceFile", sourceSnippet); // // Dependencies preparation and mounting // IEngineEnvironmentSettings environment = _engineEnvironmentSettings; string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(environment); TestFileSystemHelper.WriteTemplateSource(environment, sourceBasePath, templateSourceFiles); IMountPoint?sourceMountPoint = TestFileSystemHelper.CreateMountPoint(environment, sourceBasePath); RunnableProjectGenerator rpg = new RunnableProjectGenerator(); // cannot use SimpleConfigModel dirrectly - due to missing easy way of creating ParameterSymbols SimpleConfigModel configModel = SimpleConfigModel.FromJObject(JObject.Parse(TemplateConfigQuotelessLiteralsEnabled)); var runnableConfig = new RunnableProjectConfig(environment, rpg, configModel, sourceMountPoint.FileInfo(TestFileSystemHelper.DefaultConfigRelativePath)); TemplateCreator creator = new TemplateCreator(_engineEnvironmentSettings); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); IReadOnlyDictionary <string, string?> parameters = new Dictionary <string, string?>() { { "ChoiceParam", parameterValue } }; var res = await creator.InstantiateAsync( templateInfo : runnableConfig, name : "tst", fallbackName : "tst2", inputParameters : parameters, outputPath : targetDir); if (instantiateShouldFail) { Assert.NotNull(res.ErrorMessage); Assert.Null(res.OutputBaseDirectory); } else { Assert.Null(res.ErrorMessage); Assert.NotNull(res.OutputBaseDirectory); string resultContent = _engineEnvironmentSettings.Host.FileSystem .ReadAllText(Path.Combine(res.OutputBaseDirectory !, "sourceFile")).Trim(); Assert.Equal(expectedOutput, resultContent); } }