|
| 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 System.Linq; |
| 13 | +using NHibernate.Cfg.MappingSchema; |
| 14 | +using NHibernate.Mapping.ByCode; |
| 15 | +using NHibernate.Util; |
| 16 | +using NUnit.Framework; |
| 17 | + |
| 18 | +namespace NHibernate.Test.NHSpecificTest.GH3623 |
| 19 | +{ |
| 20 | + using System.Threading.Tasks; |
| 21 | + [TestFixture] |
| 22 | + public class ComponentsListFixtureAsync : TestCaseMappingByCode |
| 23 | + { |
| 24 | + private Guid _id1; |
| 25 | + private Guid _id2; |
| 26 | + |
| 27 | + protected override void OnSetUp() |
| 28 | + { |
| 29 | + using var session = OpenSession(); |
| 30 | + using var tr = session.BeginTransaction(); |
| 31 | + var root1 = new Entity1(); |
| 32 | + root1.Entries.Add(new ComponentListEntry { DummyString = "one", Property1 = "first", Property2 = "second" }); |
| 33 | + |
| 34 | + var root2 = new Entity2(); |
| 35 | + root2.Entries.Add(new ComponentListEntry { DummyString = "two", Property1 = "third", Property2 = "fourth" }); |
| 36 | + |
| 37 | + session.Save(root1); |
| 38 | + session.Save(root2); |
| 39 | + tr.Commit(); |
| 40 | + _id1 = root1.Id; |
| 41 | + _id2 = root2.Id; |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public async Task LoadingAsync() |
| 46 | + { |
| 47 | + using var newSession = OpenSession(); |
| 48 | + var entity1 = await (newSession.GetAsync<Entity1>(_id1)); |
| 49 | + var entity1Entry = entity1.Entries.First(); |
| 50 | + var entity2 = await (newSession.GetAsync<Entity2>(_id2)); |
| 51 | + var entity2Entry = entity2.Entries.First(); |
| 52 | + |
| 53 | + Assert.That(entity1Entry.DummyString, Is.EqualTo("one")); |
| 54 | + Assert.That(entity2Entry.DummyString, Is.EqualTo("two")); |
| 55 | + Assert.That(entity1Entry.Property1, Is.EqualTo("first")); |
| 56 | + Assert.That(entity2Entry.Property2, Is.EqualTo("fourth")); |
| 57 | + |
| 58 | + Assert.That(entity1Entry.Property2, Is.Null); |
| 59 | + Assert.That(entity2Entry.Property1, Is.Null); |
| 60 | + } |
| 61 | + |
| 62 | + protected override void OnTearDown() |
| 63 | + { |
| 64 | + using var session = OpenSession(); |
| 65 | + using var transaction = session.BeginTransaction(); |
| 66 | + session.Delete("from System.Object"); |
| 67 | + transaction.Commit(); |
| 68 | + } |
| 69 | + |
| 70 | + protected override HbmMapping GetMappings() |
| 71 | + { |
| 72 | + var mapper = new ModelMapper(); |
| 73 | + |
| 74 | + mapper.Class<Entity1>(rc => |
| 75 | + { |
| 76 | + rc.Table("Entity1"); |
| 77 | + rc.Id(x => x.Id, map => map.Generator(Generators.GuidComb)); |
| 78 | + rc.Lazy(false); |
| 79 | + rc.Property(x => x.Name); |
| 80 | + |
| 81 | + rc.Bag( |
| 82 | + x => x.Entries, |
| 83 | + v => |
| 84 | + { |
| 85 | + v.Table("Entity1Entry"); |
| 86 | + v.Key(x => x.Column("Entity1Id")); |
| 87 | + }, |
| 88 | + h => h.Component(cmp => |
| 89 | + { |
| 90 | + cmp.Property(x => x.DummyString); |
| 91 | + cmp.Property(x => x.Property1); |
| 92 | + })); |
| 93 | + }); |
| 94 | + |
| 95 | + mapper.Class<Entity2>(rc => |
| 96 | + { |
| 97 | + rc.Table("Entity2"); |
| 98 | + rc.Id(x => x.Id, map => map.Generator(Generators.GuidComb)); |
| 99 | + rc.Lazy(false); |
| 100 | + rc.Property(x => x.Name); |
| 101 | + |
| 102 | + rc.Bag( |
| 103 | + x => x.Entries, |
| 104 | + v => |
| 105 | + { |
| 106 | + v.Table("Entity2Entry"); |
| 107 | + v.Key(x => x.Column("Entity2Id")); |
| 108 | + }, |
| 109 | + h => h.Component(cmp => |
| 110 | + { |
| 111 | + cmp.Property(x => x.DummyString); |
| 112 | + cmp.Property(x => x.Property2); |
| 113 | + })); |
| 114 | + }); |
| 115 | + |
| 116 | + return mapper.CompileMappingForAllExplicitlyAddedEntities(); |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments