From: <jer...@us...> - 2008-06-02 16:28:53
|
Revision: 117 http://structuremap.svn.sourceforge.net/structuremap/?rev=117&view=rev Author: jeremydmiller Date: 2008-06-02 09:28:50 -0700 (Mon, 02 Jun 2008) Log Message: ----------- fixed svn move Added Paths: ----------- trunk/Source/StructureMap.Testing/Graph/Source/ trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/Mementos/ trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs Added: trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,72 @@ +using System; +using System.IO; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class DirectoryXmlMementoSourceTester + { + private DirectoryXmlMementoSource _source; + + + [TestFixtureSetUp] + public void TestFixtureSetUp() + { + Directory.CreateDirectory("MementoDirectory"); + + string instance1 = + "<Instance Key=\"Red\" Type=\"Color\"><Property Name=\"Color\" Value=\"Red\" /></Instance>"; + string instance2 = + "<Instance Key=\"Blue\" Type=\"Color\"><Property Name=\"Color\" Value=\"Blue\" /></Instance>"; + string instance3 = + "<Instance Key=\"Bigger\" Type=\"GreaterThan\"><Property Name=\"Attribute\" Value=\"MyDad\" /><Property Name=\"Value\" Value=\"10\" /></Instance>"; + + writeFile(instance1, @"MementoDirectory\Red.xml"); + writeFile(instance2, @"MementoDirectory\Blue.xml"); + writeFile(instance3, @"MementoDirectory\Bigger.xml"); + + _source = new DirectoryXmlMementoSource("MementoDirectory", "xml", XmlMementoStyle.NodeNormalized); + } + + private void writeFile(string text, string path) + { + FileInfo fileInfo = new FileInfo(path); + StreamWriter writer = fileInfo.CreateText(); + writer.Write(text); + + writer.Close(); + } + + [Test] + public void CanGetAllMementos() + { + InstanceMemento[] mementos = _source.GetAllMementos(); + Assert.IsNotNull(mementos); + Assert.AreEqual(3, mementos.Length); + } + + [Test] + public void GetRedInstance() + { + InstanceMemento memento = _source.GetMemento("Red"); + Assert.IsNotNull(memento); + Assert.AreEqual("Red", memento.GetProperty("Color")); + } + + [Test, ExpectedException(typeof (ApplicationException))] + public void ValidateIsNotSuccessfulWithADirectoryItCannotFind() + { + DirectoryXmlMementoSource source = + new DirectoryXmlMementoSource("NotARealDirectory", "xml", XmlMementoStyle.NodeNormalized); + source.Validate(); + } + + [Test] + public void ValidateIsSuccessfulWithAnExistingDirectory() + { + _source.Validate(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedFolderXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,45 @@ +using System.Reflection; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class EmbeddedFolderXmlMementoSourceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + string folderPath = GetType().FullName.Replace(GetType().Name, "Mementos"); + string assemblyName = Assembly.GetExecutingAssembly().FullName; + _source = + new EmbeddedFolderXmlMementoSource(XmlMementoStyle.AttributeNormalized, assemblyName, folderPath, "xml"); + } + + #endregion + + private EmbeddedFolderXmlMementoSource _source; + + /* + <Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> + <Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> + */ + + + [Test] + public void FetchAllMementos() + { + Assert.AreEqual(2, _source.GetAllMementos().Length); + } + + [Test] + public void FetchOneMemento() + { + InstanceMemento memento = _source.GetMemento("Instance1"); + Assert.AreEqual("red", memento.GetProperty("color")); + Assert.AreEqual("Instance1", memento.InstanceKey); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/EmbeddedMementoFile.xml 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Instances> + + <Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> + <Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> + +</Instances> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/MachineXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,63 @@ +using System; +using StructureMap; +using StructureMap.Source; +using NUnit.Framework; + +namespace StructureMap.Testing.Container.Source +{ + [TestFixture] + public class MachineXmlMementoSourceTester + { + private MachineXmlMementoSource source; + + [SetUp] + public void SetUp() + { + source = new MachineXmlMementoSource("Machine.XML", string.Empty, "Rule"); + } + + [Test] + public void Fetch1() + { + source.SetMachineName("server"); + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Server's favorite color is blue", "Blue", memento.GetProperty("Color")); + } + + [Test] + public void Fetch2() + { + source.SetMachineName("localhost"); + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Localhost's favorite color is red", "Red", memento.GetProperty("Color")); + } + + + + [Test] + public void FetchMachineNotFound() + { + source.SetMachineName("fake-machine"); + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Default's favorite color is red", "Orange", memento.GetProperty("Color")); + } + + /* + [Test, Ignore("Only works on Jeremy's MILLERJ box")] + public void JeremysBox() + { + InstanceMemento memento = source.GetMemento("FavoriteColor"); + + Assertion.AssertNotNull(memento); + Assertion.AssertEquals("Jeremy's favorite color is green", "Green", memento.GetProperty("Color")); + } + */ + + } +} Added: trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance1.xml 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/Mementos/Instance2.xml 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,2 @@ +<?xml version="1.0" encoding="utf-8" ?> +<Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/SingleEmbeddedXmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,45 @@ +using System.Reflection; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class SingleEmbeddedXmlMementoSourceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + string pathName = GetType().FullName.Replace(GetType().Name, "EmbeddedMementoFile.xml"); + _source = + new SingleEmbeddedXmlMementoSource("Instance", XmlMementoStyle.AttributeNormalized, + Assembly.GetExecutingAssembly(), pathName); + } + + #endregion + + private SingleEmbeddedXmlMementoSource _source; + +/* + <Instance Type="Type1" Key="Instance1" color="red" state="Texas"/> + <Instance Type="Type2" Key="Instance2" color="green" state="Missouri"/> + */ + + + [Test] + public void FetchAllMementos() + { + Assert.AreEqual(2, _source.GetAllMementos().Length); + } + + [Test] + public void FetchOneMemento() + { + InstanceMemento memento = _source.GetMemento("Instance1"); + Assert.AreEqual("red", memento.GetProperty("color")); + Assert.AreEqual("Instance1", memento.InstanceKey); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/TemplatingTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,95 @@ +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class TemplatingTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + DataMother.WriteDocument(FILE_NAME); + + _nodeTemplateSource = new XmlFileMementoSource(FILE_NAME, "NodeTemplates", "Parent"); + _attTemplateSource = new XmlAttributeFileMementoSource(FILE_NAME, "AttTemplates", "Parent"); + _source = new XmlAttributeFileMementoSource(FILE_NAME, "Parents", "Parent"); + + _referringMemento = _source.GetMemento("Jackie"); + + _templatedSource = new TemplatedMementoSource(_source, _attTemplateSource); + } + + #endregion + + private const string FILE_NAME = "InstanceMementoTemplating.xml"; + private MementoSource _nodeTemplateSource; + private MementoSource _attTemplateSource; + private MementoSource _source; + private InstanceMemento _referringMemento; + private TemplatedMementoSource _templatedSource; + + private void validateCombinedMemento(InstanceMemento combinedMemento) + { + Assert.AreEqual("70", combinedMemento.GetProperty("Age")); + Assert.AreEqual("Green", combinedMemento.GetProperty("EyeColor")); + + InstanceMemento grandChildMemeto = + combinedMemento.GetChildMemento("MyChild").GetChildMemento("MyGrandChild"); + Assert.AreEqual("1992", grandChildMemeto.GetProperty("BirthYear")); + } + + + [Test] + public void GetAllMementos() + { + InstanceMemento[] mementos = _templatedSource.GetAllMementos(); + + Assert.IsNotNull(mementos); + Assert.AreEqual(4, mementos.Length); + + foreach (InstanceMemento memento in mementos) + { + Assert.IsNotNull(memento); + } + } + + [Test] + public void GetNonTemplatedInstance() + { + InstanceMemento memento = _templatedSource.GetMemento("Nadine"); + Assert.AreEqual("80", memento.GetProperty("Age")); + Assert.AreEqual("Blue", memento.GetProperty("EyeColor")); + } + + [Test] + public void GetTemplatedMementoFromAttributeNormalizedTemplate() + { + InstanceMemento templateMemento = _attTemplateSource.GetMemento("Grandmother"); + Assert.IsNotNull(templateMemento); + InstanceMemento combinedMemento = templateMemento.Substitute(_referringMemento); + + validateCombinedMemento(combinedMemento); + } + + [Test] + public void GetTemplatedMementoFromNodeNormalizedTemplate() + { + InstanceMemento templateMemento = _nodeTemplateSource.GetMemento("Grandmother"); + Assert.IsNotNull(templateMemento); + InstanceMemento combinedMemento = templateMemento.Substitute(_referringMemento); + + validateCombinedMemento(combinedMemento); + } + + [Test] + public void GetTheTemplatedInstance() + { + InstanceMemento memento = _templatedSource.GetMemento("Jackie"); + validateCombinedMemento(memento); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,129 @@ +using System.Xml; +using NUnit.Framework; +using StructureMap.Source; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlAttributeInstanceMementoTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + string xml = "<Instance Type=\"Color\" Key=\"Red\" color=\"red\"/>"; + _memento = buildMemento(xml); + } + + #endregion + + private XmlAttributeInstanceMemento _memento; + + + private XmlAttributeInstanceMemento buildMemento(string xml) + { + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + + return new XmlAttributeInstanceMemento(doc.DocumentElement); + } + + [Test] + public void ConcreteKey() + { + Assert.AreEqual("Color", _memento.ConcreteKey); + } + + [Test] + public void GetChildIsNotNull() + { + XmlElement element = _memento.InnerElement; + XmlElement childElement = element.OwnerDocument.CreateElement("rule"); + element.AppendChild(childElement); + childElement.SetAttribute("Type", "theConcreteKey"); + childElement.SetAttribute("Key", "theInstanceKey"); + childElement.SetAttribute("prop1", "thePropertyValue"); + + InstanceMemento memento = _memento.GetChildMemento("rule"); + Assert.IsNotNull(memento); + Assert.AreEqual("theInstanceKey", memento.InstanceKey); + Assert.AreEqual("theConcreteKey", memento.ConcreteKey); + Assert.AreEqual("thePropertyValue", memento.GetProperty("prop1")); + Assert.IsFalse(memento.IsDefault); + Assert.IsFalse(memento.IsReference); + } + + [Test] + public void GetChildrenArray() + { + XmlElement element = _memento.InnerElement; + + XmlElement rulesElement = element.OwnerDocument.CreateElement("rules"); + element.AppendChild(rulesElement); + + XmlElement childElement1 = element.OwnerDocument.CreateElement("rule"); + rulesElement.AppendChild(childElement1); + childElement1.SetAttribute("Type", "theConcreteKey"); + childElement1.SetAttribute("Key", "theInstanceKey"); + childElement1.SetAttribute("prop1", "thePropertyValue"); + + XmlElement childElement2 = (XmlElement) childElement1.CloneNode(true); + childElement2.SetAttribute("prop1", "different"); + rulesElement.AppendChild(childElement2); + + InstanceMemento[] mementoArray = _memento.GetChildrenArray("rules"); + Assert.AreEqual(2, mementoArray.Length); + + Assert.AreEqual("different", mementoArray[1].GetProperty("prop1")); + } + + [Test] + public void GetChildReturnsNullIfItDoesNotExist() + { + InstanceMemento memento = _memento.GetChildMemento("rule"); + Assert.IsNull(memento); + } + + [Test] + public void GetProperty() + { + Assert.AreEqual("red", _memento.GetProperty("color")); + } + + [Test] + public void IfNoChildrenReturnNull() + { + InstanceMemento[] mementoArray = _memento.GetChildrenArray("rules"); + Assert.IsNull(mementoArray); + } + + [Test] + public void InstanceKey() + { + Assert.AreEqual("Red", _memento.InstanceKey); + } + + [Test] + public void IsDefaultIsFalse() + { + Assert.IsFalse(_memento.IsDefault); + } + + [Test] + public void IsReferenceIsFalse() + { + Assert.IsFalse(_memento.IsReference); + } + + [Test] + public void ReferencedMemento() + { + _memento.InnerElement.SetAttribute("Type", string.Empty); + + Assert.IsTrue(_memento.IsReference); + Assert.IsFalse(_memento.IsDefault); + Assert.AreEqual("Red", _memento.ReferenceKey); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,56 @@ +using System.Xml; +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlInstanceMementoTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + XmlDocument doc = DataMother.GetXmlDocument("XmlInstanceMemento.xml"); + + memento = new XmlNodeInstanceMemento(doc.DocumentElement, "Type", "Key"); + } + + #endregion + + private XmlNodeInstanceMemento memento; + + + [Test] + public void GetChildMemento() + { + InstanceMemento child = memento.GetChildMemento("Child1"); + Assert.IsNotNull(child); + + Assert.AreEqual("Child1", child.ConcreteKey, "Type is Child1"); + Assert.AreEqual("D", child.GetProperty("Prop4"), "Prop4"); + } + + [Test] + public void GetLargeStringInAttributeMemento() + { + XmlDocument document = DataMother.GetXmlDocument("CDataTest.xml"); + XmlNode node = document.DocumentElement.LastChild; + + XmlAttributeInstanceMemento memento = new XmlAttributeInstanceMemento(node); + Assert.AreEqual("select * from table", memento.GetProperty("bigProp")); + } + + [Test] + public void GetLargeStringInNodeMemento() + { + XmlDocument document = DataMother.GetXmlDocument("CDataTest.xml"); + XmlNode node = document.DocumentElement.FirstChild; + + XmlNodeInstanceMemento memento = new XmlNodeInstanceMemento(node, "Type", "Key"); + Assert.AreEqual("select * from table", memento.GetProperty("bigProp")); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,58 @@ +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlMementoSourceTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + DataMother.WriteDocument("RuleSource.xml"); + source = new XmlFileMementoSource("RuleSource.XML", "", "Rule"); + } + + #endregion + + private MementoSource source; + + + [Test] + public void GetAll() + { + // There are 4 Rules defined in the XML file + InstanceMemento[] mementos = source.GetAllMementos(); + + Assert.IsNotNull(mementos); + Assert.AreEqual(4, mementos.Length, "4 mementos from 4 XML nodes"); + + foreach (InstanceMemento memento in mementos) + { + Assert.IsNotNull(memento); + } + } + + [Test] + public void GetComplex1() + { + InstanceMemento memento = source.GetMemento("Complex1"); + + Assert.IsNotNull(memento); + + + Assert.AreEqual("Complex1", memento.InstanceKey, "InstanceKey"); + Assert.AreEqual("Complex", memento.ConcreteKey, "ConcreteTypeKey"); + Assert.AreEqual("Red", memento.GetProperty("String"), "String"); + Assert.AreEqual("Green", memento.GetProperty("String2"), "String2"); + Assert.AreEqual("1", memento.GetProperty("Int"), "Int"); + Assert.AreEqual("2", memento.GetProperty("Long"), "Long"); + Assert.AreEqual("3", memento.GetProperty("Byte"), "Byte"); + Assert.AreEqual("4.5", memento.GetProperty("Double"), "Double"); + Assert.AreEqual("true", memento.GetProperty("Bool"), "Bool"); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs 2008-06-02 16:28:50 UTC (rev 117) @@ -0,0 +1,97 @@ +using System.Collections; +using System.Xml; +using NUnit.Framework; +using StructureMap.Source; +using StructureMap.Testing.TestData; +using StructureMap.Testing.XmlWriting; + +namespace StructureMap.Testing.Graph.Source +{ + [TestFixture] + public class XmlTemplaterTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _document = DataMother.GetXmlDocument("Templater.xml"); + } + + #endregion + + private XmlDocument _document; + + [Test] + public void GetSubstititionsExplicitly() + { + XmlNode node = _document.DocumentElement.FirstChild; + XmlElement element = (XmlElement) node; + element.SetAttribute(InstanceMemento.SUBSTITUTIONS_ATTRIBUTE, "direction,color"); + + XmlTemplater templater = new XmlTemplater(node); + string[] substitutions = templater.Substitutions; + + Assert.AreEqual(2, substitutions.Length); + ArrayList list = new ArrayList(substitutions); + + Assert.IsTrue(list.Contains("color")); + Assert.IsTrue(list.Contains("direction")); + } + + [Test] + public void GetSubstitutionsImplicitly() + { + XmlNode node = _document.DocumentElement.FirstChild; + XmlTemplater templater = new XmlTemplater(node); + string[] substitutions = templater.Substitutions; + + Assert.AreEqual(4, substitutions.Length); + ArrayList list = new ArrayList(substitutions); + + Assert.IsTrue(list.Contains("color")); + Assert.IsTrue(list.Contains("name")); + Assert.IsTrue(list.Contains("state")); + Assert.IsTrue(list.Contains("direction")); + } + + + [Test] + public void HandleStringEmpty() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento("", ""); + memento.SetProperty("color", ""); + + XmlDocument doc = new XmlDocument(); + XmlElement element = doc.CreateElement("top"); + doc.AppendChild(element); + element.SetAttribute("Color", "{color}"); + + XmlTemplater templater = new XmlTemplater(element); + + XmlElement result = (XmlElement) templater.SubstituteTemplates(element, memento); + Assert.AreEqual(InstanceMemento.EMPTY_STRING, result.GetAttribute("Color")); + } + + [Test] + public void MakeSubstitutionsInXmlNode() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento("", ""); + memento.SetProperty("color", "blue"); + memento.SetProperty("name", "ObiWan"); + memento.SetProperty("state", "New York"); + memento.SetProperty("direction", "North"); + + XmlNode templateNode = _document.DocumentElement.FirstChild; + XmlTemplater templater = new XmlTemplater(templateNode); + + XmlNode expectedNode = _document.DocumentElement.LastChild; + ElementChecker checker = new ElementChecker((XmlElement) expectedNode); + + XmlElement actualElement = (XmlElement) templater.SubstituteTemplates(templateNode, memento); + + Assert.IsFalse(ReferenceEquals(templateNode, actualElement)); + checker.Check(actualElement); + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |