-
Notifications
You must be signed in to change notification settings - Fork 685
/
Copy pathGenericDynamicComponentConventionTests.cs
94 lines (75 loc) · 2.67 KB
/
GenericDynamicComponentConventionTests.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
using System;
using System.Linq;
using FluentNHibernate.Conventions.Helpers.Builders;
using FluentNHibernate.Conventions.Instances;
using FluentNHibernate.Mapping;
using FluentNHibernate.MappingModel.ClassBased;
using FluentNHibernate.Testing.DomainModel.Mapping;
using NUnit.Framework;
namespace FluentNHibernate.Testing.ConventionsTests.ApplyingToModel
{
[TestFixture]
public class GenericDynamicComponentConventionTests
{
private PersistenceModel model;
[SetUp]
public void CreatePersistenceModel()
{
model = new PersistenceModel();
}
[Test]
public void ShouldSetAccessProperty()
{
Convention(x => x.Access.Property());
VerifyModel(x => x.Access.ShouldEqual("property"));
}
[Test]
public void ShouldSetInsertProperty()
{
Convention(x => x.Insert());
VerifyModel(x => x.Insert.ShouldBeTrue());
}
[Test]
public void ShouldSetUpdateProperty()
{
Convention(x => x.Update());
VerifyModel(x => x.Update.ShouldBeTrue());
}
[Test]
public void ShouldSetUniqueProperty()
{
Convention(x => x.Unique());
VerifyModel(x => x.Unique.ShouldBeTrue());
}
[Test]
public void ShouldSetOptimisticLockProperty()
{
Convention(x => x.OptimisticLock());
VerifyModel(x => x.OptimisticLock.ShouldBeTrue());
}
#region Helpers
private void Convention(Action<IDynamicComponentInstance> convention)
{
model.Conventions.Add(new DynamicComponentConventionBuilder().Always(convention));
}
private void VerifyModel(Action<ComponentMapping> modelVerification)
{
var classMap = new ClassMap<PropertyTarget>();
classMap.Id(x => x.Id);
var map = classMap.DynamicComponent(x => x.GenericExtensionData, m =>
{
m.Map(x => (string)x["Name"]);
m.Map(x => (int)x["Age"]);
m.Map(x => (string)x["Profession"]);
});
model.Add(classMap);
var generatedModels = model.BuildMappings();
var modelInstance = (ComponentMapping)generatedModels
.First(x => x.Classes.FirstOrDefault(c => c.Type == typeof(PropertyTarget)) != null)
.Classes.First()
.Components.Where(x => x is ComponentMapping).First();
modelVerification(modelInstance);
}
#endregion
}
}