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)); }
public void JsonTest_WithFilePath() { dynamic newJson = JObject.Parse(ProcessSubstitution.Update( @"TestUpdateFiles\TestSubstitution37.xml", @"TestUpdateFiles\TestJson01.json" )); Assert.AreEqual("C:\\Temp", (string)newJson.Data); }
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); }
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); }
public void RemoveAttributesIfSpecified() { var newConfig = XDocument.Parse(ProcessSubstitution.Update( @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml" )); Assert.IsNull(newConfig.XPathSelectElement("/root/value").Attribute("duckAttr")); }
public void RemoveChildrenIfEmptyReplacementSpecified() { var newConfig = XDocument.Parse(ProcessSubstitution.Update( @"TestUpdateFiles\TestSubstitution8.xml", @"TestUpdateFiles\TestConfig3.xml" )); Assert.AreEqual("", newConfig.XPathSelectElement("/root/value").Value); }
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); }
public void DoNotChangeChildrenUnlessNewValueSpecified() { var newConfig = XDocument.Parse(ProcessSubstitution.Update( @"TestUpdateFiles\TestSubstitution7.xml", @"TestUpdateFiles\TestConfig3.xml" )); Assert.AreEqual("oldValue", newConfig.XPathSelectElement("/root/value").Value); }
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); }
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() ))); }
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); }
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); }
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); }
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")); }
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); }
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()); }
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); }
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); }
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); }
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); }
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>")); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }