|
From: <fab...@us...> - 2008-10-09 22:45:22
|
Revision: 3822
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=3822&view=rev
Author: fabiomaulo
Date: 2008-10-09 22:45:14 +0000 (Thu, 09 Oct 2008)
Log Message:
-----------
initial test to support Xml entityMode
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/
trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Accessors/
trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Accessors/XmlAccessorFixture.cs
Added: trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Accessors/XmlAccessorFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Accessors/XmlAccessorFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/EntityModeTest/Xml/Accessors/XmlAccessorFixture.cs 2008-10-09 22:45:14 UTC (rev 3822)
@@ -0,0 +1,119 @@
+using System.Xml;
+using NHibernate.Mapping;
+using NHibernate.Properties;
+using NUnit.Framework;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace NHibernate.Test.EntityModeTest.Xml.Accessors
+{
+ [TestFixture, Ignore("Not supported yet.")]
+ public class XmlAccessorFixture
+ {
+ public static XmlElement dom = GenerateTestElement();
+
+ private static XmlElement GenerateTestElement()
+ {
+ const string xml =
+@"<company id='123'>
+ description...
+ <name>NHForge</name>
+ <account num='456'/>
+</company>";
+
+ var baseXml = new XmlDocument();
+ baseXml.LoadXml(xml);
+ return baseXml.DocumentElement;
+ }
+
+ private static XmlElement GenerateRootTestElement()
+ {
+ return (new XmlDocument()).CreateElement("company");
+ }
+
+ private static Property GenerateAccountIdProperty()
+ {
+ var value = new SimpleValue {TypeName = "long"};
+
+ return new Property {Name = "number", NodeName = "account/@num", Value = value};
+ }
+
+ private static Property GenerateTextProperty()
+ {
+ var value = new SimpleValue {TypeName = "string"};
+
+ return new Property {Name = "text", NodeName = ".", Value = value};
+ }
+
+ private static Property GenerateNameProperty()
+ {
+ var value = new SimpleValue {TypeName = "string"};
+
+ return new Property {Name = "name", NodeName = "name", Value = value};
+ }
+
+ private static Property GenerateIdProperty()
+ {
+ var value = new SimpleValue {TypeName = "long"};
+
+ return new Property {Name = "id", NodeName = "@id", Value = value};
+ }
+
+ [Test]
+ public void CompanyElementGeneration()
+ {
+ ISetter idSetter = PropertyAccessorFactory.GetPropertyAccessor(GenerateIdProperty(), EntityMode.Xml).GetSetter(null,
+ null);
+ ISetter nameSetter =
+ PropertyAccessorFactory.GetPropertyAccessor(GenerateNameProperty(), EntityMode.Xml).GetSetter(null, null);
+ ISetter textSetter =
+ PropertyAccessorFactory.GetPropertyAccessor(GenerateTextProperty(), EntityMode.Xml).GetSetter(null, null);
+ ISetter accountIdSetter =
+ PropertyAccessorFactory.GetPropertyAccessor(GenerateAccountIdProperty(), EntityMode.Xml).GetSetter(null, null);
+
+ XmlNode root = GenerateRootTestElement();
+
+ idSetter.Set(root, 123L);
+ textSetter.Set(root, "description...");
+ nameSetter.Set(root, "NHForge");
+ accountIdSetter.Set(root, 456L);
+
+ //Assert.That(new NodeComparator().Compare(dom, root) == 0);
+ }
+
+ [Test]
+ public void LongAttributeExtraction()
+ {
+ Property property = GenerateIdProperty();
+ IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null);
+ var id = (long) getter.Get(dom);
+ Assert.That(id, Is.EqualTo(123L));
+ }
+
+ [Test]
+ public void LongElementAttributeExtraction()
+ {
+ Property property = GenerateAccountIdProperty();
+ IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null);
+ var id = (long) getter.Get(dom);
+ Assert.That(id, Is.EqualTo(456L));
+ }
+
+ [Test]
+ public void StringElementExtraction()
+ {
+ Property property = GenerateNameProperty();
+ IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null);
+ var name = (string) getter.Get(dom);
+ Assert.That(name, Is.EqualTo("NHForge"));
+ }
+
+ [Test]
+ public void StringTextExtraction()
+ {
+ Property property = GenerateTextProperty();
+ IGetter getter = PropertyAccessorFactory.GetPropertyAccessor(property, EntityMode.Xml).GetGetter(null, null);
+ var name = (string) getter.Get(dom);
+ Assert.That(name, Is.EqualTo("description..."));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2008-10-09 21:42:15 UTC (rev 3821)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2008-10-09 22:45:14 UTC (rev 3822)
@@ -160,6 +160,7 @@
<Compile Include="DynamicEntity\Tuplizer\TuplizerDynamicEntity.cs" />
<Compile Include="EngineTest\TypedValueFixture.cs" />
<Compile Include="EntityModeTest\Map\Basic\DynamicClassFixture.cs" />
+ <Compile Include="EntityModeTest\Xml\Accessors\XmlAccessorFixture.cs" />
<Compile Include="Events\Collections\AbstractCollectionEventFixture.cs" />
<Compile Include="Events\Collections\AbstractParentWithCollection.cs" />
<Compile Include="Events\Collections\Association\AbstractAssociationCollectionEventFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|