示例#1
0
        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);
        }
示例#2
0
        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");
        }
示例#3
0
        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")));
        }
示例#4
0
        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 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);
            }
        }