Beispiel #1
0
        public void ShouldIgnoreParserErrors()
        {
            var variables = new CalamariVariables();

            variables["fox"] = "replaced fox";

            var text = PerformTest(GetFixtureResouce("Samples", "ParserErrors.txt"), variables).text;

            // Environment.Newline returning \r\n when running tests on mono, but \n on dotnet core, just replace
            Assert.AreEqual("the quick brown replaced fox jumps over the lazy #{dog\nthe quick brown replaced fox jumps over the lazy #{dog #{", text.Replace("\r\n", "\n"));
        }
Beispiel #2
0
        static string GetPathToPowerShellWithCustomVersion(IEnumerable <string> versionInstalled, string customVersion)
        {
            var fileSystem = CreateFileSystem(versionInstalled);

            var variables = new CalamariVariables
            {
                { PowerShellVariables.CustomPowerShellVersion, customVersion }
            };

            return(CreateBootstrapper(fileSystem).PathToPowerShellExecutable(variables));
        }
        public void ShouldApplyFiltersDuringSubstitution()
        {
            var variables = new CalamariVariables
            {
                ["var"] = "=:'\"\\\r\n\t <>\uFFE6"
            };

            var textAfterReplacement = PerformTest(GetFixtureResource("Samples", "Filters.txt"), variables).text;

            this.Assent(textAfterReplacement, TestEnvironment.AssentConfiguration);
        }
        public void HandlesVariablesThatReferenceOtherVariables()
        {
            var vars = new CalamariVariables
            {
                { "/document/selfclosing", "#{a}" },
                { "a", "#{b}" },
                { "b", "value-new" }
            };

            RunTest(vars, "elements.xml");
        }
Beispiel #5
0
        public async Task AzureLinuxContainerDeploy()
        {
            newVariables = new CalamariVariables();
            AddVariables(newVariables);

            var runningContext = new RunningDeployment("", newVariables);

            await new AzureAppServiceDeployContainerBehavior(new InMemoryLog()).Execute(runningContext);

            await AssertDeploySuccessAsync(AzureWebAppHelper.GetAzureTargetSite(site.Name, "", resourceGroupName));
        }
        public void MissingVariableValue_LogsAWarning()
        {
            var variables = new CalamariVariables
            {
            };
            string jsonInputs = "{\"containerNameOverride\":\"payload\",\"package\":{\"extractedToPath\":\"#{Octopus.Action.Package[package].ExtractedPath}\"},\"target\":{\"files\":[]}}";
            var    log        = Substitute.For <ILog>();

            InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variables, log);
            log.Received().Warn(Arg.Any <string>());
        }
Beispiel #7
0
        public void HandlesVariablesThatReferenceOtherVariables()
        {
            var vars = new CalamariVariables
            {
                { "key1", "#{a}" },
                { "a", "#{b}" },
                { "b", "new-value" },
            };

            RunTest(vars, "example.properties");
        }
Beispiel #8
0
        public void ShouldBeEnabled(string accountType, string connectionEndpoint, ScriptSyntax syntax, bool expected)
        {
            var variables = new CalamariVariables
            {
                { SpecialVariables.Account.AccountType, accountType },
                { SpecialVariables.Action.ServiceFabric.ConnectionEndpoint, connectionEndpoint }
            };
            var target = new AzurePowerShellContext(variables);
            var actual = target.IsEnabled(syntax);

            actual.Should().Be(expected);
        }
        public void SimpleExpressionsAreEvaluated()
        {
            var    variableDictionary = new CalamariVariables();
            string jsonInputs         = "{\"testValue\":\"#{ | NowDateUtc}\"}";
            var    log             = Substitute.For <ILog>();
            string evaluatedInputs = InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variableDictionary, log);

            evaluatedInputs.Should().NotBeEmpty();
            evaluatedInputs.Should().NotBeEquivalentTo(jsonInputs);

            log.DidNotReceive().Warn(Arg.Any <string>());
        }
Beispiel #10
0
        public void DoesNotAddXmlHeader()
        {
            var variables = new CalamariVariables();

            variables.Set("WelcomeMessage", "Hello world");
            variables.Set("LogFile", "C:\\Log.txt");
            variables.Set("DatabaseConnection", null);

            var text = PerformTest(GetFixtureResouce("Samples", "NoHeader.config"), variables);

            Assert.That(text, Does.StartWith("<configuration"));
        }
Beispiel #11
0
        public void ShouldSubstitute()
        {
            var variables = new CalamariVariables();

            variables["ServerEndpoints[FOREXUAT01].Name"] = "forexuat01.local";
            variables["ServerEndpoints[FOREXUAT01].Port"] = "1566";
            variables["ServerEndpoints[FOREXUAT02].Name"] = "forexuat02.local";
            variables["ServerEndpoints[FOREXUAT02].Port"] = "1566";

            var text = PerformTest(GetFixtureResouce("Samples", "Servers.json"), variables).text;

            Assert.That(Regex.Replace(text, "\\s+", ""), Is.EqualTo(@"{""Servers"":[{""Name"":""forexuat01.local"",""Port"":1566},{""Name"":""forexuat02.local"",""Port"":1566}]}"));
        }
        private CalamariVariables BuildVariables()
        {
            var variables = new CalamariVariables();

            variables.Set("nodePathKey", "expectedNodePath");
            variables.Set("targetPathKey", "expectedTargetPath");
            variables.Set("bootstrapperVarKey", "expectedBootstrapperPath");
            variables.Set("inputsKey", @"{ input: ""foo"" }");
            variables.Set("targetInputsKey", @"{ targetInput: ""bar"" }");
            variables.Set("foo", "AwsAccount");
            variables.Set("discoveryContextKey", @"{ ""blah"": ""baz"" }");
            return(variables);
        }
        public void CanReplaceAnElementsText()
        {
            var vars = new CalamariVariables
            {
                { "/document/setting[@id='id-1']", "value<new" }
            };

            RunTest(vars, "complex.xml");

            Log.MessagesVerboseFormatted.Count(m => Regex.IsMatch(m, StructuredConfigMessages.StructureFound(".*"))).Should().Be(1);
            Log.MessagesVerboseFormatted.Should().Contain(StructuredConfigMessages.StructureFound("/document/setting[@id='id-1']"));
            Log.MessagesInfoFormatted.Should().NotContain(StructuredConfigMessages.NoStructuresFound);
        }
        public void VariablesInJsonInputsShouldBeEvaluated()
        {
            var variables = new CalamariVariables
            {
                { "Octopus.Action.Package[package].ExtractedPath", "C:\\OctopusTest\\Api Test\\1\\Octopus-Primary\\Work\\20210804020317-7-11\\package" },
            };
            string jsonInputs      = "{\"containerNameOverride\":\"payload\",\"package\":{\"extractedToPath\":\"#{Octopus.Action.Package[package].ExtractedPath}\"},\"target\":{\"files\":[{\"path\":\"azure-blob-container-target.0.0.0.zip\",\"fileName\":{\"type\":\"original file name\"}}]}}";
            string evaluatedInputs = InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variables, Substitute.For <ILog>());

            string expectedEvaluatedInputs = "{\"containerNameOverride\":\"payload\",\"package\":{\"extractedToPath\":\"C:\\\\OctopusTest\\\\Api Test\\\\1\\\\Octopus-Primary\\\\Work\\\\20210804020317-7-11\\\\package\"},\"target\":{\"files\":[{\"path\":\"azure-blob-container-target.0.0.0.zip\",\"fileName\":{\"type\":\"original file name\"}}]}}";

            Assert.AreEqual(expectedEvaluatedInputs, evaluatedInputs);
        }
Beispiel #15
0
        public void CanReplaceASimpleKeyValuePair()
        {
            var vars = new CalamariVariables
            {
                { "key1", "new-value" }
            };

            RunTest(vars, "example.properties");

            Log.MessagesVerboseFormatted.Count(m => Regex.IsMatch(m, StructuredConfigMessages.StructureFound(".*"))).Should().Be(1);
            Log.MessagesVerboseFormatted.Should().Contain(StructuredConfigMessages.StructureFound("key1"));
            Log.MessagesInfoFormatted.Should().NotContain(StructuredConfigMessages.NoStructuresFound);
        }
Beispiel #16
0
        public async Task SubstituteVariablesAndUploadTarBZip2Archives()
        {
            const string packageId        = "TestTarBzip2Package";
            const string packageVersion   = "0.0.1";
            const string packageExtension = "tar.bz2";
            var          fileName         = $"{packageId}.{packageVersion}.{packageExtension}";

            var packageOptions = new List <S3PackageOptions>
            {
                new S3PackageOptions
                {
                    StorageClass = "STANDARD",
                    CannedAcl    = "private",
                    StructuredVariableSubstitutionPatterns = "*.json",
                    BucketKeyBehaviour = BucketKeyBehaviourType.Filename,
                }
            };

            var variables = new CalamariVariables();

            variables.Set("Property1:Property2:Value", "InjectedValue");

            var packageFilePath = TestEnvironment.GetTestPath("AWS", "S3", "CompressedPackages", fileName);

            var prefix = UploadEntireCompressedPackage(packageFilePath, packageId, packageVersion, packageOptions, variables);

            await Validate(async client =>
            {
                var file              = await client.GetObjectAsync(bucketName, $"{prefix}{fileName}");
                var tempFileName      = Path.GetTempFileName();
                var tempDirectoryName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(tempFileName));
                try
                {
                    using (var fs = File.OpenWrite(tempFileName))
                    {
                        await file.ResponseStream.CopyToAsync(fs);
                    }

                    var log       = new InMemoryLog();
                    var extractor = new TarBzipPackageExtractor(log);
                    extractor.Extract(tempFileName, tempDirectoryName);
                    var text = File.ReadAllText(Path.Combine(tempDirectoryName, "file.json"));
                    JObject.Parse(text)["Property1"]["Property2"]["Value"].ToString().Should().Be("InjectedValue");
                }
                finally
                {
                    File.Delete(tempFileName);
                    Directory.Delete(tempDirectoryName, true);
                }
            });
        }
Beispiel #17
0
        public void ShouldOutputDiagnosticsLoggingIfEnabled()
        {
            var calamariFileSystem  = Substitute.For <ICalamariFileSystem>();
            var deploymentVariables = new CalamariVariables();

            deploymentVariables.Set(SpecialVariables.Action.Azure.CloudServicePackagePath, @"MyPackage.1.0.0.nupkg");
            deploymentVariables.Set(SpecialVariables.Package.AdditionalXmlConfigurationTransforms, @"MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config => MyApplication.ProcessingServer.WorkerRole.dll.config");
            deploymentVariables.Set(SpecialVariables.Package.AutomaticallyRunConfigurationTransformationFiles, "True");
            deploymentVariables.Set(DeploymentEnvironment.Name, "my-test-env");
            deploymentVariables.Set(SpecialVariables.Package.EnableDiagnosticsConfigTransformationLogging, "True");
            deploymentVariables.Set(SpecialVariables.Package.EnabledFeatures, SpecialVariables.Features.ConfigurationTransforms);
            var runningDeployment = new RunningDeployment(@"c:\temp\MyPackage.1.0.0.nupkg", deploymentVariables);

            //mock the world
            calamariFileSystem.DirectoryExists(@"c:\temp").Returns(true);
            calamariFileSystem.FileExists(@"c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config").Returns(true);
            calamariFileSystem.FileExists(@"c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.config").Returns(true);
            calamariFileSystem.EnumerateFilesRecursively(@"c:\temp", "*.config")
            .Returns(new[] { @"c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config", @"c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.config" });
            calamariFileSystem.EnumerateFiles(@"c:\temp", "MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config", @"MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config")
            .Returns(new[] { @"c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config" });
            calamariFileSystem.EnumerateFiles(@"c:\temp", "MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config", @"MyApplication.ProcessingServer.WorkerRole.dll.my-test-env")
            .Returns(new[] { @"c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config" });

            //these variables would normally be set by ExtractPackageToStagingDirectoryConvention
            Log.SetOutputVariable(PackageVariables.Output.InstallationDirectoryPath, "c:\\temp", runningDeployment.Variables);
            Log.SetOutputVariable(KnownVariables.OriginalPackageDirectoryPath, "c:\\temp", runningDeployment.Variables);

            var log         = new InMemoryLog();
            var transformer = Substitute.For <IConfigurationTransformer>();
            var fileLocator = new TransformFileLocator(calamariFileSystem, log);

            new ConfigurationTransformsConvention(calamariFileSystem, transformer, fileLocator, log).Install(runningDeployment);

            //not completely testing every scenario here, but this is a reasonable half way point to make sure it works without going overboard
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @"Recursively searching for transformation files that match *.config in folder 'c:\temp'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @"Found config file 'c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - checking against transform 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config => MyApplication.ProcessingServer.WorkerRole.dll.config'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - Skipping as file name 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config' does not match the target pattern 'MyApplication.ProcessingServer.WorkerRole.dll.config'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - checking against transform 'Release'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - skipping as neither transform 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.Release.config' nor transform 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.Release' could be found in 'c:\temp'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - checking against transform 'my-test-env'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - skipping as neither transform 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.my-test-env.config' nor transform 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.my-test-env' could be found in 'c:\temp'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @"Found config file 'c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.config'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - checking against transform 'MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config => MyApplication.ProcessingServer.WorkerRole.dll.config'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Info && m.FormattedMessage == @"Transforming 'c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.config' using 'c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config'.");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - checking against transform 'Release'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - skipping as neither transform 'MyApplication.ProcessingServer.WorkerRole.dll.Release.config' nor transform 'MyApplication.ProcessingServer.WorkerRole.dll.Release' could be found in 'c:\temp'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - checking against transform 'my-test-env'");
            log.Messages.Should().Contain(m => m.Level == InMemoryLog.Level.Verbose && m.FormattedMessage == @" - Skipping as target 'c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.config' has already been transformed by transform 'c:\temp\MyApplication.ProcessingServer.WorkerRole.dll.my-test-env.config'");
        }
Beispiel #18
0
        void RunNugetV3TimeoutTest(string timeoutInVariables, TimeSpan serverResponseTime, TimeSpan estimatedTimeout)
        {
            using (var server = new TestHttpServer(9001, serverResponseTime))
            {
                var packageId       = "FakePackageId";
                var version         = VersionFactory.CreateSemanticVersion(1, 2, 3);
                var feedCredentials = new CredentialCache();
                var targetFilePath  = "FakeTargetFilePath";
                var filesystem      = Substitute.For <ICalamariFileSystem>();
                var v3NugetUri      = new Uri(server.BaseUrl + "/index.json");
                var variables       = new CalamariVariables();

                if (timeoutInVariables != null)
                {
                    variables[KnownVariables.NugetHttpTimeout] = timeoutInVariables;
                }

                var downloader = new InternalNuGetPackageDownloader(filesystem, variables);

                var stopwatch = new Stopwatch();

                Action invocation = () =>
                {
                    stopwatch.Start();
                    try
                    {
                        downloader.DownloadPackage(
                            packageId,
                            version,
                            v3NugetUri,
                            feedCredentials,
                            targetFilePath,
                            maxDownloadAttempts: 1,
                            downloadAttemptBackoff: TimeSpan.Zero
                            );
                    }
                    finally
                    {
                        stopwatch.Stop();
                    }
                };

                invocation.Should()
                .ThrowExactly <Exception>();

                stopwatch.Elapsed
                .Should()
                .BeCloseTo(estimatedTimeout, TimeSpan.FromSeconds(0.5));
            }
        }
Beispiel #19
0
        public void ReplacesStronglyTypedAppSettings()
        {
            var variables = new CalamariVariables();

            variables.Set("WelcomeMessage", "Hello world");
            variables.Set("LogFile", "C:\\Log.txt");
            variables.Set("DatabaseConnection", null);

            var text = PerformTest(GetFixtureResouce("Samples", "StrongTyped.config"), variables);

            var contents = XDocument.Parse(text);

            Assert.AreEqual("Hello world", contents.XPathSelectElement("//AppSettings.Properties.Settings/setting[@name='WelcomeMessage']/value").Value);
        }
Beispiel #20
0
        public void ReplacesConnectionStrings()
        {
            var variables = new CalamariVariables();

            variables.Set("MyDb1", "Server=foo");
            variables.Set("MyDb2", "Server=bar&bar=123");

            var text = PerformTest(GetFixtureResouce("Samples", "App.config"), variables);

            var contents = XDocument.Parse(text);

            Assert.AreEqual("Server=foo", contents.XPathSelectElement("//connectionStrings/add[@name='MyDb1']").Attribute("connectionString").Value);
            Assert.AreEqual("Server=bar&bar=123", contents.XPathSelectElement("//connectionStrings/add[@name='MyDb2']").Attribute("connectionString").Value);
        }
        public void ShouldPrioritizePowerShellScriptsOverOtherSyntaxes()
        {
            var variables = new CalamariVariables();

            variables.Set(SpecialVariables.Action.Script.ScriptBodyBySyntax(ScriptSyntax.PowerShell), "Write-Host Hello PowerShell");
            variables.Set(SpecialVariables.Action.Script.ScriptBodyBySyntax(ScriptSyntax.CSharp), "Write-Host Hello CSharp");
            variables.Set(SpecialVariables.Action.Script.ScriptBodyBySyntax(ScriptSyntax.Bash), "echo Hello Bash");

            var output = InvokeCalamariForPowerShell(calamari => calamari
                                                     .Action("run-script"), variables);

            output.AssertSuccess();
            output.AssertOutput("Hello PowerShell");
        }
Beispiel #22
0
        public void ShouldBeEnabledIfAnyVariablesAreProvided(string clusterUrl, string aksClusterName,
                                                             string eksClusterName, bool expected)
        {
            var variables = new CalamariVariables
            {
                { SpecialVariables.ClusterUrl, clusterUrl },
                { SpecialVariables.AksClusterName, aksClusterName },
                { SpecialVariables.EksClusterName, eksClusterName }
            };
            var target = new KubernetesContextScriptWrapper(variables);
            var actual = target.IsEnabled(ScriptSyntaxHelper.GetPreferredScriptSyntaxForEnvironment());

            actual.Should().Be(expected);
        }
Beispiel #23
0
        public IVariables Create(CommonOptions options)
        {
            var variables = new CalamariVariables();

            ReadUnencryptedVariablesFromFile(options, variables);
            ReadEncryptedVariablesFromFile(options, variables);
            ReadOutputVariablesFromOfflineDropPreviousSteps(options, variables);

            AddEnvironmentVariables(variables);
            variables.Set(TentacleVariables.Agent.InstanceName, "#{env:TentacleInstanceName}");
            ReadAdditionalVariablesFromFile(variables);
            DeploymentJournalVariableContributor.Contribute(fileSystem, variables);

            return(variables);
        }
Beispiel #24
0
        public void ShouldRevertToExistingEncodingIfInvalid()
        {
            var filePath  = GetFixtureResouce("Samples", "UTF16LE.ini");
            var variables = new CalamariVariables();

            variables[PackageVariables.SubstituteInFilesOutputEncoding] = "utf-666";

            var encoding = (Encoding)PerformTest(filePath, variables).encoding;

            Encoding fileEncoding;

            FileSystem.ReadFile(filePath, out fileEncoding);
            Assert.AreEqual(Encoding.Unicode, fileEncoding);
            Assert.AreEqual(Encoding.Unicode, encoding);
        }
        public void ShouldRevertToExistingEncodingIfInvalid()
        {
            var filePath  = GetFixtureResource("Samples", "UTF16LE.ini");
            var variables = new CalamariVariables
            {
                [PackageVariables.SubstituteInFilesOutputEncoding] = "utf-666"
            };

            var result = PerformTest(filePath, variables);

            FileSystem.ReadFile(filePath, out var inputEncoding);
            Assert.AreEqual("utf-16", inputEncoding.WebName);
            Assert.AreEqual("utf-16", result.encoding.WebName);
            result.text.Should().MatchRegex(@"\bFile1=banknames.ora\b");
        }
Beispiel #26
0
        public void RetainUTF8Bom()
        {
            var filePath  = GetFixtureResouce("Samples", "UTF8BOM.txt");
            var variables = new CalamariVariables();

            variables["LocalCacheFolderName"] = "SpongeBob";

            var result = PerformTest(filePath, variables);

            Encoding encoding;

            FileSystem.ReadFile(filePath, out encoding);
            Assert.AreEqual(Encoding.UTF8, encoding);
            Assert.AreEqual(Encoding.UTF8, result.encoding);
        }
        public async Task Execute_LogsError_WhenContextIsMissing()
        {
            // Arrange
            var variables = new CalamariVariables();
            var context   = new RunningDeployment(variables);
            var log       = new InMemoryLog();
            var sut       = new TargetDiscoveryBehaviour(log);

            // Act
            await sut.Execute(context);

            // Assert
            log.StandardOut.Should().Contain(line => line.Contains("Could not find target discovery context in variable"));
            log.StandardOut.Should().Contain(line => line.Contains("Aborting target discovery."));
        }
Beispiel #28
0
        public void ShouldCallHelloWithSensitiveVariable()
        {
            var variables = new CalamariVariables();

            variables.Set("Name", "NameToEncrypt");

            var(output, _) = RunPowerShellScript("HelloWithVariable.ps1", new Dictionary <string, string>()
            {
                ["Name"] = "NameToEncrypt"
            }, sensitiveVariablesPassword: "******");

            output.AssertSuccess();
            output.AssertOutput("Hello NameToEncrypt");
            AssertPowerShellEdition(output);
        }
Beispiel #29
0
        public void ShouldReplaceWithNull()
        {
            const string expected =
                "{" +
                "  \"MyMessage\": null," +
                "}";

            var variables = new CalamariVariables();

            variables.Set("MyMessage", null);

            var replaced = Replace(variables, existingFile: "appsettings.single.json");

            AssertJsonEquivalent(replaced, expected);
        }
        CalamariVariables ParseVariables(string variableDefinitions)
        {
            var variables = new CalamariVariables();

            var items = variableDefinitions.Split(';');

            foreach (var item in items)
            {
                var pair  = item.Split('=');
                var key   = pair.First();
                var value = pair.Last();
                variables[key] = value;
            }

            return(variables);
        }