コード例 #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));
        }
コード例 #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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #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));
        }
コード例 #6
0
        public void RemoveChildrenIfEmptyReplacementSpecified()
        {
            var newConfig = XDocument.Parse(UpdateFile.Update(
                                                @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml"
                                                ));

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

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

            Assert.IsNull(newConfig.XPathSelectElement("/root/value").Attribute("duckAttr"));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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" }
     }
                                                                            )));
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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"));
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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"));
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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>"));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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());
        }
コード例 #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);
        }
コード例 #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);
        }