|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System.Linq; |
| 12 | +using NHibernate.Cfg.MappingSchema; |
| 13 | +using NHibernate.Linq; |
| 14 | +using NHibernate.Mapping.ByCode; |
| 15 | +using NUnit.Framework; |
| 16 | + |
| 17 | +namespace NHibernate.Test.NHSpecificTest.GH3289 |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + [TestFixture] |
| 21 | + public class ByCodeFixtureAsync : TestCaseMappingByCode |
| 22 | + { |
| 23 | + protected override HbmMapping GetMappings() |
| 24 | + { |
| 25 | + var mapper = new ModelMapper(); |
| 26 | + mapper.Class<Entity>(rc => |
| 27 | + { |
| 28 | + rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); |
| 29 | + rc.Property(x => x.Name); |
| 30 | + rc.Component(x => x.Component); |
| 31 | + }); |
| 32 | + mapper.Class<OtherEntity>(rc => |
| 33 | + { |
| 34 | + rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); |
| 35 | + rc.Property(x => x.Name); |
| 36 | + rc.Component(x => x.Component); |
| 37 | + }); |
| 38 | + mapper.JoinedSubclass<SubEntity>(rc => |
| 39 | + { |
| 40 | + rc.Key(k => k.Column("Id")); |
| 41 | + rc.Property(x => x.SomeProperty); |
| 42 | + }); |
| 43 | + mapper.Component<Component>(rc => |
| 44 | + { |
| 45 | + rc.Property(x => x.Field); |
| 46 | + rc.Lazy(true); |
| 47 | + }); |
| 48 | + |
| 49 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 50 | + } |
| 51 | + |
| 52 | + protected override void OnSetUp() |
| 53 | + { |
| 54 | + using var session = OpenSession(); |
| 55 | + using var transaction = session.BeginTransaction(); |
| 56 | + var e1 = new SubEntity { Name = "Jim" }; |
| 57 | + session.Save(e1); |
| 58 | + |
| 59 | + transaction.Commit(); |
| 60 | + } |
| 61 | + |
| 62 | + protected override void OnTearDown() |
| 63 | + { |
| 64 | + using var session = OpenSession(); |
| 65 | + using var transaction = session.BeginTransaction(); |
| 66 | + |
| 67 | + if (Dialect.SupportsTemporaryTables) |
| 68 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 69 | + else |
| 70 | + session.Delete("from System.Object"); |
| 71 | + |
| 72 | + transaction.Commit(); |
| 73 | + } |
| 74 | + |
| 75 | + [Test] |
| 76 | + public async Task TestSubEntityInterfaceWithFetchIsPropertyInitializedAsync() |
| 77 | + { |
| 78 | + using var session = OpenSession(); |
| 79 | + var data = await (session.Query<ISubEntity>() |
| 80 | + .Fetch(e => e.Component) |
| 81 | + .ToListAsync()); |
| 82 | + var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); |
| 83 | + |
| 84 | + Assert.That(result, Is.True); |
| 85 | + } |
| 86 | + |
| 87 | + [Test] |
| 88 | + public async Task TestEntityInterfaceWithFetchIsPropertyInitializedAsync() |
| 89 | + { |
| 90 | + using var session = OpenSession(); |
| 91 | + var data = await (session.Query<IEntity>() |
| 92 | + .Fetch(e => e.Component) |
| 93 | + .ToListAsync()); |
| 94 | + var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); |
| 95 | + |
| 96 | + Assert.That(result, Is.True); |
| 97 | + } |
| 98 | + |
| 99 | + [Test] |
| 100 | + public async Task TestSubEntityWithFetchIsPropertyInitializedAsync() |
| 101 | + { |
| 102 | + using var session = OpenSession(); |
| 103 | + var data = await (session.Query<SubEntity>() |
| 104 | + .Fetch(e => e.Component) |
| 105 | + .ToListAsync()); |
| 106 | + var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); |
| 107 | + |
| 108 | + Assert.That(result, Is.True); |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments