Example #1
0
        public void TestRemoveTransform()
        {
            // remove the entire system.web element

            var input     = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                  <system.web xdt:Transform=""Remove"" />
                </configuration>
                ");
            var output    = new XdtTransformer().Transform(input, transform);

            Assert.IsFalse(output.Descendants("system.web").Any());
            Assert.IsTrue(output.Descendants("configuration").Any());
        }
Example #2
0
        public void TestRemoveTransform()
        {
            // remove the entire system.web element

            var input = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                  <system.web xdt:Transform=""Remove"" />
                </configuration>
                ");
            var output = new XdtTransformer().Transform(input, transform);

            Assert.IsFalse(output.Descendants("system.web").Any());
            Assert.IsTrue(output.Descendants("configuration").Any());
        }
Example #3
0
        public void TestSetAttributesTransform()
        {
            // change the "debug" attribute to false

            var input     = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                  <system.web>
                    <compilation debug=""false"" xdt:Transform=""SetAttributes"" />
                  </system.web>
                </configuration>
                ");
            var output    = new XdtTransformer().Transform(input, transform);

            var element = output
                          .Element("configuration")
                          .Element("system.web")
                          .Element("compilation");

            Assert.IsTrue(element.Attribute("debug").Value == "false");

            // ensure we haven't accidentally added attributes from the transform document
            Assert.IsFalse(output.Descendants().Any(e =>
                                                    e.Attributes().Any(a =>
                                                                       a.Name.NamespaceName == Namespaces.Xdt)));
        }
Example #4
0
        public void TestXPathLocator()
        {
            // all the mailsettings sections anywhere in the doc will be removed

            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                    <couldbe > 
                        <anything xdt:Transform=""RemoveAll"" xdt:Locator=""XPath(//mailsettings)"" /> 
                    </couldbe>
                </configuration>
                ");

            var output = new XdtTransformer().Transform(this.doc, transform);

            Assert.IsFalse(output.Descendants("mailsettings").Any());
        }
Example #5
0
        public void TestReplaceTransform()
        {
            // replace the entire system.web element

            var input = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                  <system.web xdt:Transform=""Replace"">
                    <extra content=""here"" />
                  </system.web>
                </configuration>
                ");
            var output = new XdtTransformer().Transform(input, transform);

            var element = output
                .Element("configuration")
                .Element("system.web")
                .Element("extra");

            Assert.IsTrue(element.Attribute("content").Value == "here");

            // ensure there are no xdt attributes from the transform doc!
            Assert.IsFalse(output.Descendants().Attributes().Any(a => a.Name.NamespaceName == Namespaces.Xdt));
        }
Example #6
0
        public void TestSetAttributesTransformWithArguments()
        {
            // change the "debug" attribute to false

            var input = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                  <system.web>
                    <compilation debug=""false"" xdt:Transform=""SetAttributes(debug)"" />
                  </system.web>
                </configuration>
                ");
            var output = new XdtTransformer().Transform(input, transform);

            var element = output
                .Element("configuration")
                .Element("system.web")
                .Element("compilation");

            Assert.IsTrue(element.Attribute("debug").Value == "false");

            // ensure we haven't accidentally added attributes from the transform document
            Assert.IsFalse(output.Descendants().Any(e =>
                e.Attributes().Any(a =>
                    a.Name.NamespaceName == Namespaces.Xdt)));
        }
Example #7
0
        public void TestReplaceTransform()
        {
            // replace the entire system.web element

            var input = GetInputDocument();
            var transform = XDocument.Parse(@"
                <configuration xmlns:xdt=""http://schemas.microsoft.com/XML-Document-Transform"">
                  <system.web xdt:Transform=""Replace"">
                    <extra content=""here"" />
                  </system.web>
                </configuration>
                ");
            var output = new XdtTransformer().Transform(input, transform);

            var element = output
                .Element("configuration")
                .Element("system.web")
                .Element("extra");

            Assert.IsTrue(element.Attribute("content").Value == "here");

            // ensure there are no xdt attributes from the transform doc!
            Assert.IsFalse(output.Descendants().Attributes().Any(a => a.Name.NamespaceName == Namespaces.Xdt));
        }