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 AddRefIgnoresOtherProjectTypesWhenMultipleTypesAreAllowed() { string targetBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); string fooprojFileFullPath = Path.Combine(targetBasePath, "MyApp.fooproj"); _engineEnvironmentSettings.Host.FileSystem.WriteAllText(fooprojFileFullPath, TestCsprojFile); string barprojFileFullPath = Path.Combine(targetBasePath, "MyApp.barproj"); _engineEnvironmentSettings.Host.FileSystem.WriteAllText(barprojFileFullPath, TestCsprojFile); string csprojFileFullPath = Path.Combine(targetBasePath, "MyApp.csproj"); _engineEnvironmentSettings.Host.FileSystem.WriteAllText(csprojFileFullPath, TestCsprojFile); string fsprojFileFullPath = Path.Combine(targetBasePath, "MyApp.fsproj"); _engineEnvironmentSettings.Host.FileSystem.WriteAllText(fsprojFileFullPath, TestCsprojFile); AddReferencePostActionProcessor actionProcessor = new AddReferencePostActionProcessor(); string outputBasePath = targetBasePath; HashSet <string> projectFileExtensions = new HashSet <string>() { ".bazproj", ".fsproj" }; IReadOnlyList <string> projFilesFound = actionProcessor.FindProjFileAtOrAbovePath(_engineEnvironmentSettings.Host.FileSystem, outputBasePath, projectFileExtensions); Assert.Equal(1, projFilesFound.Count); }
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 CheckTemplateSourcesRelativeToTemplateRootMultipleDirsUnderMountPoint(bool shouldAllPathsBeValid, string source) { 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>(); string templateConfig = String.Format(TemplateConfigWithSourcePlaceholder, source); 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(); RunnableProjectGenerator generator = new RunnableProjectGenerator(); IFile templateFile = setup.FileInfoForSourceFile(pathToTemplateConfig); JObject srcObject = generator.ReadJObjectFromIFile(templateFile); SimpleConfigModel templateModel = SimpleConfigModel.FromJObject(templateFile.MountPoint.EnvironmentSettings, srcObject); RunnableProjectTemplate runnableProjectTemplate = new RunnableProjectTemplate(srcObject, generator, templateFile, templateModel, null, null); bool allPathsAreValid = generator.AreAllTemplatePathsValid(templateModel, runnableProjectTemplate); Assert.Equal(shouldAllPathsBeValid, allPathsAreValid); }
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 void AddProjectToSolutionPostActionWithoutPrimaryOutputIndexesWithOutputBasePath() { string outputBasePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); IPostAction postAction = new MockPostAction() { ActionId = AddProjectsToSolutionPostAction.ActionProcessorId, Args = new Dictionary <string, string>() }; ICreationResult creationResult = new MockCreationResult() { PrimaryOutputs = new List <ICreationPath>() { new MockCreationPath() { Path = "outputProj1.csproj" }, new MockCreationPath() { Path = "outputProj2.csproj" }, } }; string outputFileFullPath0 = Path.Combine(outputBasePath, creationResult.PrimaryOutputs[0].Path); string outputFileFullPath1 = Path.Combine(outputBasePath, creationResult.PrimaryOutputs[1].Path); Assert.True(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(EngineEnvironmentSettings, postAction, creationResult, outputBasePath, out IReadOnlyList <string> foundProjectFiles)); Assert.Equal(2, foundProjectFiles.Count); Assert.Contains(outputFileFullPath0, foundProjectFiles.ToList()); Assert.Contains(outputFileFullPath1, foundProjectFiles.ToList()); }
public void AddProjectToSolutionPostActionFindsMultipleProjectsToAdd() { string outputBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); IPostAction postAction = new MockPostAction() { ActionId = AddProjectsToSolutionPostAction.ActionProcessorId, Args = new Dictionary <string, string>() { { "primaryOutputIndexes", "0; 2" } } }; ICreationResult creationResult = new MockCreationResult( primaryOutputs: new[] { new MockCreationPath(Path.GetFullPath("outputProj1.csproj")), new MockCreationPath(Path.GetFullPath("dontFindMe.csproj")), new MockCreationPath(Path.GetFullPath("outputProj2.csproj")) }); Assert.True(AddProjectsToSolutionPostAction.TryGetProjectFilesToAdd(postAction, creationResult, outputBasePath, out IReadOnlyList <string>?foundProjectFiles)); Assert.Equal(2, foundProjectFiles?.Count); Assert.Contains(creationResult.PrimaryOutputs[0].Path, foundProjectFiles?.ToList()); Assert.Contains(creationResult.PrimaryOutputs[2].Path, foundProjectFiles?.ToList()); Assert.DoesNotContain(creationResult.PrimaryOutputs[1].Path, foundProjectFiles?.ToList()); }
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 ExcludeModifierOverridesPreviousIncludeModifierTemplateTest() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Sources = new List <ExtendedFileSource>() { new ExtendedFileSource() { Modifiers = new List <SourceModifier>() { new SourceModifier() { Include = "*.xyz" }, new SourceModifier() { Exclude = "exclude.xyz", }, } } } }; IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); templateSourceFiles.Add("other.xyz", null); templateSourceFiles.Add("include.xyz", null); templateSourceFiles.Add("exclude.xyz", null); TestTemplateSetup setup = new TestTemplateSetup(_engineEnvironmentSettings, sourceBasePath, templateSourceFiles, config); setup.WriteSource(); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); 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(2, changes.Count); IFileChange2 includeXyzChangeInfo = changes.FirstOrDefault(x => string.Equals(x.TargetRelativePath, "include.xyz")); Assert.NotNull(includeXyzChangeInfo); Assert.Equal(ChangeKind.Create, includeXyzChangeInfo.ChangeKind); IFileChange2 otherXyzChangeInfo = changes.FirstOrDefault(x => string.Equals(x.TargetRelativePath, "other.xyz")); Assert.NotNull(otherXyzChangeInfo); Assert.Equal(ChangeKind.Create, otherXyzChangeInfo.ChangeKind); }
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 SourceConfigExcludesAreOverriddenByIncludes() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); TestTemplateSetup setup = SetupTwoFilesWithConfigExtensionTemplate(_engineEnvironmentSettings, sourceBasePath); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); setup.InstantiateTemplate(targetDir); Assert.True(_engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(targetDir, "core.config"))); Assert.False(_engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(targetDir, "full.config"))); }
public void SplitConfigReadFailsIfAReferencedFileIsMissing() { string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); TestTemplateSetup setup = SetupSplitConfigWithAMissingReferencedFile(_engineEnvironmentSettings, sourcePath); IGenerator generator = new RunnableProjectGenerator(); IFileSystemInfo templateConfigFileInfo = setup.InfoForSourceFile(TestFileSystemHelper.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 SplitConfigCantReferenceFileOutsideBasePath() { string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); TestTemplateSetup setup = SetupSplitConfigWithAFileOutsideMountPoint(_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 - additional file is outside the base path."); Assert.Null(template); }
public void AddProjectToSolutionPostActionFindSolutionFileAtOutputPath() { string targetBasePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); string solutionFileFullPath = Path.Combine(targetBasePath, "MySln.sln"); EngineEnvironmentSettings.Host.FileSystem.WriteAllText(solutionFileFullPath, string.Empty); IReadOnlyList <string> solutionFiles = AddProjectsToSolutionPostAction.FindSolutionFilesAtOrAbovePath(EngineEnvironmentSettings.Host.FileSystem, targetBasePath); Assert.Equal(1, solutionFiles.Count); Assert.Equal(solutionFileFullPath, solutionFiles[0]); }
public void AddRefFindsOneDefaultProjFileInOutputDirectory() { string targetBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); string projFileFullPath = Path.Combine(targetBasePath, "MyApp.proj"); _engineEnvironmentSettings.Host.FileSystem.WriteAllText(projFileFullPath, TestCsprojFile); AddReferencePostActionProcessor actionProcessor = new AddReferencePostActionProcessor(); string outputBasePath = targetBasePath; IReadOnlyList <string> projFilesFound = actionProcessor.FindProjFileAtOrAbovePath(_engineEnvironmentSettings.Host.FileSystem, outputBasePath, new HashSet <string>()); Assert.Equal(1, projFilesFound.Count); }
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 void CopyOnlyWithoutIncludeDoesntActuallyCopyFile() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Sources = new List <ExtendedFileSource>() { new ExtendedFileSource() { Include = "**/*.txt", Modifiers = new List <SourceModifier>() { new SourceModifier() { CopyOnly = "copy.me" } } } } }; IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); templateSourceFiles.Add("something.txt", null); templateSourceFiles.Add("copy.me", null); TestTemplateSetup setup = new TestTemplateSetup(_engineEnvironmentSettings, sourceBasePath, templateSourceFiles, config); setup.WriteSource(); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); IReadOnlyDictionary <string, IReadOnlyList <IFileChange2> > allChanges = setup.GetFileChanges(targetDir); // one source, should cause one set of changes 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, "something.txt"), "didn't copy the correct file"); }
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 AddRefFindsMultipleDefaultProjFilesInOutputDirectory() { string projFilesOriginalContent = TestCsprojFile; string targetBasePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); string projFileFullPathOne = Path.Combine(targetBasePath, "MyApp.anysproj"); EngineEnvironmentSettings.Host.FileSystem.WriteAllText(projFileFullPathOne, projFilesOriginalContent); string projFileFullPathTwo = Path.Combine(targetBasePath, "MyApp2.someproj"); EngineEnvironmentSettings.Host.FileSystem.WriteAllText(projFileFullPathTwo, projFilesOriginalContent); AddReferencePostActionProcessor actionProcessor = new AddReferencePostActionProcessor(); string outputBasePath = targetBasePath; IReadOnlyList <string> projFilesFound = actionProcessor.FindProjFileAtOrAbovePath(EngineEnvironmentSettings.Host.FileSystem, outputBasePath, new HashSet <string>()); Assert.Equal(2, projFilesFound.Count); }
public void AddRefFindsOneNameConfiguredProjFileInOutputDirectory() { string targetBasePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); string fooprojFileFullPath = Path.Combine(targetBasePath, "MyApp.fooproj"); EngineEnvironmentSettings.Host.FileSystem.WriteAllText(fooprojFileFullPath, TestCsprojFile); AddReferencePostActionProcessor actionProcessor = new AddReferencePostActionProcessor(); string outputBasePath = targetBasePath; HashSet <string> projectFileExtensions = new HashSet <string>() { ".fooproj" }; IReadOnlyList <string> projFilesFound = actionProcessor.FindProjFileAtOrAbovePath(EngineEnvironmentSettings.Host.FileSystem, outputBasePath, projectFileExtensions); Assert.Equal(1, projFilesFound.Count); }
public void SplitConfigTest() { string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); TestTemplateSetup setup = SetupSplitConfigTestTemplate(_engineEnvironmentSettings, sourcePath); IGenerator generator = new RunnableProjectGenerator(); IFileSystemInfo templateConfigFileInfo = setup.InfoForSourceFile("templateSource/.template.config/template.json"); 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); // 5 in the configs + 1 for 'name' (implicit) 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 CopyOnlyWithWildcardAndParentIncludeActuallyCopiesFile() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); TestTemplateSetup setup = SetupCopyOnlyWithWildcardAndParentInclude(_engineEnvironmentSettings, sourceBasePath); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); 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 IncludeModifierOverridesPreviousExcludeModifierTemplateTest() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); TestTemplateSetup setup = SetupXYZFilesForModifierOverrideTestsTemplate(_engineEnvironmentSettings, sourceBasePath, IncludeModifierOverridesPreviousExcludeModifierConfigText); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); 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, "include.xyz"), "include modifier didn't properly override exclude modifier"); }
public void CheckTemplateRootRelativeToInstallPath(string pathToTemplateJson, bool shouldAllPathsBeValid) { 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(); RunnableProjectGenerator generator = new RunnableProjectGenerator(); IFile templateFile = setup.FileInfoForSourceFile(pathToTemplateJson); JObject srcObject = generator.ReadJObjectFromIFile(templateFile); SimpleConfigModel templateModel = SimpleConfigModel.FromJObject(templateFile.MountPoint.EnvironmentSettings, srcObject); RunnableProjectTemplate runnableProjectTemplate = new RunnableProjectTemplate(srcObject, generator, templateFile, templateModel, null, null); bool allPathsAreValid = generator.AreAllTemplatePathsValid(templateModel, runnableProjectTemplate); Assert.Equal(shouldAllPathsBeValid, allPathsAreValid); }
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 SourceConfigExcludesAreOverriddenByIncludes() { string sourceBasePath = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); SimpleConfigModel config = new SimpleConfigModel() { Identity = "test", Sources = new List <ExtendedFileSource>() { new ExtendedFileSource() { Exclude = "**/*.config", Modifiers = new List <SourceModifier>() { new SourceModifier() { Include = "core.config" } } } } }; IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); // config templateSourceFiles.Add(TestFileSystemHelper.DefaultConfigRelativePath, config.ToJObject().ToString()); // content templateSourceFiles.Add("core.config", null); templateSourceFiles.Add("full.config", null); TestTemplateSetup setup = new TestTemplateSetup(_engineEnvironmentSettings, sourceBasePath, templateSourceFiles, config); setup.WriteSource(); string targetDir = FileSystemHelpers.GetNewVirtualizedPath(_engineEnvironmentSettings); setup.InstantiateTemplate(targetDir); Assert.True(_engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(targetDir, "core.config"))); Assert.False(_engineEnvironmentSettings.Host.FileSystem.FileExists(Path.Combine(targetDir, "full.config"))); }
public void SetConfigTimestampUtc() { string templateJson = @" { ""name"": ""TestTemplate"", ""identity"": ""TestTemplate"", ""shortName"": ""testt"", ""symbols"": { ""mySymbol"": { ""type"": ""parameter"", ""replaces"": ""whatever"", ""forms"": { ""global"": [ ""fakeName"" ], } } } } "; var pathToTemplateJson = "templateSource/.template.config/template.json"; string sourcePath = FileSystemHelpers.GetNewVirtualizedPath(EngineEnvironmentSettings); IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(pathToTemplateJson, templateJson); TestTemplateSetup setup = new TestTemplateSetup(EngineEnvironmentSettings, sourcePath, templateSourceFiles); setup.WriteSource(); RunnableProjectGenerator generator = new RunnableProjectGenerator(); var templateFile = setup.InfoForSourceFile(pathToTemplateJson); generator.TryGetTemplateFromConfigInfo(templateFile, out ITemplate template, null, null); var templateWithTimestamp = Assert.IsAssignableFrom <ITemplateWithTimestamp>(template); Assert.NotNull(templateWithTimestamp.ConfigTimestampUtc); }
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); }