-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d7abf7
commit 071923a
Showing
2 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
src/NHibernate.Test/Async/NHSpecificTest/GH3363/FixtureByCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Linq; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.DomainModel; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3363 | ||
{ | ||
using System.Threading.Tasks; | ||
/// <summary> | ||
/// Fixture using 'by code' mappings | ||
/// </summary> | ||
/// <remarks> | ||
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entities" /> mapping is performed | ||
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach | ||
/// if you prefer. | ||
/// </remarks> | ||
[TestFixture] | ||
public class ByCodeFixtureAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
|
||
mapper.Class<Mother>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); | ||
rc.Property(x => x.Name); | ||
rc.Discriminator(x => x.Column("kind")); | ||
}); | ||
mapper.Subclass<Child1>(rc => | ||
{ | ||
rc.Property(x => x.Name); | ||
rc.ManyToOne(x => x.Thing, m =>{ | ||
m.NotFound(NotFoundMode.Ignore); | ||
m.Column("thingId"); | ||
}); | ||
rc.DiscriminatorValue(1); | ||
}); | ||
mapper.Subclass<Child2>(rc => | ||
{ | ||
rc.Property(x => x.Name); | ||
rc.ManyToOne(x => x.Thing, m => { | ||
m.NotFound(NotFoundMode.Ignore); | ||
m.Column("thingId"); | ||
}); | ||
rc.DiscriminatorValue(2); | ||
}); | ||
mapper.Class<Thing1>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned)); | ||
rc.Property(x => x.Name); | ||
|
||
}); | ||
mapper.Class<Thing2>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned)); | ||
rc.Property(x => x.Name); | ||
|
||
}); | ||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var t1 = new Thing1() { Name = "don't care",Id="00001" }; | ||
session.Save(t1); | ||
var t2 = new Thing2() { Name = "look for this",Id="00002" }; | ||
session.Save(t2); | ||
var child1 = new Child1 { Name = "Child1",Thing=t1 }; | ||
session.Save(child1); | ||
var child2 = new Child2 { Name = "Child1", Thing = t2 }; | ||
session.Save(child2); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// The HQL delete does all the job inside the database without loading the entities, but it does | ||
// not handle delete order for avoiding violating constraints if any. Use | ||
// session.Delete("from System.Object"); | ||
// instead if in need of having NHbernate ordering the deletes, but this will cause | ||
// loading the entities in the session. | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task LookForThingOfTypeThing1Async() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
/* | ||
* wrong statement created | ||
* select mother0_.Id as id1_0_, mother0_.Name as name3_0_, | ||
mother0_.thingId as thingid4_0_, mother0_.kind as kind2_0_ from Mother mother0_ | ||
left outer join Thing2 thing2x1_ on | ||
mother0_.thingId=thing2x1_.Id where mother0_.kind='1' and thing2x1_.Id=?" | ||
* | ||
*/ | ||
|
||
var result = await (session.Query<Mother>().Where(k => k is Child1 && (k as Child1).Thing.Id == "00001").ToListAsync()); | ||
|
||
Assert.That(result, Has.Count.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
} | ||
|
||
} |
158 changes: 158 additions & 0 deletions
158
src/NHibernate.Test/Async/NHSpecificTest/NH3363/FixtureByCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Linq; | ||
using NHibernate.Cfg.MappingSchema; | ||
using NHibernate.DomainModel; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
using NHibernate.Linq; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH3363 | ||
{ | ||
using System.Threading.Tasks; | ||
/// <summary> | ||
/// Fixture using 'by code' mappings | ||
/// </summary> | ||
/// <remarks> | ||
/// This fixture is identical to <see cref="Fixture" /> except the <see cref="Entities" /> mapping is performed | ||
/// by code in the GetMappings method, and does not require the <c>Mappings.hbm.xml</c> file. Use this approach | ||
/// if you prefer. | ||
/// </remarks> | ||
[TestFixture] | ||
public class ByCodeFixtureAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
|
||
mapper.Class<Mother>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); | ||
rc.Property(x => x.Name); | ||
rc.Discriminator(x => x.Column("kind")); | ||
}); | ||
mapper.Subclass<Child1>(rc => | ||
{ | ||
rc.Property(x => x.Name); | ||
rc.ManyToOne(x => x.Thing, m =>{ | ||
m.NotFound(NotFoundMode.Ignore); | ||
m.Column("thingId"); | ||
}); | ||
rc.DiscriminatorValue(1); | ||
}); | ||
mapper.Subclass<Child2>(rc => | ||
{ | ||
rc.Property(x => x.Name); | ||
rc.ManyToOne(x => x.Thing, m => { | ||
m.NotFound(NotFoundMode.Ignore); | ||
m.Column("thingId"); | ||
}); | ||
rc.DiscriminatorValue(2); | ||
}); | ||
mapper.Class<Thing1>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned)); | ||
rc.Property(x => x.Name); | ||
|
||
}); | ||
mapper.Class<Thing2>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.Assigned)); | ||
rc.Property(x => x.Name); | ||
|
||
}); | ||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var t1 = new Thing1() { Name = "don't care",Id="00001" }; | ||
session.Save(t1); | ||
var t2 = new Thing2() { Name = "look for this",Id="00002" }; | ||
session.Save(t2); | ||
var child1 = new Child1 { Name = "Child1",Thing=t1 }; | ||
session.Save(child1); | ||
var child2 = new Child2 { Name = "Child1", Thing = t2 }; | ||
session.Save(child2); | ||
transaction.Commit(); | ||
} | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
// The HQL delete does all the job inside the database without loading the entities, but it does | ||
// not handle delete order for avoiding violating constraints if any. Use | ||
// session.Delete("from System.Object"); | ||
// instead if in need of having NHbernate ordering the deletes, but this will cause | ||
// loading the entities in the session. | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task LookForThingOfTypeThing2Async() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var result = await (session.Query<Mother>().Where(k=>k is Child2 && (k as Child2).Thing.Id == "00002").ToListAsync()); | ||
|
||
Assert.That(result, Has.Count.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
[Test] | ||
public async Task LookForThingOfTypeThing1Async() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var oftype = await (session.Query<Mother>().Where(k => k is Child1).ToListAsync()); | ||
Assert.That(oftype, Has.Count.EqualTo(1)); | ||
Assert.That((oftype[0] as Child1).Thing, Is.Not.Null); | ||
/* | ||
* wrong statement created | ||
* select mother0_.Id as id1_0_, mother0_.Name as name3_0_, | ||
mother0_.thingId as thingid4_0_, mother0_.kind as kind2_0_ from Mother mother0_ | ||
left outer join Thing2 thing2x1_ on | ||
mother0_.thingId=thing2x1_.Id where mother0_.kind='1' and thing2x1_.Id=?" | ||
* | ||
*/ | ||
|
||
var result = await (session.Query<Mother>().Where(k => k is Child1 && (k as Child1).Thing.Id == "00001").ToListAsync()); | ||
|
||
Assert.That(result, Has.Count.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
[Test] | ||
public async Task LookForManyToOneByDescrAsync() | ||
{ | ||
using (var session = OpenSession()) | ||
using (var transaction = session.BeginTransaction()) | ||
{ | ||
var result = await (session.Query<Mother>().Where(k => k is Child2 && (k as Child2).Thing.Name == "look for this").ToListAsync()); | ||
|
||
Assert.That(result, Has.Count.EqualTo(1)); | ||
await (transaction.CommitAsync()); | ||
} | ||
} | ||
} | ||
|
||
} |