Exemplo n.º 1
0
        public void DoNotCreatePartialOutputFileIfExceptionDuringProcessWhenIndicated()
        {
            Assert.Throws <ArgumentException>(() => UpdateFile.Update(@"TestUpdateFiles\TestSubstitution5.xml", @"TestUpdateFiles\TestConfig1.xml"));
            var fileName = @"TestUpdateFiles\TestConfig1.xml_partial";

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

            Assert.AreEqual("C:\\Temp", (string)newJson.Data);
        }
        public void SubstituteInNameSpacedFile()
        {
            var newConfig = XDocument.Parse(UpdateFile.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);
        }
        public void ChangeValueOfAttributeWithFixedSub()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution7.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemplo n.º 5
0
        public void CreatePartialOutputFileIfExceptionDuringProcessWhenIndicated()
        {
            Assert.Throws <NDjangoWrapper.NDjangoWrapperException>(() => UpdateFile.Update(@"TestUpdateFiles\TestSubstitution5.xml", @"TestUpdateFiles\TestConfig1.xml", outputFailureContext: true));

            var fileName = @"TestUpdateFiles\TestConfig1.xml_partial";

            Assert.IsTrue(File.Exists(fileName));
        }
        public void RemoveChildrenIfEmptyReplacementSpecified()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("", newConfig.XPathSelectElement("/root/value").Value);
        }
        public void DoNotChangeChildrenUnlessNewValueSpecified()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution7.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("oldValue", newConfig.XPathSelectElement("/root/value").Value);
        }
        public void RemoveAttributesIfSpecified()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.IsNull(newConfig.XPathSelectElement("/root/value").Attribute("duckAttr"));
        }
Exemplo n.º 9
0
        public void CondensedChangeAttributeStructure()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution28.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemplo n.º 10
0
        public void DoNotRemoveAttributesUnlessSpecified()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution7.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

            Assert.AreEqual("quack", newConfig.XPathSelectElement("/root/value").Attribute("duckAttr").Value);
        }
Exemplo n.º 11
0
 public void InvalidSubstitutionXmlShouldThrow()
 {
     Assert.Throws <XmlSchemaValidationException>(() => XDocument.Parse(UpdateFile.Update(
                                                                            @"TestUpdateFiles\TestSubstitution20.xml", @"TestUpdateFiles\TestConfig2.xml",
                                                                            new Dictionary <string, object> {
         { "tagged", "after" }, { "Environment", "LOC" }
     }
                                                                            )));
 }
Exemplo n.º 12
0
        public void EmptyChildContentWorks()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution16.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }
                                                ));

            Assert.IsTrue(newConfig.XPathSelectElements("/root/value/NewTag").Count() == 0);
        }
Exemplo n.º 13
0
        public void SubstituteTaggedAttributeValue()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution9.xml", @"TestUpdateFiles\TestConfig3.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Attribute("myAttr").Value);
        }
Exemplo n.º 14
0
        public void TagsOutsideSpecifiedXPathsUnchanged()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution9.xml", @"TestUpdateFiles\TestConfig3.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }
                                                ));

            Assert.AreEqual("{{ tagged }}", newConfig.XPathSelectElement("/root/myValue").Value);
        }
Exemplo n.º 15
0
        public void SubstituteOldValueWithNewTaggedValue()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution4.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "taggedReplacementContent", "newvalue" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("newvalue", newConfig.XPathSelectElement("/root/value").Value);
        }
Exemplo n.º 16
0
        public void PlainTextTemplatingWorks()
        {
            var newConfig = UpdateFile.Update(
                @"TestUpdateFiles\TestSubstitution21.xml", @"TestUpdateFiles\PlainText01.txt",
                new Dictionary <string, object> {
                { "tag", "after" }, { "Environment", "LOC" }
            }.ToLazyTagDictionary());

            Assert.IsTrue(newConfig.Contains("after"));
        }
Exemplo n.º 17
0
        public void ReplaceFileWithTemplateWorks()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution10.xml", @"TestUpdateFiles\TestConfig2.xml", new Dictionary <string, object> {
                { "tagged", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/myValue").Value);
        }
Exemplo n.º 18
0
        public void AddChildContentWorks()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution15.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual(1, newConfig.XPathSelectElements("/root/value/NewTag").Count());
        }
Exemplo n.º 19
0
        public void AppendAfterWorks()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution14.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }
                                                ));

            Assert.IsTrue(newConfig.Root.Descendants().Select(el => el.Name).Contains("NewTag"));
        }
Exemplo n.º 20
0
        public void ConcatFilterWorks()
        {
            var newConfig = UpdateFile.Update(
                @"TestUpdateFiles\TestSubstitution23.xml", @"TestUpdateFiles\PlainText03.txt",
                new Dictionary <string, object> {
                { "tag", "<after>" }, { "Environment", "LOC" }
            });

            Assert.AreEqual("Some plain text. With a concat <after></after>.", newConfig);
        }
Exemplo n.º 21
0
        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(UpdateFile.Update(@"ApprovalTestFiles\Substitution.xml", @"ApprovalTestFiles\BaseFile.xml", lazyConfig));

            Approvals.VerifyXml(result.ToString());
        }
Exemplo n.º 22
0
        public void SubstituteOldValueWithNewTaggedXmlValue()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution5.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "taggedReplacementContent", "newvalue" }
            }
                                                ));

            Assert.AreEqual("newvalue", newConfig.XPathSelectElement("/root/value").Descendants().First().Name.LocalName);
        }
Exemplo n.º 23
0
        public void PlainTextWithEscaping()
        {
            var newConfig = UpdateFile.Update(
                @"TestUpdateFiles\TestSubstitution22.xml", @"TestUpdateFiles\PlainText02.txt",
                new Dictionary <string, object> {
                { "tag", "<after>" }, { "Environment", "LOC" }
            });

            Assert.AreEqual("Some plain text. With a {{ tag }}.", newConfig);
        }
Exemplo n.º 24
0
        public void NDjangoFiltersAvailable()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution12.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newvalue", "AfTer" }
            }
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/value").Value);
        }
Exemplo n.º 25
0
        public void PlainTextTemplatingWorksEvenWithXmlEscapableCharacters()
        {
            var newConfig = UpdateFile.Update(
                @"TestUpdateFiles\TestSubstitution21.xml", @"TestUpdateFiles\PlainText01.txt",
                new Dictionary <string, object> {
                { "tag", "<after>" }, { "Environment", "LOC" }
            });

            Assert.IsTrue(newConfig.Contains("<after>"));
        }
Exemplo n.º 26
0
        public void NewFileWithTemplateWorks()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution11.xml", @"TestUpdateFiles\DoesntExist.xml", new Dictionary <string, object> {
                { "tagged", "after" }
            }
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/myValue").Value);
        }
Exemplo n.º 27
0
        public void SubstituteOldValueWithNewLoopedTaggedXmlValuesAsXml()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution6.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object>
            {
                { "configList", new [] { "newvalue1", "newvalue2", "newvalue3" } }
            }
                                                ));

            Assert.AreEqual("", newConfig.XPathSelectElement("/root/value/newvalue1").Value);
        }
Exemplo n.º 28
0
        public void SubstituteOldValueWithNewLoopedTaggedXmlValues()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution6.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object>
            {
                { "configList", new [] { "newvalue1", "newvalue2", "newvalue3" } }
            }.ToLazyTagDictionary()
                                                ));

            Assert.AreEqual(XElement.Parse("<value><newvalue1/><newvalue2 /><newvalue3/></value>").ToString(), newConfig.XPathSelectElement("/root/value").ToString());
        }
Exemplo n.º 29
0
        public void TemplateAndChangesWork()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution18.xml", @"TestUpdateFiles\TestConfig2.xml", new Dictionary <string, object> {
                { "tagged", "after" }
            }
                                                ));

            Assert.AreEqual("after", newConfig.XPathSelectElement("/root/myValue").Value);
            Assert.AreEqual("afterAttr", newConfig.XPathSelectElement("/root/myValue").Attribute("myAttr").Value);
        }
Exemplo n.º 30
0
        public void MultipleChildContentWorks()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution17.xml", @"TestUpdateFiles\TestConfig1.xml", new Dictionary <string, object> {
                { "newValue", "after" }
            }
                                                ));

            Assert.AreEqual("1", newConfig.XPathSelectElements("/root/value/one").First().Value);
            Assert.AreEqual("2", newConfig.XPathSelectElements("/root/value/two").First().Value);
        }