forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurationAddMappingEvents.cs
74 lines (67 loc) · 2.58 KB
/
ConfigurationAddMappingEvents.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
using System.Collections.Generic;
using System.Linq;
using NHibernate.Cfg;
using NHibernate.Cfg.Loquacious;
using NHibernate.Dialect;
using NUnit.Framework;
namespace NHibernate.Test.CfgTest
{
[TestFixture]
public class ConfigurationAddMappingEvents
{
private const string ProductLineMapping =
@"<?xml version='1.0' encoding='utf-8' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
<class entity-name='ProductLine'>
<id name='Id' type='int'>
<generator class='hilo'/>
</id>
<property name='Description' not-null='true' length='200' type='string'/>
<bag name='Models' cascade='all' inverse='true'>
<key column='productId'/>
<one-to-many class='Model'/>
</bag>
</class>
</hibernate-mapping>
";
private const string ModelMapping =
@"<?xml version='1.0' encoding='utf-8' ?>
<hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'>
<class entity-name='Model'>
<id name='Id' type='int'>
<generator class='hilo'/>
</id>
<property name='Name' not-null='true' length='25' type='string'/>
<property name='Description' not-null='true' length='200' type='string'/>
<many-to-one name='ProductLine' column='productId' not-null='true' class='ProductLine'/>
</class>
</hibernate-mapping>
";
[Test]
public void WhenSubscribedToBeforeBindThenRaiseEventForEachMapping()
{
var listOfCalls = new List<BindMappingEventArgs>();
var configuration = new Configuration();
configuration.DataBaseIntegration(x => x.Dialect<MsSql2008Dialect>());
configuration.BeforeBindMapping += (sender, args) => { Assert.That(sender, Is.SameAs(configuration)); listOfCalls.Add(args); };
configuration.AddXmlString(ProductLineMapping);
configuration.AddXmlString(ModelMapping);
Assert.That(listOfCalls.Count, Is.EqualTo(2));
Assert.That(listOfCalls.Select(x => x.FileName).All(x => x != null), Is.True);
Assert.That(listOfCalls.Select(x => x.Mapping).All(x => x != null), Is.True);
}
[Test]
public void WhenSubscribedToAfterBindThenRaiseEventForEachMapping()
{
var listOfCalls = new List<BindMappingEventArgs>();
var configuration = new Configuration();
configuration.DataBaseIntegration(x => x.Dialect<MsSql2008Dialect>());
configuration.AfterBindMapping += (sender, args) => { Assert.That(sender, Is.SameAs(configuration)); listOfCalls.Add(args); };
configuration.AddXmlString(ProductLineMapping);
configuration.AddXmlString(ModelMapping);
Assert.That(listOfCalls.Count, Is.EqualTo(2));
Assert.That(listOfCalls.Select(x => x.FileName).All(x => x != null), Is.True);
Assert.That(listOfCalls.Select(x => x.Mapping).All(x => x != null), Is.True);
}
}
}