|
| 1 | +using System.Linq; |
| 2 | +using NHibernate.Cfg.MappingSchema; |
| 3 | +using NHibernate.Linq; |
| 4 | +using NHibernate.Mapping.ByCode; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace NHibernate.Test.NHSpecificTest.GH3289 |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class ByCodeFixture : TestCaseMappingByCode |
| 11 | + { |
| 12 | + protected override HbmMapping GetMappings() |
| 13 | + { |
| 14 | + var mapper = new ModelMapper(); |
| 15 | + mapper.Class<Entity>(rc => |
| 16 | + { |
| 17 | + rc.Id(x => x.Id, m => m.Generator(Generators.Identity)); |
| 18 | + rc.Property(x => x.Name); |
| 19 | + rc.Component(x => x.Component); |
| 20 | + }); |
| 21 | + mapper.JoinedSubclass<SubEntity>(rc => |
| 22 | + { |
| 23 | + rc.EntityName(typeof(ISubEntity).FullName); |
| 24 | + rc.Key(k => k.Column("Id")); |
| 25 | + rc.Property(x => x.SomeProperty); |
| 26 | + }); |
| 27 | + mapper.Component<Component>(rc => |
| 28 | + { |
| 29 | + rc.Property(x => x.Field); |
| 30 | + rc.Lazy(true); |
| 31 | + }); |
| 32 | + |
| 33 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 34 | + } |
| 35 | + |
| 36 | + protected override void OnSetUp() |
| 37 | + { |
| 38 | + using (var session = OpenSession()) |
| 39 | + using (var transaction = session.BeginTransaction()) |
| 40 | + { |
| 41 | + var e1 = new SubEntity { Name = "Jim" }; |
| 42 | + session.Save(e1); |
| 43 | + |
| 44 | + transaction.Commit(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + protected override void OnTearDown() |
| 49 | + { |
| 50 | + using (var session = OpenSession()) |
| 51 | + using (var transaction = session.BeginTransaction()) |
| 52 | + { |
| 53 | + session.CreateQuery("delete from System.Object").ExecuteUpdate(); |
| 54 | + |
| 55 | + transaction.Commit(); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + [Test] |
| 60 | + public void TestSubEntityInterfaceWithFetchIsPropertyInitialized() |
| 61 | + { |
| 62 | + using (var session = OpenSession()) |
| 63 | + using (var transaction = session.BeginTransaction()) |
| 64 | + { |
| 65 | + var data = session.Query<ISubEntity>() |
| 66 | + .Fetch(e => e.Component) |
| 67 | + .ToList(); |
| 68 | + var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); |
| 69 | + |
| 70 | + Assert.That(result, Is.True); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + [Test] |
| 75 | + public void TestSubEntityWithFetchIsPropertyInitialized() |
| 76 | + { |
| 77 | + using (var session = OpenSession()) |
| 78 | + using (var transaction = session.BeginTransaction()) |
| 79 | + { |
| 80 | + var data = session.Query<SubEntity>() |
| 81 | + .Fetch(e => e.Component) |
| 82 | + .ToList(); |
| 83 | + var result = NHibernateUtil.IsPropertyInitialized(data[0], "Component"); |
| 84 | + |
| 85 | + Assert.That(result, Is.True); |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +} |
0 commit comments