Skip to content

Commit 81efb59

Browse files
committed
Add test
1 parent c79ea1f commit 81efb59

File tree

13 files changed

+331
-0
lines changed

13 files changed

+331
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public class Change : DataRecord
4+
{
5+
public Change()
6+
{
7+
Type = DataRecordType.Change;
8+
}
9+
10+
public virtual DataChangeState State { get; set; }
11+
12+
public virtual string ExecutedBy { get; set; }
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public enum ChangeInternalState { New, Completed }
4+
5+
public class DataChangeState : DataState
6+
{
7+
public DataChangeState()
8+
{
9+
Type = DataRecordType.Change;
10+
}
11+
12+
public virtual ChangeInternalState State { get; set; }
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public enum IncidentInternalState { New, Assigned, Closed, Solved }
4+
5+
public class DataIncidentState : DataState
6+
{
7+
public DataIncidentState()
8+
{
9+
Type = DataRecordType.Incident;
10+
}
11+
12+
public virtual IncidentInternalState State { get; set; }
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public enum ProblemInternalState { New, Closed }
4+
5+
public class DataProblemState : DataState
6+
{
7+
public DataProblemState()
8+
{
9+
Type = DataRecordType.Problem;
10+
}
11+
12+
public virtual ProblemInternalState State { get; set; }
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Diagnostics;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3972
4+
{
5+
public enum DataRecordType
6+
{
7+
Incident,
8+
Problem,
9+
RequestForChange,
10+
Change
11+
}
12+
13+
[DebuggerDisplay("{Subject}")]
14+
public class DataRecord : Entity
15+
{
16+
public virtual DataRecordType Type { get; set; }
17+
public virtual string Subject { get; set; }
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public enum RequestForChangeInternalState { New, Orded, Closed, Cancelled }
4+
5+
public class DataRequestForChangeState : DataState
6+
{
7+
public DataRequestForChangeState()
8+
{
9+
Type = DataRecordType.RequestForChange;
10+
}
11+
12+
public virtual RequestForChangeInternalState State { get; set; }
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Diagnostics;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3972
4+
{
5+
[DebuggerDisplay("{Description}")]
6+
public class DataState : Entity
7+
{
8+
public virtual DataRecordType Type { get; set; }
9+
public virtual string Description { get; set; }
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3972
4+
{
5+
public class Entity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual int Version { get; set; }
9+
}
10+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using System.Linq;
3+
using NHibernate.Linq;
4+
using NUnit.Framework;
5+
using static NUnit.Framework.Assert;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH3972
8+
{
9+
[TestFixture]
10+
public class Fixture : BugTestCase
11+
{
12+
private DataChangeState changeState = null;
13+
private DataRequestForChangeState rfcState = null;
14+
private DataIncidentState incidentState = null;
15+
private DataProblemState problemState = null;
16+
17+
protected override void OnSetUp()
18+
{
19+
using (var session = OpenSession())
20+
using (var transaction = session.BeginTransaction())
21+
{
22+
foreach (ChangeInternalState state in Enum.GetValues(typeof(ChangeInternalState)))
23+
{
24+
changeState = new DataChangeState { State = state, Description = Enum.GetName(typeof(ChangeInternalState), state) };
25+
session.Save(changeState);
26+
}
27+
28+
foreach (RequestForChangeInternalState state in Enum.GetValues(typeof(RequestForChangeInternalState)))
29+
{
30+
rfcState = new DataRequestForChangeState { State = state, Description = Enum.GetName(typeof(RequestForChangeInternalState), state) };
31+
session.Save(rfcState);
32+
}
33+
34+
foreach (IncidentInternalState state in Enum.GetValues(typeof(IncidentInternalState)))
35+
{
36+
incidentState = new DataIncidentState { State = state, Description = Enum.GetName(typeof(IncidentInternalState), state) };
37+
session.Save(incidentState);
38+
}
39+
40+
foreach (ProblemInternalState state in Enum.GetValues(typeof(ProblemInternalState)))
41+
{
42+
problemState = new DataProblemState { State = state, Description = Enum.GetName(typeof(ProblemInternalState), state) };
43+
session.Save(problemState);
44+
}
45+
46+
session.Save(new RequestForChange { Subject = "I have a request", State = rfcState });
47+
session.Save(new Change { Subject = "I have changed the following stuff", State = changeState, ExecutedBy = "Me" });
48+
session.Save(new Incident { Subject = "Can someone look for this", State = incidentState, ReportedBy = "Someone" });
49+
session.Save(new Problem { Subject = "We have a problem", State = problemState });
50+
51+
session.Flush();
52+
transaction.Commit();
53+
}
54+
}
55+
56+
protected override void OnTearDown()
57+
{
58+
using (var session = OpenSession())
59+
using (var transaction = session.BeginTransaction())
60+
{
61+
session.Delete("from System.Object");
62+
63+
session.Flush();
64+
transaction.Commit();
65+
}
66+
}
67+
68+
[Test]
69+
public void QueryingAll()
70+
{
71+
using (var session = OpenSession())
72+
using (session.BeginTransaction())
73+
{
74+
var result = session.Query<DataRecord>().ToArray();
75+
That(result.Length, Is.EqualTo(4));
76+
}
77+
}
78+
79+
[Test]
80+
public void QueryingSubPropertiesWithDifferentNames()
81+
{
82+
using (var session = OpenSession())
83+
using (session.BeginTransaction())
84+
{
85+
var result = session.Query<DataRecord>().Select(x => new
86+
{
87+
x.Subject,
88+
((Incident)x).ReportedBy,
89+
((Change)x).ExecutedBy
90+
}).ToArray();
91+
That(result.Length, Is.EqualTo(4));
92+
That(result.Count(x => x.ReportedBy == "Someone") == 1, Is.True); // there is one entity with a set ReportedBy column, i.e. the entity of type "Incident"
93+
That(result.Count(x => x.ExecutedBy == "Me") == 1, Is.True); // there is one entity with a set ExecutedBy column, i.e. the entity of type "Change"
94+
}
95+
}
96+
97+
[Test]
98+
public void QueryingSubPropertiesWithTheSameNames()
99+
{
100+
using (var session = OpenSession())
101+
using (session.BeginTransaction())
102+
{
103+
var result = session.Query<DataRecord>().Select(x => new
104+
{
105+
x.Subject,
106+
State = ((Incident)x).State.Description,
107+
}).ToArray();
108+
That(result.Length, Is.EqualTo(4));
109+
That(result.Count(x => x.State == incidentState.Description) == 1, Is.True); // there is only one "Incident" entity
110+
}
111+
}
112+
}
113+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public class Incident : DataRecord
4+
{
5+
public Incident()
6+
{
7+
Type = DataRecordType.Incident;
8+
}
9+
10+
public virtual DataIncidentState State { get; set; }
11+
12+
public virtual string ReportedBy { get; set; }
13+
}
14+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test"
4+
namespace="NHibernate.Test.NHSpecificTest.NH3972">
5+
6+
<class name="DataRecord" table="DataRecords" abstract="false"
7+
discriminator-value="not null">
8+
<id name="Id" generator="guid.comb" />
9+
<discriminator column="Type" insert="false" type="int" />
10+
<version name="Version" column="Version" />
11+
12+
<property name="Type" column="Type" not-null="false" />
13+
<property name="Subject" column="Subject" not-null="false" />
14+
15+
<joined-subclass name="NHibernate.Test.NHSpecificTest.NH3972.Incident" table="Incidents">
16+
<key column="DataRecordId" />
17+
<many-to-one name="State" column="StateDataIncidentStateId" fetch="select" cascade="none"
18+
class="NHibernate.Test.NHSpecificTest.NH3972.DataIncidentState" not-null="false" />
19+
<property name="ReportedBy" column="ReportedBy" not-null="false" />
20+
</joined-subclass>
21+
22+
<joined-subclass name="NHibernate.Test.NHSpecificTest.NH3972.Problem" table="Problems">
23+
<key column="DataRecordId" />
24+
<many-to-one name="State" column="StateDataProblemStateId" fetch="select"
25+
cascade="none" class="NHibernate.Test.NHSpecificTest.NH3972.DataProblemState"
26+
not-null="false" />
27+
</joined-subclass>
28+
29+
<joined-subclass name="NHibernate.Test.NHSpecificTest.NH3972.RequestForChange" table="RequestForChanges">
30+
<key column="DataRecordId" />
31+
<many-to-one name="State" column="StateDataRequestForChangeStateId" fetch="select"
32+
cascade="none" class="NHibernate.Test.NHSpecificTest.NH3972.DataRequestForChangeState"
33+
not-null="false" />
34+
</joined-subclass>
35+
36+
<joined-subclass name="NHibernate.Test.NHSpecificTest.NH3972.Change" table="Changes">
37+
<key column="DataRecordId" />
38+
<many-to-one name="State" column="StateDataChangeStateId" fetch="select"
39+
cascade="none" class="NHibernate.Test.NHSpecificTest.NH3972.DataChangeState"
40+
not-null="false" />
41+
<property name="ExecutedBy" column="ExecutedBy" not-null="false" />
42+
</joined-subclass>
43+
</class>
44+
45+
<class name="DataState" table="DataStates" abstract="false" discriminator-value="not null">
46+
<id name="Id" generator="guid.comb" />
47+
<discriminator column="Type" insert="false" type="int" />
48+
<version name="Version" column="Version" />
49+
50+
<property name="Type" column="Type" not-null="false" />
51+
<property name="Description" column="Description" not-null="false" />
52+
53+
<subclass name="NHibernate.Test.NHSpecificTest.NH3972.DataIncidentState" discriminator-value="0">
54+
<property name="State" column="State" not-null="false" />
55+
</subclass>
56+
57+
<subclass name="NHibernate.Test.NHSpecificTest.NH3972.DataProblemState" discriminator-value="1">
58+
<property name="State" column="State" not-null="false" />
59+
</subclass>
60+
61+
<subclass name="NHibernate.Test.NHSpecificTest.NH3972.DataRequestForChangeState"
62+
discriminator-value="2">
63+
<property name="State" column="State" not-null="false" />
64+
</subclass>
65+
66+
<subclass name="NHibernate.Test.NHSpecificTest.NH3972.DataChangeState" discriminator-value="3">
67+
<property name="State" column="State" not-null="false" />
68+
</subclass>
69+
</class>
70+
</hibernate-mapping>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public class Problem : DataRecord
4+
{
5+
public Problem()
6+
{
7+
Type = DataRecordType.Problem;
8+
}
9+
10+
public virtual DataProblemState State { get; set; }
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace NHibernate.Test.NHSpecificTest.NH3972
2+
{
3+
public class RequestForChange : DataRecord
4+
{
5+
public RequestForChange()
6+
{
7+
Type = DataRecordType.RequestForChange;
8+
}
9+
10+
public virtual DataRequestForChangeState State { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)