-
Notifications
You must be signed in to change notification settings - Fork 686
/
Copy pathGenericDynamicComponentConventionTests.cs
115 lines (89 loc) · 3.24 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
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.OverridingFluentInterface
{
[TestFixture]
public class GenericDynamicComponentConventionTests
{
private PersistenceModel model;
private IMappingProvider mapping;
private Type mappingType;
[SetUp]
public void CreatePersistenceModel()
{
model = new PersistenceModel();
}
[Test]
public void AccessShouldntBeOverwritten()
{
Mapping(x => x.Access.Field());
Convention(x => x.Access.Property());
VerifyModel(x => x.Access.ShouldEqual("field"));
}
[Test]
public void InsertShouldntBeOverwritten()
{
Mapping(x => x.Insert());
Convention(x => x.Not.Insert());
VerifyModel(x => x.Insert.ShouldBeTrue());
}
[Test]
public void UpdateShouldntBeOverwritten()
{
Mapping(x => x.Update());
Convention(x => x.Not.Update());
VerifyModel(x => x.Update.ShouldBeTrue());
}
[Test]
public void UniqueShouldntBeOverwritten()
{
Mapping(x => x.Unique());
Convention(x => x.Not.Unique());
VerifyModel(x => x.Unique.ShouldBeTrue());
}
[Test]
public void OptimisticLockShouldntBeOverwritten()
{
Mapping(x => x.OptimisticLock());
Convention(x => x.Not.OptimisticLock());
VerifyModel(x => x.OptimisticLock.ShouldBeTrue());
}
#region Helpers
private void Convention(Action<IDynamicComponentInstance> convention)
{
model.Conventions.Add(new DynamicComponentConventionBuilder().Always(convention));
}
private void Mapping(Action<DynamicComponentPart<IDictionary<string, object>>> mappingDefinition)
{
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"]);
});
mappingDefinition(map);
mapping = classMap;
mappingType = typeof(PropertyTarget);
}
private void VerifyModel(Action<ComponentMapping> modelVerification)
{
model.Add(mapping);
var generatedModels = model.BuildMappings();
var modelInstance = (ComponentMapping)generatedModels
.First(x => x.Classes.FirstOrDefault(c => c.Type == mappingType) != null)
.Classes.First()
.Components.First();
modelVerification(modelInstance);
}
#endregion
}
}