File tree 8 files changed +78
-0
lines changed
ConventionsTests/Inspection 8 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 5
5
using FluentNHibernate . Conventions ;
6
6
using FluentNHibernate . Conventions . Inspections ;
7
7
using FluentNHibernate . MappingModel ;
8
+ using FluentNHibernate . MappingModel . Collections ;
8
9
using FluentNHibernate . Utils . Reflection ;
9
10
using NUnit . Framework ;
10
11
@@ -43,6 +44,27 @@ public void AnysCollectionIsEmpty()
43
44
inspector . Anys . IsEmpty ( ) . ShouldBeTrue ( ) ;
44
45
}
45
46
47
+ [ Test ]
48
+ public void CollectionsCollectionHasSameCountAsMapping ( )
49
+ {
50
+ mapping . AddCollection ( new BagMapping ( ) ) ;
51
+ inspector . Collections . Count ( ) . ShouldEqual ( 1 ) ;
52
+ }
53
+
54
+ [ Test ]
55
+ public void CollectionsCollectionOfInspectors ( )
56
+ {
57
+ mapping . AddCollection ( new BagMapping ( ) ) ;
58
+ inspector . Collections . First ( ) . ShouldBeOfType < ICollectionInspector > ( ) ;
59
+ }
60
+
61
+ [ Test ]
62
+ public void CollectionsCollectionIsEmpty ( )
63
+ {
64
+ inspector . Collections . IsEmpty ( ) . ShouldBeTrue ( ) ;
65
+ }
66
+
67
+
46
68
[ Test ]
47
69
public void CatalogMapped ( )
48
70
{
Original file line number Diff line number Diff line change @@ -56,6 +56,14 @@ public void ReferencesShouldAddToReferencesCollectionOnModel()
56
56
. ModelShouldMatch ( x => x . References . Count ( ) . ShouldEqual ( 1 ) ) ;
57
57
}
58
58
59
+ [ Test ]
60
+ public void HasManyShouldAddToCollectionsCollectionOnModel ( )
61
+ {
62
+ Join < OneToManyTarget > ( "table" )
63
+ . Mapping ( m => m . HasMany ( x => x . BagOfChildren ) )
64
+ . ModelShouldMatch ( x => x . Collections . Count ( ) . ShouldEqual ( 1 ) ) ;
65
+ }
66
+
59
67
[ Test ]
60
68
public void ReferencesAnyShouldAddToAnyCollectionOnModel ( )
61
69
{
Original file line number Diff line number Diff line change 1
1
using FluentNHibernate . MappingModel ;
2
2
using FluentNHibernate . MappingModel . ClassBased ;
3
+ using FluentNHibernate . MappingModel . Collections ;
3
4
using FluentNHibernate . MappingModel . Output ;
4
5
using FluentNHibernate . Testing . DomainModel . Mapping ;
5
6
using FluentNHibernate . Testing . Testing ;
@@ -148,5 +149,16 @@ public void ShouldWriteAny()
148
149
writer . VerifyXml ( mapping )
149
150
. Element ( "any" ) . Exists ( ) ;
150
151
}
152
+
153
+ [ Test ]
154
+ public void ShouldWriteCollection ( )
155
+ {
156
+ var mapping = new JoinMapping ( ) ;
157
+
158
+ mapping . AddCollection ( new BagMapping ( ) ) ;
159
+
160
+ writer . VerifyXml ( mapping )
161
+ . Element ( "bag" ) . Exists ( ) ;
162
+ }
151
163
}
152
164
}
Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
+ using FluentNHibernate . MappingModel . Collections ;
2
3
3
4
namespace FluentNHibernate . Conventions . Inspections
4
5
{
@@ -11,6 +12,7 @@ public interface IJoinInspector : IInspector
11
12
bool Optional { get ; }
12
13
IEnumerable < IPropertyInspector > Properties { get ; }
13
14
IEnumerable < IManyToOneInspector > References { get ; }
15
+ IEnumerable < ICollectionInspector > Collections { get ; }
14
16
string Schema { get ; }
15
17
string TableName { get ; }
16
18
string Catalog { get ; }
Original file line number Diff line number Diff line change @@ -87,6 +87,17 @@ public IEnumerable<IManyToOneInspector> References
87
87
}
88
88
}
89
89
90
+
91
+ public IEnumerable < ICollectionInspector > Collections
92
+ {
93
+ get
94
+ {
95
+ return mapping . Collections
96
+ . Select ( x => new CollectionInspector ( x ) )
97
+ . Cast < ICollectionInspector > ( ) ;
98
+ }
99
+ }
100
+
90
101
public string Schema
91
102
{
92
103
get { return mapping . Schema ; }
Original file line number Diff line number Diff line change @@ -159,6 +159,9 @@ JoinMapping IJoinMappingProvider.GetJoinMapping()
159
159
foreach ( var any in providers . Anys )
160
160
mapping . AddAny ( any . GetAnyMapping ( ) ) ;
161
161
162
+ foreach ( var collection in providers . Collections )
163
+ mapping . AddCollection ( collection . GetCollectionMapping ( ) ) ;
164
+
162
165
return mapping ;
163
166
}
164
167
}
Original file line number Diff line number Diff line change 4
4
using System . Reflection ;
5
5
using FluentNHibernate . Mapping ;
6
6
using FluentNHibernate . MappingModel . ClassBased ;
7
+ using FluentNHibernate . MappingModel . Collections ;
7
8
using FluentNHibernate . Visitors ;
8
9
9
10
namespace FluentNHibernate . MappingModel
@@ -51,6 +52,11 @@ public IEnumerable<AnyMapping> Anys
51
52
get { return mappedMembers . Anys ; }
52
53
}
53
54
55
+ public IEnumerable < ICollectionMapping > Collections
56
+ {
57
+ get { return mappedMembers . Collections ; }
58
+ }
59
+
54
60
public void AddProperty ( PropertyMapping property )
55
61
{
56
62
mappedMembers . AddProperty ( property ) ;
@@ -71,6 +77,11 @@ public void AddAny(AnyMapping mapping)
71
77
mappedMembers . AddAny ( mapping ) ;
72
78
}
73
79
80
+ public void AddCollection ( ICollectionMapping collectionMapping )
81
+ {
82
+ mappedMembers . AddCollection ( collectionMapping ) ;
83
+ }
84
+
74
85
public string TableName
75
86
{
76
87
get { return attributes . Get ( x => x . TableName ) ; }
Original file line number Diff line number Diff line change 1
1
using System . Xml ;
2
2
using FluentNHibernate . MappingModel . ClassBased ;
3
+ using FluentNHibernate . MappingModel . Collections ;
3
4
using FluentNHibernate . Utils ;
4
5
using FluentNHibernate . Visitors ;
5
6
@@ -89,5 +90,13 @@ public override void Visit(AnyMapping mapping)
89
90
90
91
document . ImportAndAppendChild ( xml ) ;
91
92
}
93
+
94
+ public override void Visit ( ICollectionMapping mapping )
95
+ {
96
+ var writer = serviceLocator . GetWriter < ICollectionMapping > ( ) ;
97
+ var xml = writer . Write ( mapping ) ;
98
+
99
+ document . ImportAndAppendChild ( xml ) ;
100
+ }
92
101
}
93
102
}
You can’t perform that action at this time.
0 commit comments