Skip to content

Commit

Permalink
Implemented a couple of tests that demonstrate NH-2354
Browse files Browse the repository at this point in the history
  • Loading branch information
acutus committed Oct 13, 2012
1 parent 16f53ed commit 7dd96c7
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/NHibernate.Test/NHibernate.Test.csproj
Expand Up @@ -1125,6 +1125,10 @@
<Compile Include="TypesTest\XDocTypeFixture.cs" />
<Compile Include="TypesTest\XmlDocClass.cs" />
<Compile Include="TypesTest\XmlDocTypeFixture.cs" />
<Compile Include="UnionsubclassPolymorphicFormula\Company.cs" />
<Compile Include="UnionsubclassPolymorphicFormula\Party.cs" />
<Compile Include="UnionsubclassPolymorphicFormula\Person.cs" />
<Compile Include="UnionsubclassPolymorphicFormula\UnionSubclassFixture.cs" />
<Compile Include="UtilityTest\IdentitySetFixture.cs" />
<Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" />
<Compile Include="UtilityTest\EnumerableExtensionsTests\FirstExtensionTests.cs" />
Expand Down Expand Up @@ -2915,6 +2919,8 @@
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="hibernate.cfg.xml" />
<EmbeddedResource Include="UnionsubclassPolymorphicFormula\Party.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH3050\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2469\Mappings.hbm.xml" />
<EmbeddedResource Include="NHSpecificTest\NH2033\Mappings.hbm.xml" />
Expand Down
13 changes: 13 additions & 0 deletions src/NHibernate.Test/UnionsubclassPolymorphicFormula/Company.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Test.UnionsubclassPolymorphicFormula
{
public class Company : Party
{
public override string Name { get { return this.CompanyName; } }
public virtual string CompanyName { get; set; }
}
}
13 changes: 13 additions & 0 deletions src/NHibernate.Test/UnionsubclassPolymorphicFormula/Party.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Test.UnionsubclassPolymorphicFormula
{
public abstract class Party
{
public virtual long Id { get; protected internal set; }
public abstract string Name { get; }
}
}
44 changes: 44 additions & 0 deletions src/NHibernate.Test/UnionsubclassPolymorphicFormula/Party.hbm.xml
@@ -0,0 +1,44 @@
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernate.Test"
namespace="NHibernate.Test.UnionsubclassPolymorphicFormula">

<!--
Testing the inheritance of the abstract property "Name"
-->

<!-- PARTY -->

<class xmlns="urn:nhibernate-mapping-2.2" name="Party" table="`party`" abstract="true">
<id access="backfield" name="Id">
<column name="Id" />
<generator class="sequence">
<param name="sequence">party_id_seq</param>
</generator>
</id>

<!-- PERSON -->

<union-subclass name="Person" table="`person`" extends="Party">
<property name="Name" access="readonly" formula="first_name || ' ' || last_name" update="false" insert="false">
</property>
<property name="FirstName">
<column name="first_name" />
</property>
<property name="LastName">
<column name="last_name" />
</property>
</union-subclass>

<!-- COMPANY-->

<union-subclass name="Company" table="`company`" extends="Party">
<property name="Name" access="readonly" update="false" insert="false">
<column name="company_name" />
</property>
<property name="CompanyName">
<column name="company_name" />
</property>
</union-subclass>
</class>

</hibernate-mapping>
14 changes: 14 additions & 0 deletions src/NHibernate.Test/UnionsubclassPolymorphicFormula/Person.cs
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NHibernate.Test.UnionsubclassPolymorphicFormula
{
public class Person : Party
{
public override string Name { get { return this.FirstName + " " + this.LastName; } }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
}
}
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Collections;

namespace NHibernate.Test.UnionsubclassPolymorphicFormula
{
[TestFixture]
public class UnionSubclassFixture : TestCase
{
protected override string MappingsAssembly
{
get { return "NHibernate.Test"; }
}

protected override IList Mappings
{
get { return new string[] { "UnionsubclassPolymorphicFormula.Party.hbm.xml" }; }
}

[Test]
public void QueryOverPersonTest()
{
using (ISession s = OpenSession())
{
using (ITransaction t = s.BeginTransaction())
{
var person = new Person
{
FirstName = "Mark",
LastName = "Mannson"
};

s.Save(person);

var result = s.QueryOver<Party>().Where(p => p.Name == "Mark Mannson").SingleOrDefault();

Assert.NotNull(result);
s.Delete(result);
t.Commit();
}

}
}

[Test]
public void QueryOverCompanyTest()
{
using (ISession s = OpenSession())
{
using (ITransaction t = s.BeginTransaction())
{
var company = new Company
{
CompanyName = "Limited",
};

s.Save(company);

var result = s.QueryOver<Party>().Where(p => p.Name == "Limited").SingleOrDefault();
Assert.NotNull(result);
}

}
}
}
}

0 comments on commit 7dd96c7

Please sign in to comment.