Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/ProxyTest
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15832/NHibernate.Test/ProxyTest
Added Files:
AProxy.cs AProxy.hbm.xml NHibernateProxyHelperFixture.cs
Log Message:
Modified JoinedSubclass tests to work with Proxies.
Added another test to make sure NHibernateProxyHelper is working.
--- NEW FILE: AProxy.hbm.xml ---
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class
name="NHibernate.Test.ProxyTest.AProxy, NHibernate.Test"
table="aproxy"
proxy="NHibernate.Test.ProxyTest.AProxy, NHibernate.Test"
>
<id name="Id" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name" />
</class>
</hibernate-mapping>
--- NEW FILE: AProxy.cs ---
using System;
namespace NHibernate.Test.ProxyTest
{
/// <summary>
/// Summary description for AProxy.
/// </summary>
public class AProxy
{
int _id;
string _name;
public AProxy()
{
}
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
public virtual string Name
{
get { return _name; }
set { _name = value; }
}
}
}
--- NEW FILE: NHibernateProxyHelperFixture.cs ---
using System;
using NHibernate.Proxy;
using NUnit.Framework;
namespace NHibernate.Test.ProxyTest
{
/// <summary>
/// Summary description for NHibernateProxyHelperFixture.
/// </summary>
[TestFixture]
public class NHibernateProxyHelperFixture : TestCase
{
#region NUnit.Framework.TestFixture Members
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
ExportSchema( new string[] { "ProxyTest.AProxy.hbm.xml"}, true, "NHibernate.Test" );
}
[SetUp]
public void SetUp()
{
// there are test in here where we don't need to resetup the
// tables - so only set the tables up once
}
[TearDown]
public override void TearDown()
{
// do nothing except not let the base TearDown get called
}
[TestFixtureTearDown]
public void TestFixtureTearDown()
{
base.TearDown();
}
#endregion
[Test]
public void GetClassOfProxy()
{
ISession s = null;
AProxy a = new AProxy();
try
{
s = sessions.OpenSession();
a.Name = "a proxy";
s.Save( a );
s.Flush();
}
finally
{
if( s!=null )
{
s.Close();
}
}
try
{
s = sessions.OpenSession();
System.Type type = NHibernateProxyHelper.GetClass( a );
Assert.AreEqual( typeof(AProxy), type, "Should have returned 'A' for a non-proxy" );
AProxy aProxied = (AProxy)s.Load( typeof(AProxy), a.Id );
Assert.IsFalse( NHibernate.IsInitialized( aProxied ), "should be a proxy" );
type = NHibernateProxyHelper.GetClass( aProxied );
Assert.AreEqual( typeof(AProxy), type, "even though aProxied was a Proxy it should have returned the correct type." );
s.Delete( aProxied );
s.Flush();
}
finally
{
if( s!=null )
{
s.Close();
}
}
}
}
}
|