|
| 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; |
| 12 | +using NHibernate.Cfg; |
| 13 | +using NHibernate.Cfg.MappingSchema; |
| 14 | +using NHibernate.Mapping.ByCode; |
| 15 | +using NUnit.Framework; |
| 16 | + |
| 17 | +namespace NHibernate.Test.NHSpecificTest.GH2052 |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + [TestFixture] |
| 21 | + public class FixtureAsync : TestCaseMappingByCode |
| 22 | + { |
| 23 | + private bool _useReflectionOptimizerBackup; |
| 24 | + |
| 25 | + protected override void Configure(Configuration configuration) |
| 26 | + { |
| 27 | + base.Configure(configuration); |
| 28 | + |
| 29 | + _useReflectionOptimizerBackup = Cfg.Environment.UseReflectionOptimizer; |
| 30 | + Cfg.Environment.UseReflectionOptimizer = false; |
| 31 | + } |
| 32 | + |
| 33 | + protected override void DropSchema() |
| 34 | + { |
| 35 | + // Restore original setting. |
| 36 | + Cfg.Environment.UseReflectionOptimizer = _useReflectionOptimizerBackup; |
| 37 | + base.DropSchema(); |
| 38 | + } |
| 39 | + |
| 40 | + protected override HbmMapping GetMappings() |
| 41 | + { |
| 42 | + var mapper = new ModelMapper(); |
| 43 | + |
| 44 | + mapper.Class<EntityClassProxy>( |
| 45 | + rc => |
| 46 | + { |
| 47 | + // calling the id getter of the proxy triggers a database query |
| 48 | + //rc.Proxy(typeof(EntityClassProxy)); // That is the default, no need to actually uncomment it |
| 49 | + |
| 50 | + // calling the id getter of the proxy doesn't trigger a database query |
| 51 | + //rc.Proxy(typeof(IEntity)); |
| 52 | + |
| 53 | + rc.Id(x => x.Id); |
| 54 | + rc.Property(x => x.Name); |
| 55 | + }); |
| 56 | + |
| 57 | + mapper.UnionSubclass<SubEntityInterfaceProxy>( |
| 58 | + rc => |
| 59 | + { |
| 60 | + rc.Proxy(typeof(ISubEntityProxy)); |
| 61 | + |
| 62 | + rc.Property(x => x.AnotherName); |
| 63 | + }); |
| 64 | + |
| 65 | + mapper.UnionSubclass<AnotherSubEntityInterfaceProxy>( |
| 66 | + rc => |
| 67 | + { |
| 68 | + rc.Proxy(typeof(IAnotherSubEntityProxy)); |
| 69 | + |
| 70 | + rc.Property(x => x.AnotherName); |
| 71 | + }); |
| 72 | + |
| 73 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 74 | + } |
| 75 | + |
| 76 | + [Test] |
| 77 | + public async Task ShouldSupportCheckingLookupIdAsync() |
| 78 | + { |
| 79 | + using (var session = OpenSession()) |
| 80 | + { |
| 81 | + var lookupId = Guid.NewGuid(); |
| 82 | + var entity = (IEntity) await (session.LoadAsync(typeof(EntityClassProxy), lookupId)); |
| 83 | + Assert.That(entity.Id, Is.EqualTo(lookupId)); |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + [Test] |
| 88 | + public void ShouldSupportLoadingNonexistentAsync() |
| 89 | + { |
| 90 | + using (var session = OpenSession()) |
| 91 | + { |
| 92 | + var lookupId = Guid.NewGuid(); |
| 93 | + Assert.That(() => session.LoadAsync<EntityClassProxy>(lookupId), Throws.Nothing); |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments