|
From: <fab...@us...> - 2009-05-18 05:31:21
|
Revision: 4336
http://nhibernate.svn.sourceforge.net/nhibernate/?rev=4336&view=rev
Author: fabiomaulo
Date: 2009-05-18 05:31:15 +0000 (Mon, 18 May 2009)
Log Message:
-----------
Test from H3.1 (not supported in .NET so far)
Modified Paths:
--------------
trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
Added Paths:
-----------
trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/
trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employee.cs
trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employment.cs
trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/LazyOneToOneTest.cs
trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.cs
trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.hbm.xml
Added: trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employee.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employee.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employee.cs 2009-05-18 05:31:15 UTC (rev 4336)
@@ -0,0 +1,26 @@
+using System.Collections.Generic;
+
+namespace NHibernate.Test.LazyOneToOne
+{
+ public class Employee
+ {
+ protected Employee()
+ {
+ Employments = new List<Employment>();
+ }
+
+ public Employee(Person person)
+ : this()
+ {
+ Person = person;
+ PersonName = person.Name;
+ Person.Employee = this;
+ }
+
+ public virtual string PersonName { get; protected set; }
+
+ public virtual Person Person { get; protected set; }
+
+ public virtual ICollection<Employment> Employments { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employment.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employment.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Employment.cs 2009-05-18 05:31:15 UTC (rev 4336)
@@ -0,0 +1,50 @@
+using System;
+
+namespace NHibernate.Test.LazyOneToOne
+{
+ public class Employment
+ {
+ protected Employment() { }
+ public Employment(Employee e, String org)
+ {
+ PersonName = e.PersonName;
+ OrganizationName = org;
+ StartDate = DateTime.Today.AddDays(-1);
+ e.Employments.Add(this);
+ }
+
+ public virtual string PersonName { get; protected set; }
+
+ public virtual string OrganizationName { get; protected set; }
+
+ public virtual DateTime? StartDate { get; set; }
+
+ public virtual DateTime? EndDate { get; set; }
+
+ public override bool Equals(object obj)
+ {
+ return Equals(obj as Employment);
+ }
+
+ public virtual bool Equals(Employment other)
+ {
+ if (ReferenceEquals(null, other))
+ {
+ return false;
+ }
+ if (ReferenceEquals(this, other))
+ {
+ return true;
+ }
+ return Equals(other.PersonName, PersonName) && Equals(other.OrganizationName, OrganizationName);
+ }
+
+ public override int GetHashCode()
+ {
+ unchecked
+ {
+ return ((PersonName != null ? PersonName.GetHashCode() : 0) * 397) ^ (OrganizationName != null ? OrganizationName.GetHashCode() : 0);
+ }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/LazyOneToOneTest.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/LazyOneToOneTest.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/LazyOneToOneTest.cs 2009-05-18 05:31:15 UTC (rev 4336)
@@ -0,0 +1,85 @@
+using System;
+using System.Collections;
+using NHibernate.Intercept;
+using NUnit.Framework;
+using Environment = NHibernate.Cfg.Environment;
+
+namespace NHibernate.Test.LazyOneToOne
+{
+ [TestFixture, Ignore("Not supported.")]
+ public class LazyOneToOneTest : TestCase
+ {
+ protected override IList Mappings
+ {
+ get { return new[] {"LazyOneToOne.Person.hbm.xml"}; }
+ }
+
+ protected override string MappingsAssembly
+ {
+ get { return "NHibernate.Test"; }
+ }
+
+ protected override bool AppliesTo(Dialect.Dialect dialect)
+ {
+ // this test work only with Field interception (NH-1618)
+ return FieldInterceptionHelper.IsInstrumented( new Person() );
+ }
+ protected override void Configure(Cfg.Configuration configuration)
+ {
+ cfg.SetProperty(Environment.MaxFetchDepth, "2");
+ cfg.SetProperty(Environment.UseSecondLevelCache, "false");
+ }
+
+ protected override string CacheConcurrencyStrategy
+ {
+ get { return null; }
+ }
+
+ [Test]
+ public void Lazy()
+ {
+ ISession s = OpenSession();
+ ITransaction t = s.BeginTransaction();
+ var p = new Person {Name = "Gavin"};
+ var p2 = new Person {Name = "Emmanuel"};
+ var e = new Employee(p);
+ new Employment(e, "JBoss");
+ var old = new Employment(e, "IFA") {EndDate = DateTime.Today};
+ s.Persist(p);
+ s.Persist(p2);
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ p = s.CreateQuery("from Person where name='Gavin'").UniqueResult<Person>();
+ //Assert.That(!NHibernateUtil.IsPropertyInitialized(p, "Employee"));
+
+ Assert.That(p.Employee.Person, Is.SameAs(p));
+ Assert.That(NHibernateUtil.IsInitialized(p.Employee.Employments));
+ Assert.That(p.Employee.Employments.Count, Is.EqualTo(1));
+
+ p2 = s.CreateQuery("from Person where name='Emmanuel'").UniqueResult<Person>();
+ Assert.That(p2.Employee, Is.Null);
+ t.Commit();
+ s.Close();
+
+ s = OpenSession();
+ t = s.BeginTransaction();
+ p = s.Get<Person>("Gavin");
+ //Assert.That(!NHibernateUtil.IsPropertyInitialized(p, "Employee"));
+
+ Assert.That(p.Employee.Person, Is.SameAs(p));
+ Assert.That(NHibernateUtil.IsInitialized(p.Employee.Employments));
+ Assert.That(p.Employee.Employments.Count, Is.EqualTo(1));
+
+ p2 = s.Get<Person>("Emmanuel");
+ Assert.That(p2.Employee, Is.Null);
+ s.Delete(p2);
+ s.Delete(old);
+ s.Delete(p);
+ t.Commit();
+ s.Close();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.cs
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.cs (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.cs 2009-05-18 05:31:15 UTC (rev 4336)
@@ -0,0 +1,8 @@
+namespace NHibernate.Test.LazyOneToOne
+{
+ public class Person
+ {
+ public virtual string Name { get; set; }
+ public virtual Employee Employee { get; set; }
+ }
+}
\ No newline at end of file
Added: trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.hbm.xml
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.hbm.xml (rev 0)
+++ trunk/nhibernate/src/NHibernate.Test/LazyOneToOne/Person.hbm.xml 2009-05-18 05:31:15 UTC (rev 4336)
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
+ assembly="NHibernate.Test"
+ namespace="NHibernate.Test.LazyOneToOne">
+
+ <class name="Person">
+ <id name="Name"/>
+ <one-to-one name="Employee" lazy="no-proxy" cascade="persist,delete"/>
+ </class>
+
+ <class name="Employee">
+ <id name="PersonName"/>
+ <one-to-one name="Person" lazy="no-proxy"/>
+ <bag name="Employments" inverse="true" fetch="join" lazy="false"
+ where="EndDate is null"
+ cascade="persist,delete">
+ <key column="PersonName"/>
+ <one-to-many class="Employment"/>
+ </bag>
+ </class>
+
+ <class name="Employment">
+ <composite-id>
+ <key-property name="PersonName"/>
+ <key-property name="OrganizationName"/>
+ </composite-id>
+ <property name="StartDate" update="false"/>
+ <property name="EndDate"/>
+ </class>
+
+</hibernate-mapping>
Modified: trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj
===================================================================
--- trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-17 21:30:26 UTC (rev 4335)
+++ trunk/nhibernate/src/NHibernate.Test/NHibernate.Test.csproj 2009-05-18 05:31:15 UTC (rev 4336)
@@ -327,6 +327,10 @@
<Compile Include="HQL\Ast\WithClauseFixture.cs" />
<Compile Include="HQL\Ast\Zoo.cs" />
<Compile Include="HQL\BaseFunctionFixture.cs" />
+ <Compile Include="LazyOneToOne\Employee.cs" />
+ <Compile Include="LazyOneToOne\Employment.cs" />
+ <Compile Include="LazyOneToOne\LazyOneToOneTest.cs" />
+ <Compile Include="LazyOneToOne\Person.cs" />
<Compile Include="MappingTest\NonReflectiveBinderFixture.cs" />
<Compile Include="MappingTest\Wicked.cs" />
<Compile Include="NHSpecificTest\ElementsEnums\AbstractIntEnumsBagFixture.cs" />
@@ -1812,6 +1816,7 @@
<EmbeddedResource Include="BulkManipulation\SimpleClass.hbm.xml" />
<EmbeddedResource Include="Ado\VerySimple.hbm.xml" />
<Content Include="DynamicEntity\package.html" />
+ <EmbeddedResource Include="LazyOneToOne\Person.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1747\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1159\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH1093\Mappings.hbm.xml" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|