-
Notifications
You must be signed in to change notification settings - Fork 930
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
Showing
23 changed files
with
573 additions
and
30 deletions.
There are no files selected for viewing
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
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
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
174 changes: 174 additions & 0 deletions
174
src/NHibernate.Test/Async/NHSpecificTest/GH3352/FetchFromNotMappedBaseClassFixture.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,174 @@ | ||
//------------------------------------------------------------------------------ | ||
// <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.Linq; | ||
using NHibernate.Mapping.ByCode; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3352 | ||
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class FetchFromNotMappedBaseClassFixtureAsync : TestCaseMappingByCode | ||
{ | ||
protected override HbmMapping GetMappings() | ||
{ | ||
var mapper = new ModelMapper(); | ||
mapper.Class<EntityNameMapped>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); | ||
rc.Property(x => x.Name, m => m.Lazy(true)); | ||
}); | ||
mapper.Class<EntityParentMapped>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); | ||
rc.ManyToOne(x => x.Parent, m => m.ForeignKey("none")); | ||
}); | ||
mapper.Class<EntityComponentMapped>(rc => | ||
{ | ||
rc.Id(x => x.Id, m => m.Generator(Generators.GuidComb)); | ||
rc.Component(x => x.Component); | ||
}); | ||
mapper.Component<Component>(rc => | ||
{ | ||
rc.Property(x => x.Field); | ||
rc.ManyToOne(x => x.Entity, m => m.ForeignKey("none")); | ||
rc.Lazy(true); | ||
}); | ||
return mapper.CompileMappingForAllExplicitlyAddedEntities(); | ||
} | ||
|
||
protected override void OnSetUp() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
var np = new EntityComponentMapped { Component = new Component { Field = "x" } }; | ||
session.Save(np); | ||
var e = new EntityParentMapped { Parent = np }; | ||
session.Save(e); | ||
var nameMapped = new EntityNameMapped { Name = "lazy" }; | ||
session.Save(nameMapped); | ||
np.Component.Entity = nameMapped; | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
protected override void OnTearDown() | ||
{ | ||
using var session = OpenSession(); | ||
using var transaction = session.BeginTransaction(); | ||
session.CreateQuery("delete from System.Object").ExecuteUpdate(); | ||
|
||
transaction.Commit(); | ||
} | ||
|
||
[Test] | ||
public async Task CanFetchLazyComponentFromNotMappedBaseClassAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var list = await (session.Query<EntityComponentMapped>().Fetch(x => x.Component).ToListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(1)); | ||
var result = list[0]; | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result, nameof(result.Component))); | ||
Assert.That(result.Component.Field, Is.EqualTo("x")); | ||
} | ||
|
||
[Test] | ||
public async Task CanFetchLazyComponentThenEntityFromNotMappedBaseClassAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var list = await (session.Query<EntityComponentMapped>() | ||
.Fetch(x => x.Component) | ||
.ThenFetch(x => x.Entity) | ||
.ThenFetch(x => x.Name) | ||
.ToListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(1)); | ||
var result = list[0]; | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result, nameof(result.Component))); | ||
Assert.That(result.Component.Field, Is.EqualTo("x")); | ||
Assert.That(result.Component.Entity, Is.Not.Null); | ||
Assert.That(NHibernateUtil.IsInitialized(result.Component.Entity), Is.True); | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result.Component.Entity, nameof(result.Name)), Is.True); | ||
Assert.That(result.Component.Entity.Name, Is.EqualTo("lazy")); | ||
} | ||
|
||
[Test] | ||
public async Task CanFetchLazyPropertyFromNotMappedBaseClassAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var list = await (session.Query<EntityNameMapped>().Fetch(x => x.Name).ToListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(1)); | ||
var result = list[0]; | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result, nameof(result.Name))); | ||
Assert.That(result.Name, Is.EqualTo("lazy")); | ||
} | ||
|
||
[Test] | ||
public async Task CanThenFetchLazyComponentFromNotMappedBaseClassAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var list = await (session.Query<EntityParentMapped>().Fetch(x => x.Parent).ThenFetch(x => x.Component).ToListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(1)); | ||
var result = list[0].Parent; | ||
Assert.That(NHibernateUtil.IsInitialized(result), Is.True); | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result, nameof(result.Component))); | ||
Assert.That(result.Component.Field, Is.EqualTo("x")); | ||
} | ||
|
||
[KnownBug("GH-3356")] | ||
[Test(Description = "GH-3356" )] | ||
public async Task FetchAfterSelectAsync() | ||
{ | ||
using var log = new SqlLogSpy(); | ||
|
||
using var s = OpenSession(); | ||
var list = await (s.Query<EntityParentMapped>() | ||
.Select(x => x.Parent) | ||
.Fetch(x => x.Component) | ||
.ThenFetch(x => x.Entity) | ||
.ThenFetch(x => x.Name) | ||
.ToListAsync()); | ||
Assert.That(list, Has.Count.EqualTo(1)); | ||
var result = list[0]; | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result, nameof(result.Component))); | ||
Assert.That(result.Component.Field, Is.EqualTo("x")); | ||
Assert.That(result.Component.Entity, Is.Not.Null); | ||
Assert.That(NHibernateUtil.IsInitialized(result.Component.Entity), Is.True); | ||
Assert.That(NHibernateUtil.IsPropertyInitialized(result.Component.Entity, nameof(result.Name)), Is.True); | ||
Assert.That(result.Component.Entity.Name, Is.EqualTo("lazy")); | ||
} | ||
|
||
[Test] | ||
public async Task CanFetchEntityFromNotMappedBaseClassAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var list = await (session.Query<EntityParentMapped>().Fetch(x => x.Parent).ToListAsync()); | ||
|
||
Assert.That(list, Has.Count.EqualTo(1)); | ||
Assert.That(list[0].Parent, Is.Not.Null); | ||
Assert.That(NHibernateUtil.IsInitialized(list[0].Parent)); | ||
} | ||
|
||
[Test] | ||
public void FetchNotMappedAssociationThrowsAsync() | ||
{ | ||
using var session = OpenSession(); | ||
var query = session.Query<EntityNameMapped>().Fetch(x => x.Parent); | ||
|
||
Assert.ThrowsAsync<QueryException>(() => query.ToListAsync()); | ||
} | ||
} | ||
} |
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
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
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
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,31 @@ | ||
using System; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.GH3352 | ||
{ | ||
public class Entity | ||
{ | ||
public virtual Guid Id { get; set; } | ||
public virtual string Name { get; set; } | ||
public virtual EntityComponentMapped Parent { get; set; } | ||
public virtual Component Component { get; set; } | ||
} | ||
|
||
public class EntityNameMapped : Entity | ||
{ | ||
} | ||
|
||
public class EntityParentMapped : Entity | ||
{ | ||
} | ||
|
||
public class EntityComponentMapped : Entity | ||
{ | ||
} | ||
|
||
public class Component | ||
{ | ||
public string Field { get; set; } | ||
|
||
public EntityNameMapped Entity { get; set; } | ||
} | ||
} |
Oops, something went wrong.