You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2006/03/20 21:46:32 UTC
svn commit: r387305 [1/2] - in /ibatis/trunk/cs/mapper:
IBatisNet.Common.Test/ IBatisNet.Common.Test/Domain/
IBatisNet.Common.Test/NUnit/CommonTests/Utilities/ IBatisNet.Common/
IBatisNet.Common/Utilities/Objects/Members/ IBatisNet.DataMapper/ IBatisNe...
Author: gbayon
Date: Mon Mar 20 12:46:29 2006
New Revision: 387305
URL: http://svn.apache.org/viewcvs?rev=387305&view=rev
Log:
- Refactor MemberAccessor
- Updated field support for IMemberAccessor
- Added more unit test
Added:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/IEmitPropertyAccessor.cs (with props)
Modified:
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/FieldAccessorTest.cs
ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitFieldAccessor.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/EmitPropertyAccessor.cs
ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/MemberAccessorFactory.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Configuration/DomSqlMapBuilder.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/Scope/ConfigurationScope.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper/SqlMapper.cs
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/Domain/Property.cs Mon Mar 20 12:46:29 2006
@@ -19,7 +19,8 @@
public class Property
{
private string _string = string.Empty;
- public int _int = int.MinValue;
+ private int _int = int.MinValue;
+ public int publicInt = int.MinValue;
private DateTime _dateTime = DateTime.MinValue;
private decimal _decimal = decimal.MinValue;
private sbyte _sbyte = sbyte.MinValue;
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.2005.csproj Mon Mar 20 12:46:29 2006
@@ -132,6 +132,7 @@
<Compile Include="NUnit\CommonTests\Transaction\TransactionTest.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="NUnit\CommonTests\Utilities\BaseMemberTest.cs" />
<Compile Include="NUnit\CommonTests\Utilities\FieldAccessorTest.cs" />
<Compile Include="NUnit\CommonTests\Utilities\ObjectFactoryTest.cs" />
<Compile Include="NUnit\CommonTests\Utilities\PropertyAccessorPerformance.cs" />
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/IBatisNet.Common.Test.csproj Mon Mar 20 12:46:29 2006
@@ -295,6 +295,11 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "NUnit\CommonTests\Utilities\BaseMemberTest.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "NUnit\CommonTests\Utilities\FieldAccessorTest.cs"
SubType = "Code"
BuildAction = "Compile"
Added: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs?rev=387305&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs Mon Mar 20 12:46:29 2006
@@ -0,0 +1,935 @@
+using System;
+using System.Reflection;
+using IBatisNet.Common.Test.Domain;
+using IBatisNet.Common.Utilities;
+using IBatisNet.Common.Utilities.Objects.Members;
+using NUnit.Framework;
+
+namespace IBatisNet.Common.Test.NUnit.CommonTests.Utilities
+{
+ /// <summary>
+ /// Summary description for FieldAccessorTest.
+ /// </summary>
+ [TestFixture]
+ public abstract class BaseMemberTest
+ {
+ protected MemberAccessorFactory factory = null;
+ protected IMemberAccessor intAccessor = null;
+ protected IMemberAccessor longAccessor = null;
+ protected IMemberAccessor sbyteAccessor = null;
+ protected IMemberAccessor datetimeAccessor = null;
+ protected IMemberAccessor decimalAccessor = null;
+ protected IMemberAccessor byteAccessor = null;
+ protected IMemberAccessor stringAccessor = null;
+ protected IMemberAccessor charAccessor = null;
+ protected IMemberAccessor shortAccessor = null;
+ protected IMemberAccessor ushortAccessor = null;
+ protected IMemberAccessor uintAccessor = null;
+ protected IMemberAccessor ulongAccessor = null;
+ protected IMemberAccessor boolAccessor = null;
+ protected IMemberAccessor doubleAccessor = null;
+ protected IMemberAccessor floatAccessor = null;
+ protected IMemberAccessor guidAccessor = null;
+ protected IMemberAccessor timespanAccessor = null;
+ protected IMemberAccessor accountAccessor = null;
+ protected IMemberAccessor enumAccessor = null;
+#if dotnet2
+ protected IMemberAccessor nullableAccessor = null;
+#endif
+
+
+ /// <summary>
+ /// Initialize an sqlMap
+ /// </summary>
+ [TestFixtureSetUp]
+ protected virtual void SetUpFixture()
+ {
+ factory = new MemberAccessorFactory(true);
+ }
+
+ /// <summary>
+ /// Dispose the SqlMap
+ /// </summary>
+ [TestFixtureTearDown]
+ protected virtual void TearDownFixture()
+ {
+ factory = null;
+ }
+
+ /// <summary>
+ /// Test setting null on integer property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnIntegerProperty()
+ {
+ Property prop = new Property();
+ prop.Int = -99;
+
+ // Property accessor
+ intAccessor.Set(prop, null);
+ Assert.AreEqual(0, prop.Int);
+ }
+
+ /// <summary>
+ /// Test setting an integer property.
+ /// </summary>
+ [Test]
+ public void TestSetInteger()
+ {
+ Property prop = new Property();
+ prop.Int = -99;
+
+ // Property accessor
+ int test = 57;
+ intAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Int);
+ }
+
+ /// <summary>
+ /// Test getting an integer property.
+ /// </summary>
+ [Test]
+ public void TestGetInteger()
+ {
+ int test = -99;
+ Property prop = new Property();
+ prop.Int = test;
+
+ // Property accessor
+ Assert.AreEqual(test, intAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on Long property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnLongProperty()
+ {
+ Property prop = new Property();
+ prop.Long = 78945566664213223;
+
+ // Property accessor
+ longAccessor.Set(prop, null);
+ Assert.AreEqual((long)0, prop.Long);
+ }
+
+ /// <summary>
+ /// Test setting an Long property.
+ /// </summary>
+ [Test]
+ public void TestSetLong()
+ {
+ Property prop = new Property();
+ prop.Long = 78945566664213223;
+
+ // Property accessor
+ long test = 123456789987456;
+ longAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Long);
+ }
+
+ /// <summary>
+ /// Test getting an long property.
+ /// </summary>
+ [Test]
+ public void TestGetLong()
+ {
+ long test = 78945566664213223;
+ Property prop = new Property();
+ prop.Long = test;
+
+ // Property accessor
+ Assert.AreEqual(test, longAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on sbyte property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnSbyteProperty()
+ {
+ Property prop = new Property();
+ prop.SByte = 78;
+
+ // Property accessor
+ sbyteAccessor.Set(prop, null);
+ Assert.AreEqual((sbyte)0, prop.SByte);
+ }
+
+ /// <summary>
+ /// Test setting an sbyte property.
+ /// </summary>
+ [Test]
+ public void TestSetSbyte()
+ {
+ Property prop = new Property();
+ prop.SByte = 78;
+
+ // Property accessor
+ sbyte test = 19;
+ sbyteAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.SByte);
+ }
+
+ /// <summary>
+ /// Test getting an sbyte property.
+ /// </summary>
+ [Test]
+ public void TestGetSbyte()
+ {
+ sbyte test = 78;
+ Property prop = new Property();
+ prop.SByte = test;
+
+ // Property accessor
+ Assert.AreEqual(test, sbyteAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on String property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnStringProperty()
+ {
+ Property prop = new Property();
+ prop.String = "abc";
+
+ // Property accessor
+ stringAccessor.Set(prop, null);
+ Assert.IsNull(prop.String);
+ }
+
+ /// <summary>
+ /// Test setting an String property.
+ /// </summary>
+ [Test]
+ public void TestSetString()
+ {
+ Property prop = new Property();
+ prop.String = "abc";
+
+ // Property accessor
+ string test = "wxc";
+ stringAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.String);
+ }
+
+ /// <summary>
+ /// Test getting an String property.
+ /// </summary>
+ [Test]
+ public void TestGetString()
+ {
+ string test = "abc";
+ Property prop = new Property();
+ prop.String = test;
+
+ // Property accessor
+ Assert.AreEqual(test, stringAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on DateTime property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnDateTimeProperty()
+ {
+ Property prop = new Property();
+ prop.DateTime = DateTime.Now;
+
+ // Property accessor
+ datetimeAccessor.Set(prop, null);
+ Assert.AreEqual(DateTime.MinValue, prop.DateTime);
+ }
+
+ /// <summary>
+ /// Test setting an DateTime property.
+ /// </summary>
+ [Test]
+ public void TestSetDateTime()
+ {
+ Property prop = new Property();
+ prop.DateTime = DateTime.Now;
+
+ // Property accessor
+ DateTime test = new DateTime(1987,11,25);
+ datetimeAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.DateTime);
+ }
+
+ /// <summary>
+ /// Test getting an DateTime property.
+ /// </summary>
+ [Test]
+ public void TestGetDateTime()
+ {
+ DateTime test = new DateTime(1987, 11, 25);
+ Property prop = new Property();
+ prop.DateTime = test;
+
+ // Property accessor
+ Assert.AreEqual(test, datetimeAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on decimal property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnDecimalProperty()
+ {
+ Property prop = new Property();
+ prop.Decimal = 45.187M;
+
+ // Property accessor
+ decimalAccessor.Set(prop, null);
+ Assert.AreEqual(0.0M, prop.Decimal);
+ }
+
+ /// <summary>
+ /// Test setting an decimal property.
+ /// </summary>
+ [Test]
+ public void TestSetDecimal()
+ {
+ Property prop = new Property();
+ prop.Decimal = 45.187M;
+
+ // Property accessor
+ Decimal test = 789456.141516M;
+ decimalAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Decimal);
+ }
+
+ /// <summary>
+ /// Test getting an decimal property.
+ /// </summary>
+ [Test]
+ public void TestGetDecimal()
+ {
+ Decimal test = 789456.141516M;
+ Property prop = new Property();
+ prop.Decimal = test;
+
+ // Property accessor
+ Assert.AreEqual(test, decimalAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on byte property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnByteProperty()
+ {
+ Property prop = new Property();
+ prop.Byte = 78;
+
+ // Property accessor
+ byteAccessor.Set(prop, null);
+ Assert.AreEqual((byte)0, prop.Byte);
+ }
+
+ /// <summary>
+ /// Test setting an byte property.
+ /// </summary>
+ [Test]
+ public void TestSetByte()
+ {
+ Property prop = new Property();
+ prop.Byte = 15;
+
+ // Property accessor
+ byte test = 94;
+ byteAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Byte);
+ }
+
+ /// <summary>
+ /// Test getting an byte property.
+ /// </summary>
+ [Test]
+ public void TestGetByte()
+ {
+ byte test = 78;
+ Property prop = new Property();
+ prop.Byte = test;
+
+ // Property accessor
+ Assert.AreEqual(test, byteAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on char property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnCharProperty()
+ {
+ Property prop = new Property();
+ prop.Char = 'r';
+
+ // Property accessor
+ charAccessor.Set(prop, null);
+ Assert.AreEqual('\0', prop.Char);
+ }
+
+ /// <summary>
+ /// Test setting an char property.
+ /// </summary>
+ [Test]
+ public void TestSetChar()
+ {
+ Property prop = new Property();
+ prop.Char = 'b';
+
+ // Property accessor
+ char test = 'j';
+ charAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Char);
+ }
+
+ /// <summary>
+ /// Test getting an char property.
+ /// </summary>
+ [Test]
+ public void TestGetChar()
+ {
+ char test = 'z';
+ Property prop = new Property();
+ prop.Char = test;
+
+ // Property accessor
+ Assert.AreEqual(test, charAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on short property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnShortProperty()
+ {
+ Property prop = new Property();
+ prop.Short = 5;
+
+ // Property accessor
+ shortAccessor.Set(prop, null);
+ Assert.AreEqual((short)0, prop.Short);
+ }
+
+ /// <summary>
+ /// Test setting an short property.
+ /// </summary>
+ [Test]
+ public void TestSetShort()
+ {
+ Property prop = new Property();
+ prop.Short = 9;
+
+ // Property accessor
+ short test = 45;
+ shortAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Short);
+ }
+
+ /// <summary>
+ /// Test getting an short property.
+ /// </summary>
+ [Test]
+ public void TestGetShort()
+ {
+ short test = 99;
+ Property prop = new Property();
+ prop.Short = test;
+
+ // Property accessor
+ Assert.AreEqual(test, shortAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on ushort property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnUShortProperty()
+ {
+ Property prop = new Property();
+ prop.UShort = 5;
+
+ // Property accessor
+ ushortAccessor.Set(prop, null);
+ Assert.AreEqual((ushort)0, prop.UShort);
+ }
+
+ /// <summary>
+ /// Test setting an ushort property.
+ /// </summary>
+ [Test]
+ public void TestSetUShort()
+ {
+ Property prop = new Property();
+ prop.UShort = 9;
+
+ // Property accessor
+ ushort test = 45;
+ ushortAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.UShort);
+ }
+
+ /// <summary>
+ /// Test getting an ushort property.
+ /// </summary>
+ [Test]
+ public void TestGetUShort()
+ {
+ ushort test = 99;
+ Property prop = new Property();
+ prop.UShort = test;
+
+ // Property accessor
+ Assert.AreEqual(test, ushortAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on uint property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnUIntProperty()
+ {
+ Property prop = new Property();
+ prop.UInt = 5;
+
+ // Property accessor
+ uintAccessor.Set(prop, null);
+ Assert.AreEqual((uint)0, prop.UInt);
+ }
+
+ /// <summary>
+ /// Test setting an uint property.
+ /// </summary>
+ [Test]
+ public void TestSetUInt()
+ {
+ Property prop = new Property();
+ prop.UInt = 9;
+
+ // Property accessor
+ uint test = 45;
+ uintAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.UInt);
+ }
+
+ /// <summary>
+ /// Test getting an uint property.
+ /// </summary>
+ [Test]
+ public void TestGetUInt()
+ {
+ uint test = 99;
+ Property prop = new Property();
+ prop.UInt = test;
+
+ // Property accessor
+ Assert.AreEqual(test, uintAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on ulong property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnULongProperty()
+ {
+ Property prop = new Property();
+ prop.ULong = 5L;
+
+ // Property accessor
+ ulongAccessor.Set(prop, null);
+ Assert.AreEqual((ulong)0, prop.ULong);
+ }
+
+ /// <summary>
+ /// Test setting an ulong property.
+ /// </summary>
+ [Test]
+ public void TestSetULong()
+ {
+ Property prop = new Property();
+ prop.ULong = 45464646578;
+
+ // Property accessor
+ ulong test = 45;
+ ulongAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.ULong);
+ }
+
+ /// <summary>
+ /// Test getting an ulong property.
+ /// </summary>
+ [Test]
+ public void TestGetULong()
+ {
+ ulong test = 99;
+ Property prop = new Property();
+ prop.ULong = test;
+
+ // Property accessor
+ Assert.AreEqual(test, ulongAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on bool property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnBoolProperty()
+ {
+ Property prop = new Property();
+ prop.Bool = true;
+
+ // Property accessor
+ boolAccessor.Set(prop, null);
+ Assert.AreEqual(false, prop.Bool);
+ }
+
+ /// <summary>
+ /// Test setting an bool property.
+ /// </summary>
+ [Test]
+ public void TestSetBool()
+ {
+ Property prop = new Property();
+ prop.Bool = false;
+
+ // Property accessor
+ bool test = true;
+ boolAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Bool);
+ }
+
+ /// <summary>
+ /// Test getting an bool property.
+ /// </summary>
+ [Test]
+ public void TestGetBool()
+ {
+ bool test = false;
+ Property prop = new Property();
+ prop.Bool = test;
+
+ // Property accessor
+ Assert.AreEqual(test, boolAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on double property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnDoubleProperty()
+ {
+ Property prop = new Property();
+ prop.Double = 788956.56D;
+
+ // Property accessor
+ doubleAccessor.Set(prop, null);
+ Assert.AreEqual(0.0D, prop.Double);
+ }
+
+ /// <summary>
+ /// Test setting an double property.
+ /// </summary>
+ [Test]
+ public void TestSetDouble()
+ {
+ Property prop = new Property();
+ prop.Double = 56789123.45888D;
+
+ // Property accessor
+ double test = 788956.56D;
+ doubleAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Double);
+ }
+
+ /// <summary>
+ /// Test getting an double property.
+ /// </summary>
+ [Test]
+ public void TestGetDouble()
+ {
+ double test = 788956.56D;
+ Property prop = new Property();
+ prop.Double = test;
+
+ // Property accessor
+ Assert.AreEqual(test, doubleAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting null on float property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnFloatProperty()
+ {
+ Property prop = new Property();
+ prop.Float = 565.45F;
+
+ // Property accessor
+ floatAccessor.Set(prop, null);
+ Assert.AreEqual(0.0D, prop.Float);
+ }
+
+ /// <summary>
+ /// Test setting an float property.
+ /// </summary>
+ [Test]
+ public void TestSetFloat()
+ {
+ Property prop = new Property();
+ prop.Float = 565.45F;
+
+ // Property accessor
+ float test = 4567.45F;
+ floatAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Float);
+ }
+
+ /// <summary>
+ /// Test getting an float property.
+ /// </summary>
+ [Test]
+ public void TestGetFloat()
+ {
+ float test = 565.45F;
+ Property prop = new Property();
+ prop.Float = test;
+
+ // Property accessor
+ Assert.AreEqual(test, floatAccessor.Get(prop));
+ }
+
+
+ /// <summary>
+ /// Test setting null on Guid property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnGuidProperty()
+ {
+ Property prop = new Property();
+ prop.Guid = Guid.NewGuid();
+
+ // Property accessor
+ guidAccessor.Set(prop, null);
+ Assert.AreEqual(Guid.Empty, prop.Guid);
+ }
+
+ /// <summary>
+ /// Test setting an Guid property.
+ /// </summary>
+ [Test]
+ public void TestSetGuid()
+ {
+ Property prop = new Property();
+ prop.Guid = Guid.NewGuid();
+
+ // Property accessor
+ Guid test = Guid.NewGuid();
+ guidAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Guid);
+ }
+
+ /// <summary>
+ /// Test getting an Guid property.
+ /// </summary>
+ [Test]
+ public void TestGetGuid()
+ {
+ Guid test = Guid.NewGuid();
+ Property prop = new Property();
+ prop.Guid = test;
+
+ // Property accessor
+ Assert.AreEqual(test, guidAccessor.Get(prop));
+ }
+
+
+ /// <summary>
+ /// Test the setting null on a TimeSpan property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnTimeSpanProperty()
+ {
+ Property prop = new Property();
+ prop.TimeSpan = new TimeSpan(5, 12, 57, 21, 13);
+
+ // Property accessor
+ timespanAccessor.Set(prop, null);
+ Assert.AreEqual(TimeSpan.MinValue, prop.TimeSpan);
+ }
+
+ /// <summary>
+ /// Test setting an TimeSpan property.
+ /// </summary>
+ [Test]
+ public void TestSetTimeSpan()
+ {
+ Property prop = new Property();
+ prop.TimeSpan = new TimeSpan(5, 12, 57, 21, 13);
+
+ // Property accessor
+ TimeSpan test = new TimeSpan(15, 5, 21, 45, 35);
+ timespanAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.TimeSpan);
+ }
+
+ /// <summary>
+ /// Test getting an TimeSpan property.
+ /// </summary>
+ [Test]
+ public void TestGetTimeSpan()
+ {
+ TimeSpan test = new TimeSpan(5, 12, 57, 21, 13);
+ Property prop = new Property();
+ prop.TimeSpan = test;
+
+ // Property accessor
+ Assert.AreEqual(test, timespanAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test the setting null on a object property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnAccountProperty()
+ {
+ Property prop = new Property();
+ prop.Account = new Account() ;
+ prop.Account.FirstName = "test";
+
+ // Property accessor
+ accountAccessor.Set(prop, null);
+ Assert.AreEqual(null, prop.Account);
+ }
+
+ /// <summary>
+ /// Test getting an object property.
+ /// </summary>
+ [Test]
+ public void TestGetAccount()
+ {
+ Account test = new Account();
+ test.FirstName = "Gilles";
+
+ Property prop = new Property();
+ prop.Account = test;
+
+ // Property accessor
+ Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(test), HashCodeProvider.GetIdentityHashCode(prop.Account));
+ Assert.AreEqual(test.FirstName, ((Account)accountAccessor.Get(prop)).FirstName);
+ }
+
+ /// <summary>
+ /// Test setting an object property.
+ /// </summary>
+ [Test]
+ public void TestSetAccount()
+ {
+ Property prop = new Property();
+ prop.Account = new Account() ;
+ prop.Account.FirstName = "test";
+
+ // Property accessor
+ string firstName = "Gilles";
+ Account test = new Account();
+ test.FirstName = firstName;
+ accountAccessor.Set(prop, test);
+
+ Assert.AreEqual(firstName, prop.Account.FirstName);
+ }
+
+ /// <summary>
+ /// Test the setting null on a Enum property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnEnumProperty()
+ {
+ Property prop = new Property();
+ prop.Day = Days.Thu;
+
+ PropertyInfo propertyInfo = typeof(Property).GetProperty("Day", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
+ propertyInfo.SetValue(prop, null, null);
+
+ // Property accessor
+ enumAccessor.Set(prop, null);
+ Assert.AreEqual(TimeSpan.MinValue, prop.TimeSpan);
+ }
+
+ /// <summary>
+ /// Test setting an Enum property.
+ /// </summary>
+ [Test]
+ public void TestSetEnum()
+ {
+ Property prop = new Property();
+ prop.Day = Days.Thu;
+
+ // Property accessor
+ Days test = Days.Wed;
+ enumAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Day);
+ }
+
+ /// <summary>
+ /// Test getting an Enum property.
+ /// </summary>
+ [Test]
+ public void TestGetEnum()
+ {
+ Days test = Days.Wed;
+ Property prop = new Property();
+ prop.Day = test;
+
+ // Property accessor
+ Assert.AreEqual(test, enumAccessor.Get(prop));
+ }
+
+#if dotnet2
+ /// <summary>
+ /// Test the setting null on a nullable int property.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnNullableIntProperty()
+ {
+ Property prop = new Property();
+ prop.IntNullable = 85;
+
+ // Property accessor
+ nullableAccessor.Set(prop, null);
+ Assert.AreEqual(null, prop.IntNullable);
+ }
+
+ /// <summary>
+ /// Test getting an nullable int property.
+ /// </summary>
+ [Test]
+ public void TestGetNullableInt()
+ {
+ Int32? test = 55;
+ Property prop = new Property();
+ prop.IntNullable = test;
+
+ // Property accessor
+ Assert.AreEqual(test, nullableAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting an nullable int property.
+ /// </summary>
+ [Test]
+ public void TestSetNullableInt()
+ {
+ Property prop = new Property();
+ prop.IntNullable = 99;
+
+ // Property accessor
+ Int32? test = 55;
+ nullableAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.IntNullable);
+
+ }
+#endif
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/BaseMemberTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/FieldAccessorTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/FieldAccessorTest.cs?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/FieldAccessorTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/FieldAccessorTest.cs Mon Mar 20 12:46:29 2006
@@ -13,37 +13,107 @@
[TestFixture]
public class FieldAccessorTest
{
- /// <summary>
- /// Test setting an integer property.
- /// </summary>
- [Test]
- public void TestSetInteger()
- {
- Property prop = new Property();
- prop.Int = -99;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "_int");
- int test = 57;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Int);
- }
-
- /// <summary>
- /// Test getting an integer property.
- /// </summary>
- [Test]
- public void TestGetInteger()
- {
- int test = -99;
- Property prop = new Property();
- prop.Int = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "_int");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
+ private MemberAccessorFactory _factory = null;
+
+ #region SetUp & TearDown
+
+ /// <summary>
+ /// SetUp
+ /// </summary>
+ [SetUp]
+ public void SetUp()
+ {
+ _factory = new MemberAccessorFactory(true);
+ }
+
+
+ /// <summary>
+ /// TearDown
+ /// </summary>
+ [TearDown]
+ public void Dispose()
+ {
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Test setting null on integer public field.
+ /// </summary>
+ [Test]
+ public void TestSetNullOnIntegerField()
+ {
+ Property prop = new Property();
+ prop.publicInt = -99;
+
+ // Property accessor
+ IMemberAccessor memberAccessor = _factory.CreateMemberAccessor(typeof(Property), "publicInt");
+ memberAccessor.Set(prop, null);
+ Assert.AreEqual(0, prop.publicInt);
+ }
+
+ /// <summary>
+ /// Test setting an integer public field.
+ /// </summary>
+ [Test]
+ public void TestSetPublicFieldInteger()
+ {
+ Property prop = new Property();
+ prop.publicInt = -99;
+
+ // Property accessor
+ int test = 57;
+ IMemberAccessor memberAccessor = _factory.CreateMemberAccessor(typeof(Property), "publicInt");
+ memberAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.publicInt);
+ }
+
+ /// <summary>
+ /// Test getting an integer public field.
+ /// </summary>
+ [Test]
+ public void TestGetPublicFieldInteger()
+ {
+ int test = -99;
+ Property prop = new Property();
+ prop.publicInt = test;
+
+ // Property accessor
+ IMemberAccessor memberAccessor = _factory.CreateMemberAccessor(typeof(Property), "publicInt");
+ Assert.AreEqual(test, memberAccessor.Get(prop));
+ }
+
+ /// <summary>
+ /// Test setting an integer private field.
+ /// </summary>
+ [Test]
+ [ExpectedException(typeof(FieldAccessException))]
+ public void TestSetPrivateFieldInteger()
+ {
+ Property prop = new Property();
+ prop.Int = -99;
+
+ // Property accessor
+ int test = 57;
+ IMemberAccessor memberAccessor = _factory.CreateMemberAccessor(typeof(Property), "_int");
+ memberAccessor.Set(prop, test);
+ Assert.AreEqual(test, prop.Int);
+ }
+
+ /// <summary>
+ /// Test getting an integer private field.
+ /// </summary>
+ [Test]
+ [ExpectedException(typeof(FieldAccessException))]
+ public void TestGetPrivateFieldInteger()
+ {
+ int test = -99;
+ Property prop = new Property();
+ prop.Int = test;
+
+ // Property accessor
+ IMemberAccessor memberAccessor = _factory.CreateMemberAccessor(typeof(Property), "_int");
+ Assert.AreEqual(test, memberAccessor.Get(prop));
+ }
}
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common.Test/NUnit/CommonTests/Utilities/PropertyAccessorTest.cs Mon Mar 20 12:46:29 2006
@@ -7,8 +7,8 @@
namespace IBatisNet.Common.Test.NUnit.CommonTests.Utilities
{
- [TestFixture]
- public class PropertyAccessorTest
+ [TestFixture]
+ public class PropertyAccessorTest : BaseMemberTest
{
#region SetUp & TearDown
@@ -18,6 +18,28 @@
[SetUp]
public void SetUp()
{
+ intAccessor = factory.CreateMemberAccessor(typeof(Property), "Int");
+ longAccessor = factory.CreateMemberAccessor(typeof(Property), "Long");
+ sbyteAccessor = factory.CreateMemberAccessor(typeof(Property), "SByte");
+ stringAccessor = factory.CreateMemberAccessor(typeof(Property), "String");
+ datetimeAccessor = factory.CreateMemberAccessor(typeof(Property), "DateTime");
+ decimalAccessor = factory.CreateMemberAccessor(typeof(Property), "Decimal");
+ byteAccessor = factory.CreateMemberAccessor(typeof(Property), "Byte");
+ charAccessor = factory.CreateMemberAccessor(typeof(Property), "Char");
+ shortAccessor = factory.CreateMemberAccessor(typeof(Property), "Short");
+ ushortAccessor = factory.CreateMemberAccessor(typeof(Property), "UShort");
+ uintAccessor = factory.CreateMemberAccessor(typeof(Property), "UInt");
+ ulongAccessor = factory.CreateMemberAccessor(typeof(Property), "ULong");
+ boolAccessor = factory.CreateMemberAccessor(typeof(Property), "Bool");
+ doubleAccessor = factory.CreateMemberAccessor(typeof(Property), "Double");
+ floatAccessor = factory.CreateMemberAccessor(typeof(Property), "Float");
+ guidAccessor = factory.CreateMemberAccessor(typeof(Property), "Guid");
+ timespanAccessor = factory.CreateMemberAccessor(typeof(Property), "TimeSpan");
+ accountAccessor = factory.CreateMemberAccessor(typeof(Property), "Account");
+ enumAccessor = factory.CreateMemberAccessor(typeof(Property), "Day");
+#if dotnet2
+ nullableAccessor = factory.CreateMemberAccessor(typeof(Property), "IntNullable");
+#endif
}
@@ -31,1054 +53,38 @@
#endregion
- /// <summary>
- /// Test MemberAccessorFactory
- /// </summary>
- [Test]
- public void TestMemberAccessorFactory()
- {
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor1 = factory.CreateMemberAccessor(typeof(Property), "Int");
- IMemberAccessor propertyAccessor2 = factory.CreateMemberAccessor(typeof(Property), "Int");
-
- Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(propertyAccessor1), HashCodeProvider.GetIdentityHashCode(propertyAccessor2) );
- }
-
- /// <summary>
- /// Test multiple MemberAccessorFactory
- /// </summary>
- [Test]
- public void TestMultipleMemberAccessorFactory()
- {
- Property prop = new Property();
- MemberAccessorFactory factory1 = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor1 = factory1.CreateMemberAccessor(typeof(Property), "Int");
-
- MemberAccessorFactory factory2 = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor2 = factory2.CreateMemberAccessor(typeof(Property), "Int");
-
- Assert.AreEqual(int.MinValue, propertyAccessor1.Get(prop));
- Assert.AreEqual(int.MinValue, propertyAccessor2.Get(prop));
- }
-
-
-
- /// <summary>
- /// Test the performance of getting an integer property.
- /// </summary>
- [Test]
- public void TestSetNullOnIntegerProperty()
- {
- Property prop = new Property();
- prop.Int = -99;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Int");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(0, prop.Int);
- }
-
- /// <summary>
- /// Test setting an integer property.
- /// </summary>
- [Test]
- public void TestSetInteger()
- {
- Property prop = new Property();
- prop.Int = -99;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Int");
- int test = 57;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Int);
- }
-
- /// <summary>
- /// Test getting an integer property.
- /// </summary>
- [Test]
- public void TestGetInteger()
- {
- int test = -99;
- Property prop = new Property();
- prop.Int = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Int");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an Long property.
- /// </summary>
- [Test]
- public void TestSetNullOnLongProperty()
- {
- Property prop = new Property();
- prop.Long = 78945566664213223;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Long");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((long)0, prop.Long);
- }
-
- /// <summary>
- /// Test setting an Long property.
- /// </summary>
- [Test]
- public void TestSetLong()
- {
- Property prop = new Property();
- prop.Long = 78945566664213223;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Long");
- long test = 123456789987456;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Long);
- }
-
- /// <summary>
- /// Test getting an long property.
- /// </summary>
- [Test]
- public void TestGetLong()
- {
- long test = 78945566664213223;
- Property prop = new Property();
- prop.Long = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Long");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an sbyte property.
- /// </summary>
- [Test]
- public void TestSetNullOnSbyteProperty()
- {
- Property prop = new Property();
- prop.SByte = 78;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "SByte");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((sbyte)0, prop.SByte);
- }
-
- /// <summary>
- /// Test setting an sbyte property.
- /// </summary>
- [Test]
- public void TestSetSbyte()
- {
- Property prop = new Property();
- prop.SByte = 78;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "SByte");
- sbyte test = 19;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.SByte);
- }
-
- /// <summary>
- /// Test getting an sbyte property.
- /// </summary>
- [Test]
- public void TestGetSbyte()
- {
- sbyte test = 78;
- Property prop = new Property();
- prop.SByte = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "SByte");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an String property.
- /// </summary>
- [Test]
- public void TestSetNullOnStringProperty()
- {
- Property prop = new Property();
- prop.String = "abc";
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "String");
- propertyAccessor.Set(prop, null);
- Assert.IsNull(prop.String);
- }
-
- /// <summary>
- /// Test setting an String property.
- /// </summary>
- [Test]
- public void TestSetString()
- {
- Property prop = new Property();
- prop.String = "abc";
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "String");
- string test = "wxc";
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.String);
- }
-
- /// <summary>
- /// Test getting an String property.
- /// </summary>
- [Test]
- public void TestGetString()
- {
- string test = "abc";
- Property prop = new Property();
- prop.String = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "String");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an DateTime property.
- /// </summary>
- [Test]
- public void TestSetNullOnDateTimeProperty()
- {
- Property prop = new Property();
- prop.DateTime = DateTime.Now;
-
-// PropertyInfo propertyInfo = typeof(Property).GetProperty("DateTime", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
-// propertyInfo.SetValue(prop, null, null);
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "DateTime");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(DateTime.MinValue, prop.DateTime);
- }
-
- /// <summary>
- /// Test setting an DateTime property.
- /// </summary>
- [Test]
- public void TestSetDateTime()
- {
- Property prop = new Property();
- prop.DateTime = DateTime.Now;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "DateTime");
- DateTime test = new DateTime(1987,11,25);
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.DateTime);
- }
-
- /// <summary>
- /// Test getting an DateTime property.
- /// </summary>
- [Test]
- public void TestGetDateTime()
- {
- DateTime test = new DateTime(1987,11,25);
- Property prop = new Property();
- prop.DateTime = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "DateTime");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an decimal property.
- /// </summary>
- [Test]
- public void TestSetNullOnDecimalProperty()
- {
- Property prop = new Property();
- prop.Decimal = 45.187M;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Decimal");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(0.0M, prop.Decimal);
- }
-
- /// <summary>
- /// Test setting an decimal property.
- /// </summary>
- [Test]
- public void TestSetDecimal()
- {
- Property prop = new Property();
- prop.Decimal = 45.187M;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Decimal");
- Decimal test = 789456.141516M;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Decimal);
- }
-
- /// <summary>
- /// Test getting an decimal property.
- /// </summary>
- [Test]
- public void TestGetDecimal()
- {
- Decimal test = 789456.141516M;
- Property prop = new Property();
- prop.Decimal = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Decimal");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an byte property.
- /// </summary>
- [Test]
- public void TestSetNullOnByteProperty()
- {
- Property prop = new Property();
- prop.Byte = 78;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Byte");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((byte)0, prop.Byte);
- }
-
- /// <summary>
- /// Test setting an byte property.
- /// </summary>
- [Test]
- public void TestSetByte()
- {
- Property prop = new Property();
- prop.Byte = 15;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Byte");
- byte test = 94;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Byte);
- }
-
- /// <summary>
- /// Test getting an byte property.
- /// </summary>
- [Test]
- public void TestGetByte()
- {
- byte test = 78;
- Property prop = new Property();
- prop.Byte = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Byte");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an char property.
- /// </summary>
- [Test]
- public void TestSetNullOnCharProperty()
- {
- Property prop = new Property();
- prop.Char = 'r';
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Char");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual('\0', prop.Char);
- }
-
- /// <summary>
- /// Test setting an char property.
- /// </summary>
- [Test]
- public void TestSetChar()
- {
- Property prop = new Property();
- prop.Char = 'b';
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Char");
- char test = 'j';
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Char);
- }
-
- /// <summary>
- /// Test getting an char property.
- /// </summary>
- [Test]
- public void TestGetChar()
- {
- char test = 'z';
- Property prop = new Property();
- prop.Char = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Char");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an short property.
- /// </summary>
- [Test]
- public void TestSetNullOnShortProperty()
- {
- Property prop = new Property();
- prop.Short = 5;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Short");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((short)0, prop.Short);
- }
-
- /// <summary>
- /// Test setting an short property.
- /// </summary>
- [Test]
- public void TestSetShort()
- {
- Property prop = new Property();
- prop.Short = 9;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Short");
- short test = 45;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Short);
- }
-
- /// <summary>
- /// Test getting an short property.
- /// </summary>
- [Test]
- public void TestGetShort()
- {
- short test = 99;
- Property prop = new Property();
- prop.Short = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Short");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an ushort property.
- /// </summary>
- [Test]
- public void TestSetNullOnUShortProperty()
- {
- Property prop = new Property();
- prop.UShort = 5;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "UShort");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((ushort)0, prop.UShort);
- }
-
- /// <summary>
- /// Test setting an ushort property.
- /// </summary>
- [Test]
- public void TestSetUShort()
- {
- Property prop = new Property();
- prop.UShort = 9;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "UShort");
- ushort test = 45;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.UShort);
- }
-
- /// <summary>
- /// Test getting an ushort property.
- /// </summary>
- [Test]
- public void TestGetUShort()
- {
- ushort test = 99;
- Property prop = new Property();
- prop.UShort = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "UShort");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an uint property.
- /// </summary>
- [Test]
- public void TestSetNullOnUIntProperty()
- {
- Property prop = new Property();
- prop.UInt = 5;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "UInt");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((uint)0, prop.UInt);
- }
-
- /// <summary>
- /// Test setting an uint property.
- /// </summary>
- [Test]
- public void TestSetUInt()
- {
- Property prop = new Property();
- prop.UInt = 9;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "UInt");
- uint test = 45;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.UInt);
- }
-
- /// <summary>
- /// Test getting an uint property.
- /// </summary>
- [Test]
- public void TestGetUInt()
- {
- uint test = 99;
- Property prop = new Property();
- prop.UInt = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "UInt");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an ulong property.
- /// </summary>
- [Test]
- public void TestSetNullOnULongProperty()
- {
- Property prop = new Property();
- prop.ULong = 5L;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "ULong");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual((ulong)0, prop.ULong);
- }
+ ///// <summary>
+ ///// Test MemberAccessorFactory
+ ///// </summary>
+ //[Test]
+ //public void TestMemberAccessorFactory()
+ //{
+ // IMemberAccessor propertyAccessor1 = factory.CreateMemberAccessor(typeof(Property), "Int");
+ // IMemberAccessor propertyAccessor2 = factory.CreateMemberAccessor(typeof(Property), "Int");
+
+ // Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(propertyAccessor1), HashCodeProvider.GetIdentityHashCode(propertyAccessor2) );
+ //}
+
+ ///// <summary>
+ ///// Test multiple MemberAccessorFactory
+ ///// </summary>
+ //[Test]
+ //public void TestMultipleMemberAccessorFactory()
+ //{
+ // Property prop = new Property();
+ // IMemberAccessor propertyAccessor1 = factory1.CreateMemberAccessor(typeof(Property), "Int");
+
+ // MemberAccessorFactory factory2 = new MemberAccessorFactory(true);
+ // IMemberAccessor propertyAccessor2 = factory2.CreateMemberAccessor(typeof(Property), "Int");
+
+ // Assert.AreEqual(int.MinValue, propertyAccessor1.Get(prop));
+ // Assert.AreEqual(int.MinValue, propertyAccessor2.Get(prop));
+ //}
- /// <summary>
- /// Test setting an ulong property.
- /// </summary>
- [Test]
- public void TestSetULong()
- {
- Property prop = new Property();
- prop.ULong = 45464646578;
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "ULong");
- ulong test = 45;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.ULong);
- }
- /// <summary>
- /// Test getting an ulong property.
- /// </summary>
- [Test]
- public void TestGetULong()
- {
- ulong test = 99;
- Property prop = new Property();
- prop.ULong = test;
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "ULong");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
- /// <summary>
- /// Test the performance of getting an bool property.
- /// </summary>
- [Test]
- public void TestSetNullOnBoolProperty()
- {
- Property prop = new Property();
- prop.Bool = true;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Bool");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(false, prop.Bool);
- }
-
- /// <summary>
- /// Test setting an bool property.
- /// </summary>
- [Test]
- public void TestSetBool()
- {
- Property prop = new Property();
- prop.Bool = false;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Bool");
- bool test = true;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Bool);
- }
-
- /// <summary>
- /// Test getting an bool property.
- /// </summary>
- [Test]
- public void TestGetBool()
- {
- bool test = false;
- Property prop = new Property();
- prop.Bool = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Bool");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an double property.
- /// </summary>
- [Test]
- public void TestSetNullOnDoubleProperty()
- {
- Property prop = new Property();
- prop.Double = 788956.56D;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Double");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(0.0D, prop.Double);
- }
-
- /// <summary>
- /// Test setting an double property.
- /// </summary>
- [Test]
- public void TestSetDouble()
- {
- Property prop = new Property();
- prop.Double = 56789123.45888D;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Double");
- double test = 788956.56D;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Double);
- }
-
- /// <summary>
- /// Test getting an double property.
- /// </summary>
- [Test]
- public void TestGetDouble()
- {
- double test = 788956.56D;
- Property prop = new Property();
- prop.Double = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Double");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an float property.
- /// </summary>
- [Test]
- public void TestSetNullOnFloatProperty()
- {
- Property prop = new Property();
- prop.Float = 565.45F;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Float");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(0.0D, prop.Float);
- }
-
- /// <summary>
- /// Test setting an float property.
- /// </summary>
- [Test]
- public void TestSetFloat()
- {
- Property prop = new Property();
- prop.Float = 565.45F;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Float");
- float test = 4567.45F;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Float);
- }
-
- /// <summary>
- /// Test getting an float property.
- /// </summary>
- [Test]
- public void TestGetFloat()
- {
- float test = 565.45F;
- Property prop = new Property();
- prop.Float = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Float");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the performance of getting an Guid property.
- /// </summary>
- [Test]
- public void TestSetNullOnGuidProperty()
- {
- Property prop = new Property();
- prop.Guid = Guid.NewGuid();
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Guid");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(Guid.Empty, prop.Guid);
- }
-
- /// <summary>
- /// Test setting an Guid property.
- /// </summary>
- [Test]
- public void TestSetGuid()
- {
- Property prop = new Property();
- prop.Guid = Guid.NewGuid();
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Guid");
- Guid test = Guid.NewGuid();
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Guid);
- }
-
- /// <summary>
- /// Test getting an Guid property.
- /// </summary>
- [Test]
- public void TestGetGuid()
- {
- Guid test = Guid.NewGuid();
- Property prop = new Property();
- prop.Guid = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Guid");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
- /// <summary>
- /// Test the setting null on a TimeSpan property.
- /// </summary>
- [Test]
- public void TestSetNullOnTimeSpanProperty()
- {
- Property prop = new Property();
- prop.TimeSpan = new TimeSpan(5,12,57,21,13) ;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "TimeSpan");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(TimeSpan.MinValue, prop.TimeSpan);
- }
-
- /// <summary>
- /// Test setting an TimeSpan property.
- /// </summary>
- [Test]
- public void TestSetTimeSpan()
- {
- Property prop = new Property();
- prop.TimeSpan = new TimeSpan(5,12,57,21,13) ;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "TimeSpan");
- TimeSpan test = new TimeSpan(15,5,21,45,35) ;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.TimeSpan);
- }
-
- /// <summary>
- /// Test getting an TimeSpan property.
- /// </summary>
- [Test]
- public void TestGetTimeSpan()
- {
- TimeSpan test = new TimeSpan(5,12,57,21,13) ;
- Property prop = new Property();
- prop.TimeSpan = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "TimeSpan");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
-
- /// <summary>
- /// Test the setting null on a object property.
- /// </summary>
- [Test]
- public void TestSetNullOnAccountProperty()
- {
- Property prop = new Property();
- prop.Account = new Account() ;
- prop.Account.FirstName = "test";
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Account");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(null, prop.Account);
- }
-
- /// <summary>
- /// Test getting an object property.
- /// </summary>
- [Test]
- public void TestGetAccount()
- {
- Account test = new Account();
- test.FirstName = "Gilles";
-
- Property prop = new Property();
- prop.Account = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Account");
-
- Assert.AreEqual(HashCodeProvider.GetIdentityHashCode(test), HashCodeProvider.GetIdentityHashCode(prop.Account));
-
- Assert.AreEqual(test.FirstName, ((Account)propertyAccessor.Get(prop)).FirstName );
- }
-
- /// <summary>
- /// Test setting an object property.
- /// </summary>
- [Test]
- public void TestSetAccount()
- {
- Property prop = new Property();
- prop.Account = new Account() ;
- prop.Account.FirstName = "test";
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Account");
- Account test = new Account();
- test.FirstName = "Gilles";
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test.FirstName, prop.Account.FirstName);
-
- }
-
- /// <summary>
- /// Test the setting null on a Enum property.
- /// </summary>
- [Test]
- public void TestSetNullOnEnumProperty()
- {
- Property prop = new Property();
- prop.Day = Days.Thu;
-
- PropertyInfo propertyInfo = typeof(Property).GetProperty("Day", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance);
- propertyInfo.SetValue(prop, null, null);
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Day");
- propertyAccessor.Set(prop, null);
- //Assert.AreEqual(TimeSpan.MinValue, prop.TimeSpan);
- }
-
- /// <summary>
- /// Test setting an Enum property.
- /// </summary>
- [Test]
- public void TestSetEnum()
- {
- Property prop = new Property();
- prop.Day = Days.Thu;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Day");
- Days test = Days.Wed;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.Day);
- }
-
- /// <summary>
- /// Test getting an Enum property.
- /// </summary>
- [Test]
- public void TestGetEnum()
- {
- Days test = Days.Wed;
- Property prop = new Property();
- prop.Day = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "Day");
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
-
-#if dotnet2
- /// <summary>
- /// Test the setting null on a nullable int property.
- /// </summary>
- [Test]
- public void TestSetNullOnNullableIntProperty()
- {
- Property prop = new Property();
- prop.IntNullable = 85;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "IntNullable");
- propertyAccessor.Set(prop, null);
- Assert.AreEqual(null, prop.IntNullable);
- }
-
- /// <summary>
- /// Test getting an nullable int property.
- /// </summary>
- [Test]
- public void TestGetNullableInt()
- {
- Int32? test = 55;
- Property prop = new Property();
- prop.IntNullable = test;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "IntNullable");
-
- Assert.AreEqual(test, propertyAccessor.Get(prop));
- }
-
- /// <summary>
- /// Test setting an nullable int property.
- /// </summary>
- [Test]
- public void TestSetNullableInt()
- {
- Property prop = new Property();
- prop.IntNullable = 99;
-
- // Property accessor
- MemberAccessorFactory factory = new MemberAccessorFactory(true);
- IMemberAccessor propertyAccessor = factory.CreateMemberAccessor(typeof(Property), "IntNullable");
- Int32? test = 55;
- propertyAccessor.Set(prop, test);
- Assert.AreEqual(test, prop.IntNullable);
-
- }
-#endif
}
}
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.2005.csproj Mon Mar 20 12:46:29 2006
@@ -198,8 +198,10 @@
<Compile Include="Utilities\Objects\FactoryBuilder.cs" />
<Compile Include="Utilities\Objects\IFactory.cs" />
<Compile Include="Utilities\Objects\IObjectFactory.cs" />
+ <Compile Include="Utilities\Objects\Members\BaseEmitAccessor.cs" />
<Compile Include="Utilities\Objects\Members\EmitFieldAccessor.cs" />
- <Compile Include="Utilities\Objects\Members\ILPropertyAccessor.cs" />
+ <Compile Include="Utilities\Objects\Members\EmitPropertyAccessor.cs" />
+ <Compile Include="Utilities\Objects\Members\IEmitPropertyAccessor.cs" />
<Compile Include="Utilities\Objects\Members\IMemberAccessor.cs" />
<Compile Include="Utilities\Objects\Members\MemberAccessorFactory.cs" />
<Compile Include="Utilities\Objects\Members\ReflectionFieldAccessor.cs" />
Modified: ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj?rev=387305&r1=387304&r2=387305&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/IBatisNet.Common.csproj Mon Mar 20 12:46:29 2006
@@ -345,12 +345,22 @@
BuildAction = "Compile"
/>
<File
+ RelPath = "Utilities\Objects\Members\BaseEmitAccessor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
RelPath = "Utilities\Objects\Members\EmitFieldAccessor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Utilities\Objects\Members\EmitPropertyAccessor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Utilities\Objects\Members\IEmitPropertyAccessor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
Added: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs?rev=387305&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs Mon Mar 20 12:46:29 2006
@@ -0,0 +1,178 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: 374175 $
+ * $LastChangedDate$
+ * $LastChangedBy$
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2006/2005 - The Apache Software Foundation
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Reflection.Emit;
+
+namespace IBatisNet.Common.Utilities.Objects.Members
+{
+ /// <summary>
+ ///
+ /// </summary>
+ public abstract class BaseEmitAccessor : IMemberAccessor
+ {
+ /// <summary>
+ /// The class parent type
+ /// </summary>
+ protected Type targetType = null;
+ /// <summary>
+ /// The property/field name
+ /// </summary>
+ protected string memberName = string.Empty;
+ /// <summary>
+ /// The property/field type
+ /// </summary>
+ protected Type memberType = null;
+ /// <summary>
+ /// The IL emitted IMemberAccessor
+ /// </summary>
+ protected IMemberAccessor emittedMemberAccessor = null;
+ /// <summary>
+ /// The AssemblyBuilder use to keep the type
+ /// </summary>
+ protected AssemblyBuilder assemblyBuilder = null;
+ /// <summary>
+ /// The ModuleBuilder use to create the type
+ /// </summary>
+ protected ModuleBuilder moduleBuilder = null;
+ /// <summary>
+ /// The null internal value used by this member type
+ /// </summary>
+ protected object nullInternal = null;
+
+ /// <summary>
+ ///
+ /// </summary>
+ protected static IDictionary typeToOpcode = new HybridDictionary();
+
+ /// <summary>
+ /// Static constructor
+ /// "Initialize a private IDictionary with type-opCode pairs
+ /// </summary>
+ static BaseEmitAccessor()
+ {
+ typeToOpcode[typeof(sbyte)] = OpCodes.Ldind_I1;
+ typeToOpcode[typeof(byte)] = OpCodes.Ldind_U1;
+ typeToOpcode[typeof(char)] = OpCodes.Ldind_U2;
+ typeToOpcode[typeof(short)] = OpCodes.Ldind_I2;
+ typeToOpcode[typeof(ushort)] = OpCodes.Ldind_U2;
+ typeToOpcode[typeof(int)] = OpCodes.Ldind_I4;
+ typeToOpcode[typeof(uint)] = OpCodes.Ldind_U4;
+ typeToOpcode[typeof(long)] = OpCodes.Ldind_I8;
+ typeToOpcode[typeof(ulong)] = OpCodes.Ldind_I8;
+ typeToOpcode[typeof(bool)] = OpCodes.Ldind_I1;
+ typeToOpcode[typeof(double)] = OpCodes.Ldind_R8;
+ typeToOpcode[typeof(float)] = OpCodes.Ldind_R4;
+ }
+
+ /// <summary>
+ /// Get the null value for a given type
+ /// </summary>
+ /// <param name="type"></param>
+ /// <returns></returns>
+ protected object GetNullInternal(Type type)
+ {
+ if (type.IsValueType)
+ {
+ if (type.IsEnum)
+ {
+ return GetNullInternal(Enum.GetUnderlyingType(type));
+ }
+
+ if (type.IsPrimitive)
+ {
+ if (type == typeof(Int32)) { return 0; }
+ if (type == typeof(Double)) { return (Double)0; }
+ if (type == typeof(Int16)) { return (Int16)0; }
+ if (type == typeof(SByte)) { return (SByte)0; }
+ if (type == typeof(Int64)) { return (Int64)0; }
+ if (type == typeof(Byte)) { return (Byte)0; }
+ if (type == typeof(UInt16)) { return (UInt16)0; }
+ if (type == typeof(UInt32)) { return (UInt32)0; }
+ if (type == typeof(UInt64)) { return (UInt64)0; }
+ if (type == typeof(UInt64)) { return (UInt64)0; }
+ if (type == typeof(Single)) { return (Single)0; }
+ if (type == typeof(Boolean)) { return false; }
+ if (type == typeof(char)) { return '\0'; }
+ }
+ else
+ {
+ if (type == typeof(DateTime)) { return DateTime.MinValue; }
+ if (type == typeof(Decimal)) { return 0m; }
+ if (type == typeof(Guid)) { return Guid.Empty; }
+ if (type == typeof(TimeSpan)) { return TimeSpan.MinValue; }
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// This method create a new type oject for the the field accessor class
+ /// that will provide dynamic access.
+ /// </summary>
+ protected void EmitIL()
+ {
+ // Create a new type oject for the the field accessor class.
+ EmitType();
+
+ // Create a new instance
+ emittedMemberAccessor = assemblyBuilder.CreateInstance("MemberAccessorFor" + targetType.FullName + memberName) as IMemberAccessor;
+
+ nullInternal = GetNullInternal(memberType);
+
+ if (emittedMemberAccessor == null)
+ {
+ throw new MethodAccessException(
+ string.Format("Unable to create propert/field accessor for \"{0}\".", memberType));
+ }
+ }
+
+ /// <summary>
+ /// Create an type that will provide the get and set methods.
+ /// </summary>
+ protected abstract void EmitType();
+
+ #region IMemberAccessor Members
+
+ /// <summary>
+ /// Gets the field value from the specified target.
+ /// </summary>
+ /// <param name="target">Target object.</param>
+ /// <returns>Property value.</returns>
+ public abstract object Get(object target);
+
+ /// <summary>
+ /// Sets the field for the specified target.
+ /// </summary>
+ /// <param name="target">Target object.</param>
+ /// <param name="value">Value to set.</param>
+ public abstract void Set(object target, object value);
+
+ #endregion
+ }
+}
Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.Common/Utilities/Objects/Members/BaseEmitAccessor.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy