forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubclassPropertiesSplitsTests.cs
109 lines (100 loc) · 3.77 KB
/
SubclassPropertiesSplitsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System.Collections.Generic;
using System.Linq;
using NHibernate.Mapping.ByCode;
using NUnit.Framework;
namespace NHibernate.Test.MappingByCode.ExpliticMappingTests
{
[TestFixture]
public class SubclassPropertiesSplitsTests
{
private class MyClass
{
public int Id { get; set; }
}
private class Inherited : MyClass
{
public string Something0 { get; set; }
public string SomethingA1 { get; set; }
public string SomethingA2 { get; set; }
public string SomethingB1 { get; set; }
public string SomethingB2 { get; set; }
}
[Test]
public void WhenSplittedPropertiesThenRegisterSplitGroupIds()
{
var inspector = new ExplicitlyDeclaredModel();
var mapper = new ModelMapper(inspector);
mapper.Subclass<Inherited>(map =>
{
map.Join("MyClassSplit1", mj =>
{
mj.Property(x => x.SomethingA1);
mj.Property(x => x.SomethingA2);
});
map.Join("MyClassSplit2", mj =>
{
mj.Property(x => x.SomethingB1);
mj.Property(x => x.SomethingB2);
});
map.Property(x => x.Something0);
});
IEnumerable<string> tablePerClassSplits = inspector.GetPropertiesSplits(typeof(Inherited));
Assert.That(tablePerClassSplits, Is.EquivalentTo(new [] {"MyClassSplit1", "MyClassSplit2"}));
}
[Test]
public void WhenSplittedPropertiesThenRegister()
{
var inspector = new ExplicitlyDeclaredModel();
var mapper = new ModelMapper(inspector);
mapper.Subclass<Inherited>(map =>
{
map.Join("MyClassSplit1", mj =>
{
mj.Property(x => x.SomethingA1);
mj.Property(x => x.SomethingA2);
});
map.Join("MyClassSplit2", mj =>
{
mj.Property(x => x.SomethingB1);
mj.Property(x => x.SomethingB2);
});
map.Property(x => x.Something0);
});
Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.Something0)), Is.False);
Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.Something0)), Is.False);
Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA1)), Is.True);
Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit1", For<Inherited>.Property(x => x.SomethingA2)), Is.True);
Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB1)), Is.True);
Assert.That(inspector.IsTablePerClassSplit(typeof(MyClass), "MyClassSplit2", For<Inherited>.Property(x => x.SomethingB2)), Is.True);
}
[Test]
public void WhenMapSplittedPropertiesThenEachPropertyIsInItsSplitGroup()
{
var inspector = new ExplicitlyDeclaredModel();
var mapper = new ModelMapper(inspector);
mapper.Class<MyClass>(map => map.Id(x => x.Id, idmap => { }));
mapper.Subclass<Inherited>(map =>
{
map.Join("MyClassSplit1", mj =>
{
mj.Property(x => x.SomethingA1);
mj.Property(x => x.SomethingA2);
});
map.Join("MyClassSplit2", mj =>
{
mj.Property(x => x.SomethingB1);
mj.Property(x => x.SomethingB2);
});
map.Property(x => x.Something0);
});
var hbmDoc = mapper.CompileMappingFor(new[] { typeof(Inherited) });
var hbmClass = hbmDoc.SubClasses[0];
Assert.That(hbmClass.Joins.Select(j => j.table), Is.EquivalentTo(new [] {"MyClassSplit1", "MyClassSplit2"}));
Assert.That(hbmClass.Properties.Single().Name, Is.EqualTo("Something0"));
var hbmSplit1 = hbmClass.Joins.Single(j => "MyClassSplit1" == j.table);
Assert.That(hbmSplit1.Properties.Select(p => p.Name), Is.EquivalentTo(new [] {"SomethingA1", "SomethingA2"}));
var hbmSplit2 = hbmClass.Joins.Single(j => "MyClassSplit2" == j.table);
Assert.That(hbmSplit2.Properties.Select(p => p.Name), Is.EquivalentTo(new [] {"SomethingB1", "SomethingB2"}));
}
}
}