Permalink
Browse files

Implemented a couple of tests that demonstrate NH-2354

  • Loading branch information...
1 parent 16f53ed commit 7dd96c74a12322ba2630f2e7d442f85b6670ebb6 @acutus committed Oct 13, 2012
@@ -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" />
@@ -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" />
@@ -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; }
+ }
+}
@@ -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; }
+ }
+}
@@ -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>
@@ -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.