Skip to content

Commit 1a49378

Browse files
acutushazzik
authored andcommitted
Implemented a couple of tests that demonstrate NH-2354
1 parent 12e8615 commit 1a49378

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,10 @@
12301230
<Compile Include="Unionsubclass\DatabaseKeywordBase.cs" />
12311231
<Compile Include="Unionsubclass\DatabaseKeywordsFixture.cs" />
12321232
<Compile Include="UtilityTest\ArrayHelperTests.cs" />
1233+
<Compile Include="UnionsubclassPolymorphicFormula\Company.cs" />
1234+
<Compile Include="UnionsubclassPolymorphicFormula\Party.cs" />
1235+
<Compile Include="UnionsubclassPolymorphicFormula\Person.cs" />
1236+
<Compile Include="UnionsubclassPolymorphicFormula\UnionSubclassFixture.cs" />
12331237
<Compile Include="UtilityTest\IdentitySetFixture.cs" />
12341238
<Compile Include="UtilityTest\EnumerableExtensionsTests\AnyExtensionTests.cs" />
12351239
<Compile Include="UtilityTest\EnumerableExtensionsTests\FirstExtensionTests.cs" />
@@ -3048,6 +3052,7 @@
30483052
<EmbeddedResource Include="NHSpecificTest\NH3332\Mappings.hbm.xml">
30493053
<SubType>Designer</SubType>
30503054
</EmbeddedResource>
3055+
<EmbeddedResource Include="UnionsubclassPolymorphicFormula\Party.hbm.xml" />
30513056
<EmbeddedResource Include="NHSpecificTest\NH3050\Mappings.hbm.xml" />
30523057
<EmbeddedResource Include="NHSpecificTest\NH2469\Mappings.hbm.xml" />
30533058
<EmbeddedResource Include="NHSpecificTest\NH2033\Mappings.hbm.xml" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
7+
{
8+
public class Company : Party
9+
{
10+
public override string Name { get { return this.CompanyName; } }
11+
public virtual string CompanyName { get; set; }
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
7+
{
8+
public abstract class Party
9+
{
10+
public virtual long Id { get; protected internal set; }
11+
public abstract string Name { get; }
12+
}
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
2+
assembly="NHibernate.Test"
3+
namespace="NHibernate.Test.UnionsubclassPolymorphicFormula">
4+
5+
<!--
6+
Testing the inheritance of the abstract property "Name"
7+
-->
8+
9+
<!-- PARTY -->
10+
11+
<class xmlns="urn:nhibernate-mapping-2.2" name="Party" table="`party`" abstract="true">
12+
<id access="backfield" name="Id">
13+
<column name="Id" />
14+
<generator class="sequence">
15+
<param name="sequence">party_id_seq</param>
16+
</generator>
17+
</id>
18+
19+
<!-- PERSON -->
20+
21+
<union-subclass name="Person" table="`person`" extends="Party">
22+
<property name="Name" access="readonly" formula="first_name || ' ' || last_name" update="false" insert="false">
23+
</property>
24+
<property name="FirstName">
25+
<column name="first_name" />
26+
</property>
27+
<property name="LastName">
28+
<column name="last_name" />
29+
</property>
30+
</union-subclass>
31+
32+
<!-- COMPANY-->
33+
34+
<union-subclass name="Company" table="`company`" extends="Party">
35+
<property name="Name" access="readonly" update="false" insert="false">
36+
<column name="company_name" />
37+
</property>
38+
<property name="CompanyName">
39+
<column name="company_name" />
40+
</property>
41+
</union-subclass>
42+
</class>
43+
44+
</hibernate-mapping>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
7+
{
8+
public class Person : Party
9+
{
10+
public override string Name { get { return this.FirstName + " " + this.LastName; } }
11+
public virtual string FirstName { get; set; }
12+
public virtual string LastName { get; set; }
13+
}
14+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using System.Collections;
7+
8+
namespace NHibernate.Test.UnionsubclassPolymorphicFormula
9+
{
10+
[TestFixture]
11+
public class UnionSubclassFixture : TestCase
12+
{
13+
protected override string MappingsAssembly
14+
{
15+
get { return "NHibernate.Test"; }
16+
}
17+
18+
protected override IList Mappings
19+
{
20+
get { return new string[] { "UnionsubclassPolymorphicFormula.Party.hbm.xml" }; }
21+
}
22+
23+
[Test]
24+
public void QueryOverPersonTest()
25+
{
26+
using (ISession s = OpenSession())
27+
{
28+
using (ITransaction t = s.BeginTransaction())
29+
{
30+
var person = new Person
31+
{
32+
FirstName = "Mark",
33+
LastName = "Mannson"
34+
};
35+
36+
s.Save(person);
37+
38+
var result = s.QueryOver<Party>().Where(p => p.Name == "Mark Mannson").SingleOrDefault();
39+
40+
Assert.NotNull(result);
41+
s.Delete(result);
42+
t.Commit();
43+
}
44+
45+
}
46+
}
47+
48+
[Test]
49+
public void QueryOverCompanyTest()
50+
{
51+
using (ISession s = OpenSession())
52+
{
53+
using (ITransaction t = s.BeginTransaction())
54+
{
55+
var company = new Company
56+
{
57+
CompanyName = "Limited",
58+
};
59+
60+
s.Save(company);
61+
62+
var result = s.QueryOver<Party>().Where(p => p.Name == "Limited").SingleOrDefault();
63+
Assert.NotNull(result);
64+
}
65+
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)