コード例 #1
0
        public void ShouldFailIfElementForUnspecifiedEnvironment()
        {
            XElement config = new XElement("stuff",
                new XAttribute(Console.BuildConfigForAttribute, "live,nosystest"),
                new XElement("dome", new XAttribute("name", "7")),
                new XElement("hill", new XElement("speed", new XAttribute(ConfigurationGenerator.ForEnvironmentsAttribute, "systest"), "some text")));

            try {
                var confgen = new ConfigurationGenerator(config);
                confgen.ConfigForEnvironment("live");
                Assert.Fail("expected configuration exception");
            } catch (NoSuchEnvironmentException) {
            }
        }
コード例 #2
0
        public void ShouldIncludeElementsForCurrentEnvironment()
        {
            XElement config = new XElement("stuff",
                new XAttribute(Console.BuildConfigForAttribute, "live,systest"),
                new XElement("dome", new XAttribute("name", "7")),
                new XElement("hill", new XElement("speed", new XAttribute(ConfigurationGenerator.ForEnvironmentsAttribute, "systest"), "some text")));

            var confgen = new ConfigurationGenerator(config);
            XElement generated = confgen.ConfigForEnvironment("systest");

            XElement expected = new XElement("stuff",
                new XElement("dome", new XAttribute("name", "7")),
                new XElement("hill", new XElement("speed", "some text")));
            Assert.AreEqual(expected.ToString(), generated.ToString());
        }
コード例 #3
0
        public void ShouldGenerateIdenticalXml()
        {
            XElement config = new XElement("stuff",
                new XAttribute(Console.BuildConfigForAttribute, "dev, systest1, systest2"),
                new XElement("dome", new XAttribute("name", "7")),
                new XElement("hill", new XElement ("speed", "some text")));

            XElement expectedConfig = new XElement("stuff",
                new XElement("dome", new XAttribute("name", "7")),
                new XElement("hill", new XElement ("speed", "some text")));

            var confgen = new ConfigurationGenerator(config);
            XElement generated = confgen.ConfigForEnvironment("someenv");

            Assert.AreEqual(expectedConfig.ToString(), generated.ToString());
        }
コード例 #4
0
        private void AssertOutputForInput(string input, string env, string output)
        {
            XElement config = XElement.Parse(input);

            var confgen = new ConfigurationGenerator(config);
            var generated = confgen.ConfigForEnvironment(env);

            XElement expected = XElement.Parse(output);

            Assert.That(generated.ToString(), Is.EqualTo(expected.ToString()));
        }
コード例 #5
0
        public void VariablesShouldBeSetOnlyForEnvironment()
        {
            var xml =
            @"<stuff xmlns:conf=""http://schemas.refractalize.org/confgen"" conf:with-vars=""true"" conf:environments=""dev,live"">
            <conf:var name=""host"" conf:for=""dev"">localhost</conf:var>
            <conf:var name=""host"" conf:for=""live"">example.com</conf:var>
            <host value=""{host}""/>
            </stuff>";

            XElement config = XElement.Parse(xml);

            var confgen = new ConfigurationGenerator(config);
            var devGenerated = confgen.ConfigForEnvironment("dev");
            var liveGenerated = confgen.ConfigForEnvironment("live");

            var devXml =
            @"<stuff>
            <host value=""localhost""/>
            </stuff>";
            var liveXml =
            @"<stuff>
            <host value=""example.com""/>
            </stuff>";

            Assert.That(devGenerated.ToString(), Is.EqualTo(XElement.Parse(devXml).ToString()));
            Assert.That(liveGenerated.ToString(), Is.EqualTo(XElement.Parse(liveXml).ToString()));
        }