Exemplo n.º 1
0
        public void TestChangingMappingKey()
        {
            var key = (YamlScalar)"def";
            var map = new YamlMapping(key, 3);

            key.Value = "ghi";
            Assert.IsTrue(map.ContainsKey(key));
            Assert.IsTrue(map.Remove(key));

            map[map] = 4;
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            var map2 = new YamlMapping(key, 3);

            map2[map2] = 2;
            map2[map]  = 4;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            map[map2] = 2;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            map.Tag = YamlNode.DefaultTagPrefix + "map";
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);

            var seq = new YamlSequence(map);

            map.Add(seq, 4);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
            seq.Add(map);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
        }
Exemplo n.º 2
0
        public void MergeKey()
        {
            var map      = new YamlMapping("existing", "value");
            var mergeKey = new YamlScalar("!!merge", "<<");

            map.Add(mergeKey, new YamlMapping("existing", "new value"));
            map.OnLoaded();
            Assert.AreEqual(1, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode)"value", map["existing"]);

            map.Add(mergeKey, new YamlMapping("not existing", "new value"));
            map.OnLoaded();
            Assert.AreEqual(2, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode)"value", map["existing"]);
            Assert.IsTrue(map.ContainsKey("not existing"));
            Assert.AreEqual((YamlNode)"new value", map["not existing"]);

            map.Add(mergeKey, new YamlMapping("key1", "value1", 2, 2, 3.0, 3.0));
            map.OnLoaded();
            Assert.AreEqual(5, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode)"value", map["existing"]);
            Assert.IsTrue(map.ContainsKey("not existing"));
            Assert.AreEqual((YamlNode)"new value", map["not existing"]);
            Assert.IsTrue(map.ContainsKey(2));
            Assert.AreEqual((YamlNode)2, map[2]);
            Assert.IsTrue(map.ContainsKey(3.0));
            Assert.AreEqual((YamlNode)3.0, map[3.0]);

            map = new YamlMapping(
                "existing", "value",
                mergeKey, new YamlMapping("not existing", "new value"));
            map.OnLoaded();
            Assert.AreEqual(2, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode)"value", map["existing"]);
            Assert.IsTrue(map.ContainsKey("not existing"));
            Assert.AreEqual((YamlNode)"new value", map["not existing"]);

            map = (YamlMapping)YamlNode.FromYaml(
                "key1: value1\r\n" +
                "key2: value2\r\n" +
                "<<: \r\n" +
                "  key2: value2 modified\r\n" +
                "  key3: value3\r\n" +
                "  <<: \r\n" +
                "    key4: value4\r\n" +
                "    <<: value5\r\n" +
                "key6: <<\r\n")[0];
            Assert.AreEqual(
                "%YAML 1.2\r\n" +
                "---\r\n" +
                "<<: value5\r\n" +
                "key6: <<\r\n" +
                "key3: value3\r\n" +
                "key2: value2\r\n" +
                "key4: value4\r\n" +
                "key1: value1\r\n" +
                "...\r\n",
                map.ToYaml()
                );
            Assert.IsTrue(map.ContainsKey(mergeKey));
            Assert.AreEqual(mergeKey, map["key6"]);

            map.Remove(mergeKey);
            map.Add(mergeKey, map); // recursive
            map.OnLoaded();
            Assert.AreEqual(        // nothing has been changed
                "%YAML 1.2\r\n" +
                "---\r\n" +
                "key6: <<\r\n" +
                "key3: value3\r\n" +
                "key2: value2\r\n" +
                "key4: value4\r\n" +
                "key1: value1\r\n" +
                "...\r\n",
                map.ToYaml()
                );
        }
Exemplo n.º 3
0
        public void TestChangingMappingKey()
        {
            var key = (YamlScalar)"def";
            var map = new YamlMapping(key, 3);
            key.Value = "ghi";
            Assert.IsTrue(map.ContainsKey(key));
            Assert.IsTrue(map.Remove(key));

            map[map] = 4;
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            var map2 = new YamlMapping(key, 3);
            map2[map2] = 2;
            map2[map] = 4;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            map[map2] = 2;
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);

            map.Tag = YamlNode.DefaultTagPrefix + "map";
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);

            var seq = new YamlSequence(map);
            map.Add(seq, 4);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
            seq.Add(map);
            Assert.IsTrue(map2.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map2[map2]);
            Assert.AreEqual((YamlNode)4, map2[map]);
            Assert.IsTrue(map.ContainsKey(map));
            Assert.AreEqual((YamlNode)4, map[map]);
            Assert.IsTrue(map.ContainsKey(map2));
            Assert.AreEqual((YamlNode)2, map[map2]);
        }
Exemplo n.º 4
0
        public void ApplySettings(IActivityMonitor m)
        {
            if (!this.CheckCurrentBranch(m))
            {
                return;
            }
            YamlMapping firstMapping = GetFirstMapping(m, true);

            if (firstMapping == null)
            {
                return;
            }
            var solution = _driver.GetSolution(m, allowInvalidSolution: true);

            if (solution == null)
            {
                return;
            }

            // We don't use AppVeyor for private repositories.
            if (!GitFolder.IsPublic)
            {
                if (TextContent != null)
                {
                    m.Log(LogLevel.Info, "The project is private, so we don't use Appveyor and the Appveyor.yml is not needed.");
                    Delete(m);
                }
                return;
            }
            // We currently always use AppVeyor when the repository is public.
            YamlMapping env = FindOrCreateYamlElement(m, firstMapping, "environment");

            if (env == null)
            {
                return;
            }

            var passphrase = _keyStore.GetSecretKey(m, SolutionDriver.CODECAKEBUILDER_SECRET_KEY, false);

            if (passphrase != null)
            {
                var central = KeyVault.DecryptValues(_sharedState.CICDKeyVault, passphrase);
                if (central.TryGetValue(APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY, out var appveyorSecure))
                {
                    env[SolutionDriver.CODECAKEBUILDER_SECRET_KEY] = CreateKeyValue("secure", appveyorSecure);
                }
                else
                {
                    m.Warn($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure key has been skipped: {APPVEYOR_ENCRYPTED_CODECAKEBUILDER_SECRET_KEY} key should be defined in CICDKeyVault.");
                }
            }
            else
            {
                m.Info($"Update of {SolutionDriver.CODECAKEBUILDER_SECRET_KEY} encrypted secure skipped.");
            }
            // Remove obsolete environment variables definitions.
            env.Remove("NUGET_API_KEY");
            env.Remove("MYGET_RELEASE_API_KEY");
            env.Remove("MYGET_PREVIEW_API_KEY");
            env.Remove("MYGET_CI_API_KEY");
            env.Remove("CK_DB_TEST_MASTER_CONNECTION_STRING");
            env.Remove("AZURE_FEED_SIGNATURE_OPENSOURCE_PAT");
            env.Remove("AZURE_FEED_PAT");
            env.Remove("VSS_NUGET_EXTERNAL_FEED_ENDPOINTS");
            if (_solutionSpec.SqlServer != null)
            {
                env["SqlServer/MasterConnectionString"] = new YamlValue($"Server=(local)\\SQL{_solutionSpec.SqlServer.ToUpperInvariant()};Database=master;User ID=sa;Password=Password12!");
            }
            //
            firstMapping.Remove(new YamlValue("init"));
            if (_solutionSpec.SqlServer != null)
            {
                firstMapping["services"] = new YamlValue("mssql" + _solutionSpec.SqlServer.ToLowerInvariant());
            }
            var install = new YamlSequence();

            // Temporary: installs the 6.9.0 of npm.
            if (solution.GeneratedArtifacts.Any(g => g.Artifact.Type.Name == "NPM"))
            {
                install.Add(CreateKeyValue("cmd", "npm install -g [email protected]"));
                install.Add(CreateKeyValue("ps", "Install-Product node 12"));
            }
            firstMapping["install"] = install;

            firstMapping["version"]      = new YamlValue("build{build}");
            firstMapping["image"]        = new YamlValue("Visual Studio 2019");
            firstMapping["clone_folder"] = new YamlValue("C:\\CKli-World\\" + GitFolder.SubPath.Path.Replace('/', '\\'));
            EnsureDefaultBranches(firstMapping);
            SetSequence(firstMapping, "build_script", new YamlValue("dotnet run --project CodeCakeBuilder -nointeraction"));
            firstMapping["test"]      = new YamlValue("off");
            firstMapping["artifacts"] = new YamlSequence()
            {
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\*.log'"),
                    ["name"] = new YamlValue("Log file")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\*.trx'"),
                    ["name"] = new YamlValue("Visual studio test results file")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**\Tests\**\TestResult*.xml'"),
                    ["name"] = new YamlValue("NUnit tests result files")
                },
                new YamlMapping()
                {
                    ["path"] = new YamlValue(@"'**Tests\**\Logs\**\*'"),
                    ["name"] = new YamlValue("Log files")
                }
            };
            CreateOrUpdate(m, YamlMappingToString(m));
        }
Exemplo n.º 5
0
        public void MergeKey()
        {
            var map = new YamlMapping("existing", "value");
            var mergeKey = new YamlScalar("!!merge", "<<");

            map.Add(mergeKey, new YamlMapping("existing", "new value"));
            map.OnLoaded();
            Assert.AreEqual(1, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode) "value", map["existing"]);

            map.Add(mergeKey, new YamlMapping("not existing", "new value"));
            map.OnLoaded();
            Assert.AreEqual(2, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode) "value", map["existing"]);
            Assert.IsTrue(map.ContainsKey("not existing"));
            Assert.AreEqual((YamlNode) "new value", map["not existing"]);

            map.Add(mergeKey, new YamlMapping("key1", "value1", 2, 2, 3.0, 3.0));
            map.OnLoaded();
            Assert.AreEqual(5, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode) "value", map["existing"]);
            Assert.IsTrue(map.ContainsKey("not existing"));
            Assert.AreEqual((YamlNode) "new value", map["not existing"]);
            Assert.IsTrue(map.ContainsKey(2));
            Assert.AreEqual((YamlNode) 2, map[2]);
            Assert.IsTrue(map.ContainsKey(3.0));
            Assert.AreEqual((YamlNode) 3.0, map[3.0]);

            map = new YamlMapping(
                "existing", "value",
                mergeKey, new YamlMapping("not existing", "new value"));
            map.OnLoaded();
            Assert.AreEqual(2, map.Count);
            Assert.IsTrue(map.ContainsKey("existing"));
            Assert.AreEqual((YamlNode) "value", map["existing"]);
            Assert.IsTrue(map.ContainsKey("not existing"));
            Assert.AreEqual((YamlNode) "new value", map["not existing"]);

            map = (YamlMapping) YamlNode.FromYaml(
                "key1: value1\r\n" +
                "key2: value2\r\n" +
                "<<: \r\n" +
                "  key2: value2 modified\r\n" +
                "  key3: value3\r\n" +
                "  <<: \r\n" +
                "    key4: value4\r\n" +
                "    <<: value5\r\n" +
                "key6: <<\r\n")[0];

            var mapBack = map.ToYaml();

            Assert.AreEqual(@"%YAML 1.2
---
<<: value5
key1: value1
key2: value2
key3: value3
key4: value4
key6: <<
...
", mapBack);
            Assert.IsTrue(map.ContainsKey(mergeKey));
            Assert.AreEqual(mergeKey, map["key6"]);

            map.Remove(mergeKey);
            map.Add(mergeKey, map); // recursive
            map.OnLoaded();

            // nothing has been changed
            mapBack = map.ToYaml();
            Assert.AreEqual(@"%YAML 1.2
---
key1: value1
key2: value2
key3: value3
key4: value4
key6: <<
...
", mapBack);
        }