Skip to content

Commit 698b567

Browse files
committed
NH-2439 - Add tests
1 parent 26f8f96 commit 698b567

File tree

7 files changed

+188
-0
lines changed

7 files changed

+188
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH2439">
3+
<class name="Organisation" abstract ="false" table="tblTrnOrganisation">
4+
<id name="OrganisationId">
5+
<generator class="guid"></generator>
6+
</id>
7+
8+
9+
</class>
10+
11+
12+
<class name="TrainingComponent" abstract="true" table="tblTrnNrt">
13+
<id name ="Id" column="NrtId">
14+
<generator class="guid"></generator>
15+
</id>
16+
<!--discriminator column="NrtObjectTypeId" type="int" /-->
17+
18+
<property name="Code" column="NationalCode" length="12"></property>
19+
<property name="Title" column="NationalTitle" length="200"></property>
20+
</class>
21+
22+
23+
<class name="RtoScope" table="tblTrnRtoScope" dynamic-insert="true" dynamic-update="true" >
24+
<id name="Id" column="RtoScopeId">
25+
<generator class="guid"></generator>
26+
</id>
27+
28+
<many-to-one column="OrganisationId" class="Organisation" name="Rto" not-null="true"/>
29+
<many-to-one column="NrtId" class="TrainingComponent" name="Nrt" not-null="true" fetch="join"/>
30+
31+
<property name="StartDate" column="ScopeStartDate" not-null="true"/>
32+
<property name="EndDate" column="ScopeEndDate"/>
33+
34+
<property name="IsRefused" column="IsRefused" not-null="true"/>
35+
</class>
36+
37+
<class name="OrganisationSearchResult" table="uvwOrganisationSearch">
38+
<id name="Id">
39+
<generator class="guid"></generator>
40+
</id>
41+
42+
<many-to-one name="Organisation" column="OrganisationId" lazy="no-proxy" />
43+
</class>
44+
</hibernate-mapping>
45+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Linq;
3+
using NHibernate.Cfg;
4+
using NHibernate.Linq;
5+
using NUnit.Framework;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH2439
8+
{
9+
[TestFixture]
10+
public class NH2439Fixture : BugTestCase
11+
{
12+
protected override void Configure(Configuration configuration)
13+
{
14+
base.Configure(configuration);
15+
configuration.SetProperty(Cfg.Environment.ShowSql, "true");
16+
}
17+
18+
protected override void OnSetUp()
19+
{
20+
using (var session = OpenSession())
21+
{
22+
var organisation = new Organisation();
23+
var trainingComponent = new TrainingComponent {Code = "123", Title = "title"};
24+
var scope = new RtoScope
25+
{
26+
Nrt = trainingComponent,
27+
Rto = organisation,
28+
StartDate = DateTime.Today.AddDays(-100)
29+
};
30+
31+
session.Save(organisation);
32+
session.Save(trainingComponent);
33+
session.Save(scope);
34+
35+
var searchResult = new OrganisationSearchResult {Organisation = organisation};
36+
session.Save(searchResult);
37+
session.Flush();
38+
}
39+
base.OnSetUp();
40+
}
41+
42+
protected override void OnTearDown()
43+
{
44+
using (var session = OpenSession())
45+
{
46+
session.Delete("from OrganisationSearchResult");
47+
session.Delete("from RtoScope");
48+
session.Delete("from Organisation");
49+
session.Delete("from TrainingComponent");
50+
session.Flush();
51+
}
52+
}
53+
54+
[Test]
55+
public void TheTest()
56+
{
57+
using (var session = OpenSession())
58+
{
59+
const string filter = "ABC";
60+
61+
var scopes = session.Query<RtoScope>()
62+
.Where(s => s.StartDate <= DateTime.Today && (s.EndDate == null || s.EndDate >= DateTime.Today) && !s.IsRefused)
63+
.Where(t => t.Nrt.Title.Contains(filter) || t.Nrt.Code == filter);
64+
65+
var query = session.Query<OrganisationSearchResult>();
66+
var finalQuery = query.Where(r => scopes.Any(s => s.Rto == r.Organisation));
67+
var organisations = scopes.Select(s => s.Rto);
68+
69+
var rtoScopes = scopes.ToList();
70+
var organisations1 = organisations.ToList();
71+
72+
Assert.That(rtoScopes.Count == 0);
73+
Assert.That(organisations1.Count == 0);
74+
75+
//the SQL in below fails - the organisations part of the query is not included at all..
76+
var organisationSearchResults = query
77+
.Where(r => organisations.Contains(r.Organisation))
78+
.ToList();
79+
80+
Assert.That(organisationSearchResults.Count == 0);
81+
82+
var list = finalQuery.ToList();
83+
Assert.That(list.Count == 0);
84+
}
85+
}
86+
}
87+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH2439
4+
{
5+
public class Organisation
6+
{
7+
public virtual Guid OrganisationId { get; set; }
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH2439
4+
{
5+
public class OrganisationSearchResult
6+
{
7+
protected virtual Guid Id { get; set; }
8+
9+
public virtual Organisation Organisation { get; set; }
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH2439
4+
{
5+
public class RtoScope
6+
{
7+
public virtual Guid Id { get; set; }
8+
9+
public virtual Organisation Rto { get; set; }
10+
11+
public virtual TrainingComponent Nrt { get; set; }
12+
13+
public virtual DateTime StartDate { get; set; }
14+
15+
public virtual DateTime? EndDate { get; set; }
16+
17+
public virtual bool IsRefused { get; set; }
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH2439
4+
{
5+
public class TrainingComponent
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Code { get; set; }
9+
public virtual string Title { get; set; }
10+
}
11+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,11 @@
806806
<Compile Include="NHSpecificTest\NH2808\Model.cs" />
807807
<Compile Include="NHSpecificTest\NH2812\Entities.cs" />
808808
<Compile Include="NHSpecificTest\NH2812\Fixture.cs" />
809+
<Compile Include="NHSpecificTest\NH2439\NH2439Fixture.cs" />
810+
<Compile Include="NHSpecificTest\NH2439\Organisation.cs" />
811+
<Compile Include="NHSpecificTest\NH2439\OrganisationSearchResult.cs" />
812+
<Compile Include="NHSpecificTest\NH2439\RtoScope.cs" />
813+
<Compile Include="NHSpecificTest\NH2439\TrainingComponent.cs" />
809814
<Compile Include="NHSpecificTest\NH2880\Fixture.cs" />
810815
<Compile Include="NHSpecificTest\NH2880\Model.cs" />
811816
<Compile Include="NHSpecificTest\NH2500\Fixture.cs" />
@@ -3064,6 +3069,7 @@
30643069
<Compile Include="IdGen\Enhanced\Forcedtable\HiLoForcedTableSequenceTest.cs" />
30653070
<Compile Include="IdGen\Enhanced\Forcedtable\PooledForcedTableSequenceTest.cs" />
30663071
<EmbeddedResource Include="NHSpecificTest\NH3010\Mappings.hbm.xml" />
3072+
<EmbeddedResource Include="NHSpecificTest\NH2439\Mappings.hbm.xml" />
30673073
<EmbeddedResource Include="MappingByCode\IntegrationTests\NH2825\Mappings.hbm.xml" />
30683074
<EmbeddedResource Include="NHSpecificTest\NH2880\Mappings.hbm.xml" />
30693075
<EmbeddedResource Include="NHSpecificTest\NH2982\Mappings.hbm.xml" />

0 commit comments

Comments
 (0)