Skip to content

Commit 813451f

Browse files
committed
add a test case for issue nhibernate#3623
1 parent 0c9e442 commit 813451f

File tree

3 files changed

+253
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)