|
From: <fab...@us...> - 2009-05-18 21:23:58
|
Revision: 4338
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4338&view=rev
Author: fabiomaulo
Date: 2009-05-18 21:23:51 +0000 (Mon, 18 May 2009)
Log Message:
-----------
Starting fix of NH-1786
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate/NHibernate.csproj
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate/Bytecode/ActivatorObjectsFactory.cs
trunk/nhibernate/src/NHibernate/Bytecode/IObjectsFactory.cs
trunk/nhibernate/src/NHibernate.Test/Bytecode/ActivatorObjectFactoryFixture.cs
Added: trunk/nhibernate/src/NHibernate/Bytecode/ActivatorObjectsFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Bytecode/ActivatorObjectsFactory.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Bytecode/ActivatorObjectsFactory.cs 2009-05-18 21:23:51 UTC (rev 4338)
@@ -0,0 +1,22 @@
+using System;
+
+namespace NHibernate.Bytecode
+{
+ public class ActivatorObjectsFactory: IObjectsFactory
+ {
+ public object CreateInstance(System.Type type)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object CreateInstance(System.Type type, bool nonPublic)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object CreateInstance(System.Type type, params object[] ctorArgs)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate/Bytecode/IObjectsFactory.cs
===================================================================
--- trunk/nhibernate/src/NHibernate/Bytecode/IObjectsFactory.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate/Bytecode/IObjectsFactory.cs 2009-05-18 21:23:51 UTC (rev 4338)
@@ -0,0 +1,29 @@
+namespace NHibernate.Bytecode
+{
+ public interface IObjectsFactory
+ {
+ /// <summary>
+ /// Creates an instance of the specified type.
+ /// </summary>
+ /// <param name="type">The type of object to create.</param>
+ /// <returns>A reference to the created object.</returns>
+ object CreateInstance(System.Type type);
+
+ /// <summary>
+ /// Creates an instance of the specified type.
+ /// </summary>
+ /// <param name="type">The type of object to create.</param>
+ /// <param name="nonPublic">true if a public or nonpublic default constructor can match; false if only a public default constructor can match.</param>
+ /// <returns>A reference to the created object.</returns>
+ object CreateInstance(System.Type type, bool nonPublic);
+
+ /// <summary>
+ /// Creates an instance of the specified type using the constructor
+ /// that best matches the specified parameters.
+ /// </summary>
+ /// <param name="type">The type of object to create.</param>
+ /// <param name="ctorArgs">An array of constructor arguments.</param>
+ /// <returns>A reference to the created object.</returns>
+ object CreateInstance(System.Type type, params object[] ctorArgs);
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate/NHibernate.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-05-18 19:37:55 UTC (rev 4337)
+++ trunk/nhibernate/src/NHibernate/NHibernate.csproj 2009-05-18 21:23:51 UTC (rev 4338)
@@ -451,7 +451,9 @@
<Compile Include="AdoNet\Util\FormatStyle.cs" />
<Compile Include="AdoNet\Util\IFormatter.cs" />
<Compile Include="AdoNet\Util\SqlStatementLogger.cs" />
+ <Compile Include="Bytecode\ActivatorObjectsFactory.cs" />
<Compile Include="Bytecode\HibernateByteCodeException.cs" />
+ <Compile Include="Bytecode\IObjectsFactory.cs" />
<Compile Include="Bytecode\ProxyFactoryFactoryNotConfiguredException.cs" />
<Compile Include="Bytecode\UnableToLoadProxyFactoryFactoryException.cs" />
<Compile Include="Cache\FakeCache.cs" />
Added: trunk/nhibernate/src/NHibernate.Test/Bytecode/ActivatorObjectFactoryFixture.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/Bytecode/ActivatorObjectFactoryFixture.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/Bytecode/ActivatorObjectFactoryFixture.cs 2009-05-18 21:23:51 UTC (rev 4338)
@@ -0,0 +1,72 @@
+using System;
+using NHibernate.Bytecode;
+using NUnit.Framework;
+
+namespace NHibernate.Test.Bytecode
+{
+ [TestFixture, Ignore("Not implemented yet.")]
+ public class ActivatorObjectFactoryFixture
+ {
+ public class WithOutPublicParameterLessCtor
+ {
+ public string Something { get; set; }
+ protected WithOutPublicParameterLessCtor() { }
+
+ public WithOutPublicParameterLessCtor(string something)
+ {
+ Something = something;
+ }
+ }
+
+ public class PublicParameterLessCtor
+ {
+ }
+
+ public struct ValueType
+ {
+ public string Something { get; set; }
+ }
+
+ [Test]
+ public void CreateInstanceDefCtor()
+ {
+ var of = new ActivatorObjectsFactory();
+ Assert.Throws<ArgumentNullException>(() => of.CreateInstance(null));
+ Assert.Throws<ArgumentNullException>(() => of.CreateInstance(typeof(WithOutPublicParameterLessCtor)));
+ var instance = of.CreateInstance(typeof(PublicParameterLessCtor));
+ Assert.That(instance, Is.Not.Null);
+ Assert.That(instance, Is.InstanceOf<PublicParameterLessCtor>());
+ }
+
+ [Test]
+ public void CreateInstanceWithNoPublicCtor()
+ {
+ var of = new ActivatorObjectsFactory();
+ Assert.Throws<ArgumentNullException>(() => of.CreateInstance(null, false));
+ var instance = of.CreateInstance(typeof(WithOutPublicParameterLessCtor), true);
+ Assert.That(instance, Is.Not.Null);
+ Assert.That(instance, Is.InstanceOf<WithOutPublicParameterLessCtor>());
+ }
+
+ [Test]
+ public void CreateInstanceOfValueType()
+ {
+ var of = new ActivatorObjectsFactory();
+ var instance = of.CreateInstance(typeof(ValueType), true);
+ Assert.That(instance, Is.Not.Null);
+ Assert.That(instance, Is.InstanceOf<ValueType>());
+ }
+
+ [Test]
+ public void CreateInstanceWithArguments()
+ {
+ var of = new ActivatorObjectsFactory();
+ Assert.Throws<ArgumentNullException>(() => of.CreateInstance(null, new[] {1}));
+ var value = "a value";
+ var instance = of.CreateInstance(typeof(WithOutPublicParameterLessCtor), new[]{value});
+ Assert.That(instance, Is.Not.Null);
+ Assert.That(instance, Is.InstanceOf<WithOutPublicParameterLessCtor>());
+ Assert.That(((WithOutPublicParameterLessCtor)instance).Something, Is.EqualTo(value));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-18 19:37:55 UTC (rev 4337)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-18 21:23:51 UTC (rev 4338)
@@ -88,6 +88,7 @@
<Compile Include="BulkManipulation\BaseFixture.cs" />
<Compile Include="BulkManipulation\HQLBulkOperations.cs" />
<Compile Include="BulkManipulation\SimpleClass.cs" />
+ <Compile Include="Bytecode\ActivatorObjectFactoryFixture.cs" />
<Compile Include="Bytecode\Lightweight\BytecodeProviderFixture.cs" />
<Compile Include="Bytecode\WrongProxyFactoryFactory.cs" />
<Compile Include="CacheTest\CacheFixture.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|