public void ProcessesStandardTokenizedVariables()
        {
            var generator = CreateGenerator();
            var template  = File.ReadAllText(TemplateManifestPath);
            var match     = generator.GetMatches(template).Cast <Match>().FirstOrDefault();
            var config    = new TestBuildConfiguration
            {
                BuildConfiguration = "Test",
                ProjectDirectory   = Directory.GetCurrentDirectory(),
                SolutionDirectory  = Directory.GetCurrentDirectory()
            };
            var variables = EnvironmentAnalyzer.GatherEnvironmentVariables(config, true);

            foreach (var variable in variables)
            {
                _testOutputHelper.WriteLine($"  - {variable.Key}: {variable.Value}");
            }
            var processedTemplate = generator.ProcessMatch(template, match, variables);
            var json = JsonConvert.DeserializeAnonymousType(processedTemplate, new
            {
                TemplatedParameter   = "",
                CustomTokenParameter = ""
            });

            Assert.Equal("%%CustomTokenParameter%%", json.CustomTokenParameter);
            Assert.Equal(nameof(AppManifestGeneratorFixture), json.TemplatedParameter);
        }
        public void GetsValuesForBuildConfigurationFromConfigurationEnvironment()
        {
            var config         = GetConfiguration();
            var settingsConfig = new SettingsConfig
            {
                Properties = new List <ValueConfig>
                {
                    new ValueConfig
                    {
                        Name         = "SampleProp",
                        PropertyType = PropertyType.String
                    }
                }
            };

            config.Configuration.Environment.Defaults.Add("SampleProp", "Hello Tests");
            config.Configuration.Environment.Configuration[config.BuildConfiguration] = new Dictionary <string, string>
            {
                { "SampleProp", "Hello Override" }
            };
            config.Configuration.AppSettings[config.ProjectName] = new List <SettingsConfig>(new[] { settingsConfig });

            var mergedSecrets = EnvironmentAnalyzer.GatherEnvironmentVariables(config);

            Assert.True(mergedSecrets.ContainsKey("SampleProp"));
            Assert.Equal(config.Configuration.Environment.Configuration[config.BuildConfiguration]["SampleProp"], mergedSecrets["SampleProp"]);
        }
        public void GetsValuesFromJson(string filename)
        {
            var config         = GetConfiguration($"{nameof(GetsValuesFromJson)}-{Path.GetFileNameWithoutExtension(filename)}");
            var settingsConfig = new SettingsConfig
            {
                Properties = new List <ValueConfig>
                {
                    new ValueConfig
                    {
                        Name         = "SampleProp",
                        PropertyType = PropertyType.String
                    }
                }
            };

            config.Configuration.AppSettings[config.ProjectName] = new List <SettingsConfig>(new[] { settingsConfig });

            var secrets = new
            {
                SampleProp = "Hello Tests"
            };

            File.WriteAllText(Path.Combine(config.ProjectDirectory, filename), JsonSerializer.Serialize(secrets));

            var mergedSecrets = EnvironmentAnalyzer.GatherEnvironmentVariables(config);

            Assert.True(mergedSecrets.ContainsKey("SampleProp"));
            Assert.Equal(secrets.SampleProp, mergedSecrets["SampleProp"]);
        }
        public void OverridesConfigEnvironmentFromHostEnvironment()
        {
            var config         = GetConfiguration();
            var settingsConfig = new SettingsConfig
            {
                Properties = new List <ValueConfig>
                {
                    new ValueConfig
                    {
                        Name         = "SampleProp3",
                        PropertyType = PropertyType.String
                    }
                }
            };

            config.Configuration.AppSettings[config.ProjectName]     = new List <SettingsConfig>(new[] { settingsConfig });
            config.Configuration.Environment.Defaults["SampleProp3"] = "Hello Config Environment";

            Environment.SetEnvironmentVariable("SampleProp3", nameof(OverridesConfigEnvironmentFromHostEnvironment), EnvironmentVariableTarget.Process);

            var mergedSecrets = EnvironmentAnalyzer.GatherEnvironmentVariables(config);

            Assert.True(mergedSecrets.ContainsKey("SampleProp3"));
            Assert.Equal(nameof(OverridesConfigEnvironmentFromHostEnvironment), mergedSecrets["SampleProp3"]);
        }
        public void ProcessesStandardTokenizedVariables()
        {
            var generator         = CreateGenerator();
            var template          = File.ReadAllText(TemplateManifestPath);
            var match             = generator.GetMatches(template).FirstOrDefault();
            var variables         = EnvironmentAnalyzer.GatherEnvironmentVariables(Directory.GetCurrentDirectory(), true);
            var processedTemplate = generator.ProcessMatch(template, match, variables);
            var json = JsonConvert.DeserializeAnonymousType(processedTemplate, new
            {
                TemplatedParameter   = "",
                CustomTokenParameter = ""
            });

            Assert.Equal("%%CustomTokenParameter%%", json.CustomTokenParameter);
            Assert.Equal(nameof(AppManifestGeneratorFixture), json.TemplatedParameter);
        }
Ejemplo n.º 6
0
        public void ProcessCustomTokenizedVariables()
        {
            var config = GetConfiguration();

            config.BuildConfiguration            = "Test";
            config.ProjectDirectory              = config.SolutionDirectory = Directory.GetCurrentDirectory();
            config.Configuration.Manifests.Token = @"%%";
            var generator = CreateGenerator(config);

            var template          = File.ReadAllText(TemplateManifestPath);
            var match             = generator.GetMatches(template).Cast <Match>().FirstOrDefault();
            var variables         = EnvironmentAnalyzer.GatherEnvironmentVariables(config, true);
            var processedTemplate = generator.ProcessMatch(template, match, variables);
            var json = JsonSerializer.Deserialize <TestManifest>(processedTemplate);

            Assert.Equal(nameof(AppManifestGeneratorFixture), json.CustomTokenParameter);
            Assert.Equal("$TemplatedParameter$", json.TemplatedParameter);
        }
        public override bool Execute()
        {
            var variables = EnvironmentAnalyzer.GatherEnvironmentVariables(ProjectDirectory, true);

            string message;

            if (variables.Any())
            {
                message = $"Found {variables.Count} Environment Variables\n";
                foreach (var variable in variables)
                {
                    message += $"    {variable.Key}: {variable.Value}\n";
                }
            }
            else
            {
                message = "There doesn't seem to be any Environment Variables... something is VERY VERY Wrong...";
            }

            Log.LogMessage(Microsoft.Build.Framework.MessageImportance.High, message);

            return(true);
        }