Exemple #1
0
        public void DoNotCreatePartialOutputFileIfExceptionDuringProcessWhenIndicated()
        {
            Assert.Throws <NDjangoWrapper.NDjangoWrapperException>(() => ProcessSubstitution.Update(@"TestUpdateFiles\TestSubstitution5.xml", @"TestUpdateFiles\TestConfig1.xml"));
            var fileName = @"TestUpdateFiles\TestConfig1.xml_partial";

            Assert.False(File.Exists(fileName));
        }
Exemple #2
0
        public void JsonTest_WithFilePath()
        {
            dynamic newJson = JObject.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution37.xml", @"TestUpdateFiles\TestJson01.json"
                                                ));

            Assert.AreEqual("C:\\Temp", (string)newJson.Data);
        }
Exemple #3
0
        public void CondensedChangeAttributeStructure()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution28.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemple #4
0
        public void SubstituteInNameSpacedFile()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(@"TestUpdateFiles\TestSubstitution3.xml", @"TestUpdateFiles\TestConfig2.xml"));
            var nms       = new XmlNamespaceManager(new NameTable());

            nms.AddNamespace("c", "http://madeup.com");
            Assert.AreEqual("newvalue", newConfig.XPathSelectElement("/c:root/c:value", nms).Value);
        }
Exemple #5
0
        public void RemoveAttributesIfSpecified()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.IsNull(newConfig.XPathSelectElement("/root/value").Attribute("duckAttr"));
        }
Exemple #6
0
        public void RemoveChildrenIfEmptyReplacementSpecified()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("", newConfig.XPathSelectElement("/root/value").Value);
        }
Exemple #7
0
        public void ChangeValueOfAttributeWithFixedSubEvenWhenOldAttributesRemoved()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemple #8
0
        public void DoNotChangeChildrenUnlessNewValueSpecified()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution7.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("oldValue", newConfig.XPathSelectElement("/root/value").Value);
        }
Exemple #9
0
        public void DoNotRemoveAttributesUnlessSpecified()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution7.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("quack", newConfig.XPathSelectElement("/root/value").Attribute("duckAttr").Value);
        }
Exemple #10
0
 public void InvalidSubstitutionXmlShouldThrow()
 {
     Assert.Throws <XmlSchemaValidationException>(() => XDocument.Parse(ProcessSubstitution.Update(
                                                                            @"TestUpdateFiles\TestSubstitution20.xml", @"TestUpdateFiles\TestConfig2.xml",
                                                                            new Dictionary <string, object> {
         { "tagged", "after" }, { "Environment", "LOC" }
     }.ToLazyTagDictionary()
                                                                            )));
 }
Exemple #11
0
        public void TagsOutsideSpecifiedXPathsUnchanged()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution9.xml", @"TestUpdateFiles\TestConfig3.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("{{ tagged }}", newConfig.XPathSelectElement("/root/myValue").Value);
        }
Exemple #12
0
        public void UpdateAllKnowsAboutTaggedFiles()
        {
            ProcessSubstitution.Update(@"TestUpdateFiles\TestSubstitution13.xml", new Dictionary <string, object> {
                { "FilePath", "TaggedPath" }
            }.ToLazyTagDictionary(), false);

            var document = XDocument.Load(@"TestUpdateFiles\TestConfig-TaggedPath.xml");

            Assert.AreEqual("newvalue", document.XPathSelectElement("/root/value").Value);
        }
Exemple #13
0
        public void EmptyChildContentWorks()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution16.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.IsTrue(newConfig.XPathSelectElements("/root/value/NewTag").Count() == 0);
        }
Exemple #14
0
        public void AppendAfterWorks()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution14.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.IsTrue(newConfig.Root.Descendants().Select(el => el.Name).Contains("NewTag"));
        }
Exemple #15
0
        public void SubstituteTaggedAttributeValue()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution9.xml", @"TestUpdateFiles\TestConfig3.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemple #16
0
        public void NewFileWithTemplateWorks()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution11.xml", @"TestUpdateFiles\DoesntExist.xml", new Dictionary <string, object> {
                { "tagged", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/myValue").Value);
        }
        public void Transform()
        {
            var config = TagDictionary.FromSources("ident", new Dictionary <TagSource, string> {
                { TagSource.XmlFileName, @"ApprovalTestFiles\Config.xml" }
            });
            var lazyConfig = new Lazy <TagDictionary>(() => config);
            var result     = XDocument.Parse(ProcessSubstitution.Update(@"ApprovalTestFiles\Substitution.xml", @"ApprovalTestFiles\BaseFile.xml", lazyConfig));

            Approvals.VerifyXml(result.ToString());
        }
Exemple #18
0
        public void SubstituteOldValueWithNewTaggedXmlValue()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution5.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "taggedReplacementContent", "newvalue" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("newvalue", newConfig.XPathSelectElement("/root/value").Descendants().First().Name.LocalName);
        }
Exemple #19
0
        public void ConcatFilterWorks()
        {
            var newConfig = ProcessSubstitution.Update(
                @"TestUpdateFiles\TestSubstitution23.xml", @"TestUpdateFiles\PlainText03.txt",
                new Dictionary <string, object> {
                { "tag", "<after>" }, { "Environment", "LOC" }
            }.ToLazyTagDictionary());

            Assert.AreEqual("Some plain text. With a concat <after></after>.", newConfig);
        }
Exemple #20
0
        public void NDjangoFiltersAvailable()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution12.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newvalue", "AfTer" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Value);
        }
Exemple #21
0
        public void PlainTextWithEscaping()
        {
            var newConfig = ProcessSubstitution.Update(
                @"TestUpdateFiles\TestSubstitution22.xml", @"TestUpdateFiles\PlainText02.txt",
                new Dictionary <string, object> {
                { "tag", "<after>" }, { "Environment", "LOC" }
            }.ToLazyTagDictionary());

            Assert.AreEqual("Some plain text. With a {{ tag }}.", newConfig);
        }
Exemple #22
0
        public void PlainTextTemplatingWorksEvenWithXmlEscapableCharacters()
        {
            var newConfig = ProcessSubstitution.Update(
                @"TestUpdateFiles\TestSubstitution21.xml", @"TestUpdateFiles\PlainText01.txt",
                new Dictionary <string, object> {
                { "tag", "<after>" }, { "Environment", "LOC" }
            }.ToLazyTagDictionary());

            Assert.IsTrue(newConfig.Contains("<after>"));
        }
Exemple #23
0
        public void SubstituteOldValueWithNewLoopedTaggedXmlValuesAsXml()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution6.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object>
            {
                { "configList", new [] { "newvalue1", "newvalue2", "newvalue3" } }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("", newConfig.XPathSelectElement("/root/value/newvalue1").Value);
        }
Exemple #24
0
        public void SubstituteIf_False()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution30.xml", @"TestUpdateFiles\TestConfig3.xml",
                                                new Dictionary <string, object> {
                { "Environment", "NOT_INT" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("before", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemple #25
0
        public void MultipleChildContentWorks()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution17.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("1", newConfig.XPathSelectElements("/root/value/one").First().Value);
            Assert.AreEqual("2", newConfig.XPathSelectElements("/root/value/two").First().Value);
        }
Exemple #26
0
        public void TemplateAndChangesWork()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution18.xml", @"TestUpdateFiles\TestConfig2.xml", new Dictionary <string, object> {
                { "tagged", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/myValue").Value);
            Assert.AreEqual("afterAttr", newConfig.XPathSelectElement("/root/myValue").Attribute("myAttr").Value);
        }
Exemple #27
0
        public void AppendAfterWorksWithAmpersandInTag()
        {
            ProcessSubstitution.Update(@"TestUpdateFiles\TestSubstitution26.xml", new Dictionary <string, object> {
                { "tagValue", "t&his*text" }
            }.ToLazyTagDictionary(), false);

            var document = XDocument.Load(@"TestUpdateFiles\TestConfig1.xml");
            var nms      = new XmlNamespaceManager(new NameTable());

            nms.AddNamespace("c", "http://madeup.com");
            Assert.AreEqual("t&his*text", document.XPathSelectElement("/root/testing").Value);
        }
Exemple #28
0
        public void UpdateAllTouchesAllFiles()
        {
            ProcessSubstitution.Update(@"TestUpdateFiles\TestSubstitution3.xml", new Dictionary <string, object> {
                { "tagValue", "Tagged!" }
            }.ToLazyTagDictionary(), false);

            var document  = XDocument.Load(@"TestUpdateFiles\TestConfig1.xml");
            var document2 = XDocument.Load(@"TestUpdateFiles\TestConfig2.xml");
            var nms       = new XmlNamespaceManager(new NameTable());

            nms.AddNamespace("c", "http://madeup.com");
            Assert.AreEqual("newvalue", document2.XPathSelectElement("/c:root/c:value", nms).Value);
            Assert.AreEqual("Tagged!", document.XPathSelectElement("/root/value").Value);
        }
Exemple #29
0
        public void CondensedAllSubsStructure()
        {
            var newConfig = XDocument.Parse(ProcessSubstitution.Update(
                                                @"TestUpdateFiles\TestSubstitution29.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.NotNull(newConfig.XPathSelectElement("/root/testing"));
            Assert.Null(newConfig.XPathSelectElement("/root/testing/test[1]").Attribute("myAttr"));
            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/testing/test[1]").Attribute("myAttr2").Value);
            Assert.AreEqual("value", newConfig.XPathSelectElement("/root/testing/test[1]").Value);
            Assert.AreEqual("new-after", newConfig.XPathSelectElement("/root/testing/test[2]").Attribute("myAttr").Value);
            Assert.AreEqual("new-value", newConfig.XPathSelectElement("/root/testing/test[2]").Value);
            Assert.NotNull(newConfig.XPathSelectElement("/root/myValue"));
            Assert.AreEqual("nodeValue", newConfig.XPathSelectElement("/root/myValue").Value);
        }
Exemple #30
0
        public void JsonTest()
        {
            var data = ProcessSubstitution.Update(
                @"TestUpdateFiles\TestSubstitution36.xml", @"TestUpdateFiles\TestJson01.json"
                );
            dynamic newJson = JObject.Parse(data);

            Assert.AreEqual("NewData", (string)newJson.Data);
            Assert.AreEqual(2, (int)newJson.Data2);
            Assert.AreEqual("NotItem1", (string)newJson.Collection[0].NotData);
            Assert.AreEqual("NotItem2", (string)newJson.Collection[1].NotData);
            Assert.AreEqual("Value1", (string)newJson.ComplexData.Complex1);
            Assert.AreEqual("Value2", (string)newJson.ComplexData.Complex2);
            Assert.AreEqual("Value3", (string)newJson.ComplexData.Complex3);
            Assert.AreEqual("Bill", (string)newJson.SubTrees.DataPoint.Value);
        }