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 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 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); }
private static TestTemplateSetup SetupSourceModifierRenameIsCaseSensitiveTestTemplate(IEngineEnvironmentSettings environment, string basePath) { string sourceConfig = @" { ""sources"": [ { ""modifiers"": [ { ""rename"": { ""RenameMe.txt"": ""YesNewName.txt"", ""DontRenameMe.txt"": ""NoNewName.txt"", } } ] } ] } "; IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); // template.json templateSourceFiles.Add(TemplateConfigTestHelpers.DefaultConfigRelativePath, sourceConfig); // content templateSourceFiles.Add("RenameMe.txt", null); templateSourceFiles.Add("dontrenameme.txt", null); TestTemplateSetup setup = new TestTemplateSetup(environment, basePath, templateSourceFiles); setup.WriteSource(); return(setup); }
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"]); }
// The file outside the proper location is not created - it can't be by this mechanism. // It doesn't need to exist, the reader will fail in trying to read it. private static TestTemplateSetup SetupSplitConfigWithAFileOutsideMountPoint(IEngineEnvironmentSettings environment, string basePath) { IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(".template.config/template.json", TemplateJsonWithAdditionalFileOutsideBasePath); TestTemplateSetup setup = new TestTemplateSetup(environment, basePath, templateSourceFiles); setup.WriteSource(); return(setup); }
// Uses the same template.json as the test that successfully reads a split config. // But doesn't create the additional file private static TestTemplateSetup SetupSplitConfigWithAMissingReferencedFile(IEngineEnvironmentSettings environment, string basePath) { IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(".template.config/template.json", TemplateJsonWithProperAdditionalConfigFilesString); TestTemplateSetup setup = new TestTemplateSetup(environment, basePath, templateSourceFiles); setup.WriteSource(); return(setup); }
private static TestTemplateSetup SetupCopyOnlyWithWildcardAndParentInclude(IEngineEnvironmentSettings environment, string basePath) { IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(TemplateConfigTestHelpers.DefaultConfigRelativePath, CopyOnlyWithWildcardAndParentIncludeConfigText); templateSourceFiles.Add("copy.me", null); TestTemplateSetup setup = new TestTemplateSetup(environment, basePath, templateSourceFiles); setup.WriteSource(); return(setup); }
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 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 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"))); }
private static TestTemplateSetup SetupXYZFilesForModifierOverrideTestsTemplate(IEngineEnvironmentSettings environment, string basePath, string templateConfig) { IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); templateSourceFiles.Add(TemplateConfigTestHelpers.DefaultConfigRelativePath, templateConfig); templateSourceFiles.Add("other.xyz", null); templateSourceFiles.Add("include.xyz", null); templateSourceFiles.Add("exclude.xyz", null); TestTemplateSetup setup = new TestTemplateSetup(environment, basePath, templateSourceFiles); setup.WriteSource(); return(setup); }
private static TestTemplateSetup SetupTwoFilesWithConfigExtensionTemplate(IEngineEnvironmentSettings environment, string basePath) { IDictionary <string, string> templateSourceFiles = new Dictionary <string, string>(); // config templateSourceFiles.Add(TemplateConfigTestHelpers.DefaultConfigRelativePath, ExcludesWithIncludeModifierConfigText); // content templateSourceFiles.Add("core.config", null); templateSourceFiles.Add("full.config", null); TestTemplateSetup setup = new TestTemplateSetup(environment, basePath, templateSourceFiles); setup.WriteSource(); return(setup); }
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 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); }