1
+ using System . Linq ;
2
+ using FakeItEasy ;
3
+ using FluentNHibernate . MappingModel ;
4
+ using FluentNHibernate . MappingModel . Collections ;
5
+ using FluentNHibernate . Visitors ;
6
+ using NUnit . Framework ;
7
+
8
+ namespace FluentNHibernate . Testing . Visitors
9
+ {
10
+ public abstract class RelationshipPairingVisitorSpec : Specification
11
+ {
12
+ protected RelationshipPairingVisitor visitor ;
13
+ protected CollectionMapping collectionMappingToZ ;
14
+ protected ManyToOneMapping manyToOneZToHolder ;
15
+ protected ManyToOneMapping manyToOneYToHolder ;
16
+ }
17
+
18
+ [ TestFixture ]
19
+ public class when_the_relationship_pairing_visitor_visits_with_multiple_many_to_one_mapping_references : RelationshipPairingVisitorSpec
20
+ {
21
+ public override void establish_context ( )
22
+ {
23
+ manyToOneYToHolder = new ManyToOneMapping ( ) ;
24
+ manyToOneYToHolder . Set ( x => x . Class , Layer . Defaults , new TypeReference ( typeof ( Holder ) ) ) ;
25
+ manyToOneYToHolder . Set ( x => x . Name , Layer . Defaults , "ARankedFirstProperty" ) ;
26
+ manyToOneYToHolder . ContainingEntityType = typeof ( ARankedFirst ) ;
27
+ manyToOneYToHolder . Member = new PropertyMember ( typeof ( ARankedFirst ) . GetProperty ( "ARankedFirstProperty" ) ) ;
28
+
29
+ manyToOneZToHolder = new ManyToOneMapping ( ) ;
30
+ manyToOneZToHolder . Set ( x => x . Class , Layer . Defaults , new TypeReference ( typeof ( Holder ) ) ) ;
31
+ manyToOneZToHolder . Set ( x => x . Name , Layer . Defaults , "BRankedSecondProperty" ) ;
32
+ manyToOneZToHolder . ContainingEntityType = typeof ( BRankedSecond ) ;
33
+ manyToOneZToHolder . Member = new PropertyMember ( typeof ( BRankedSecond ) . GetProperty ( "BRankedSecondProperty" ) ) ;
34
+
35
+ var relationship = new OneToManyMapping ( ) ;
36
+ relationship . Set ( x => x . Class , Layer . Defaults , new TypeReference ( typeof ( BRankedSecond ) ) ) ;
37
+ relationship . ContainingEntityType = typeof ( Holder ) ;
38
+
39
+ collectionMappingToZ = CollectionMapping . Bag ( ) ;
40
+ collectionMappingToZ . Set ( x => x . ChildType , Layer . Defaults , typeof ( BRankedSecond ) ) ;
41
+ collectionMappingToZ . Set ( x => x . Name , Layer . Defaults , "ColectionOfBRankedSeconds" ) ;
42
+ collectionMappingToZ . Set ( x => x . Relationship , Layer . Defaults , relationship ) ;
43
+ collectionMappingToZ . ContainingEntityType = typeof ( Holder ) ;
44
+
45
+ visitor = new RelationshipPairingVisitor ( A . Fake < PairBiDirectionalManyToManySidesDelegate > ( ) ) ;
46
+ }
47
+
48
+ [ Test ]
49
+ public void should_associate_the_collection_mapping_to_the_correct_type ( )
50
+ {
51
+ visitor . ProcessCollection ( collectionMappingToZ ) ;
52
+ visitor . ProcessManyToOne ( manyToOneYToHolder ) ;
53
+ visitor . ProcessManyToOne ( manyToOneZToHolder ) ;
54
+ visitor . Visit ( Enumerable . Empty < HibernateMapping > ( ) ) ;
55
+
56
+ var otherSide = ( ManyToOneMapping ) collectionMappingToZ . OtherSide ;
57
+ otherSide . ContainingEntityType . ShouldEqual ( typeof ( BRankedSecond ) ) ;
58
+ }
59
+ }
60
+ }
0 commit comments