forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentAsIdTests.cs
92 lines (75 loc) · 2.58 KB
/
ComponentAsIdTests.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
using System.Linq;
using NHibernate.Cfg.MappingSchema;
using NHibernate.Mapping.ByCode.Impl;
using NUnit.Framework;
namespace NHibernate.Test.MappingByCode.MappersTests
{
[TestFixture]
public class ComponentAsIdTests
{
private class PersonId
{
public string Email { get; set; }
public User User { get; set; }
}
private class Person
{
public PersonId Id { get; set; }
public string Name { get; set; }
}
private class User
{
public int Id { get; set; }
}
[Test]
public void WhenCreatedThenSetTheComponentClass()
{
var mapdoc = new HbmMapping();
var component = new HbmCompositeId();
new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x=> x.Id), component, mapdoc);
Assert.That(component.@class, Does.Contain("PersonId"));
}
[Test]
public void CanMapProperty()
{
var mapdoc = new HbmMapping();
var compositeId = new HbmCompositeId();
var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc);
mapper.Property(For<PersonId>.Property(ts => ts.Email), x => { });
Assert.That(compositeId.Items, Has.Length.EqualTo(1));
Assert.That(compositeId.Items.First(), Is.TypeOf<HbmKeyProperty>());
Assert.That(compositeId.Items.OfType<HbmKeyProperty>().First().Name, Is.EqualTo("Email"));
}
[Test]
public void CallPropertyMapper()
{
var mapdoc = new HbmMapping();
var compositeId = new HbmCompositeId();
var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc);
var called = false;
mapper.Property(For<PersonId>.Property(ts => ts.Email), x => called = true);
Assert.That(called, Is.True);
}
[Test]
public void CanMapManyToOne()
{
var mapdoc = new HbmMapping();
var compositeId = new HbmCompositeId();
var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc);
mapper.ManyToOne(For<PersonId>.Property(ts => ts.User), x => { });
Assert.That(compositeId.Items, Has.Length.EqualTo(1));
Assert.That(compositeId.Items.First(), Is.TypeOf<HbmKeyManyToOne>());
Assert.That(compositeId.Items.OfType<HbmKeyManyToOne>().First().Name, Is.EqualTo("User"));
}
[Test]
public void CallMapManyToOneMapper()
{
var mapdoc = new HbmMapping();
var compositeId = new HbmCompositeId();
var mapper = new ComponentAsIdMapper(typeof(PersonId), For<Person>.Property(x => x.Id), compositeId, mapdoc);
var called = false;
mapper.ManyToOne(For<PersonId>.Property(ts => ts.User), x => called = true);
Assert.That(called, Is.True);
}
}
}