1
+ using System ;
1
2
using System . Linq ;
2
3
using FluentNHibernate . Automapping ;
4
+ using FluentNHibernate . Mapping ;
5
+ using FluentNHibernate . MappingModel . Identity ;
3
6
using NUnit . Framework ;
4
7
5
8
namespace FluentNHibernate . Testing . AutoMapping . Overrides
@@ -38,6 +41,60 @@ public void ShouldntMapReferencesUsedInCompositeId()
38
41
39
42
classMapping . References . ShouldNotContain ( x => x . Name == "Child" ) ;
40
43
}
44
+
45
+ [ Test ]
46
+ public void ShouldMapEnumIdAsAString ( )
47
+ {
48
+ var model = AutoMap . Source ( new StubTypeSource ( new [ ] { typeof ( CompositeIdEntityWithEnum ) } ) )
49
+ . Override < CompositeIdEntityWithEnum > ( o =>
50
+ o . CompositeId ( )
51
+ . KeyProperty ( x => x . FirstId )
52
+ . KeyProperty ( x => x . SecondId ) ) ;
53
+
54
+
55
+ VerifyMapping ( model , idMap =>
56
+ {
57
+ var firstKey = idMap . Keys . First ( ) ;
58
+
59
+ //this part is dumb because i'm asserting a specific implementation. i don't have any other way
60
+ //of getting to the key type though
61
+ firstKey . ShouldBeOfType ( typeof ( KeyPropertyMapping ) ) ;
62
+ var keyProp = ( KeyPropertyMapping ) firstKey ;
63
+ keyProp . Type . GetUnderlyingSystemType ( ) . ShouldEqual ( typeof ( GenericEnumMapper < > ) . MakeGenericType ( typeof ( SomeEnum ) ) ) ;
64
+ } ) ;
65
+ }
66
+
67
+ [ Test ]
68
+ public void ShouldMapEnumIdAsOverridenType ( )
69
+ {
70
+ var model = AutoMap . Source ( new StubTypeSource ( new [ ] { typeof ( CompositeIdEntityWithEnum ) } ) )
71
+ . Override < CompositeIdEntityWithEnum > ( o =>
72
+ o . CompositeId ( )
73
+ . KeyProperty ( x => x . FirstId ) . CustomType < SomeEnum > ( )
74
+ . KeyProperty ( x => x . SecondId ) . CustomType < SomeEnum > ( ) ) ;
75
+
76
+
77
+ VerifyMapping ( model , idMap =>
78
+ {
79
+ var firstKey = idMap . Keys . First ( ) ;
80
+ firstKey . ShouldBeOfType ( typeof ( KeyPropertyMapping ) ) ;
81
+ var firstKeyProp = ( KeyPropertyMapping ) firstKey ;
82
+ firstKeyProp . Type . GetUnderlyingSystemType ( ) . ShouldEqual ( typeof ( SomeEnum ) ) ;
83
+ } ) ;
84
+ }
85
+
86
+ private void VerifyMapping ( AutoPersistenceModel model , Action < CompositeIdMapping > verifier )
87
+ {
88
+ var idMapping = model . BuildMappings ( )
89
+ . First ( )
90
+ . Classes
91
+ . First ( )
92
+ . Id
93
+ ;
94
+
95
+ idMapping . ShouldBeOfType ( typeof ( CompositeIdMapping ) ) ;
96
+ verifier ( ( CompositeIdMapping ) idMapping ) ;
97
+ }
41
98
}
42
99
43
100
internal class CompositeIdEntity
@@ -46,4 +103,16 @@ internal class CompositeIdEntity
46
103
public int SecondId { get ; set ; }
47
104
public Child Child { get ; set ; }
48
105
}
106
+
107
+ internal class CompositeIdEntityWithEnum
108
+ {
109
+ public SomeEnum FirstId { get ; set ; }
110
+ public SomeEnum SecondId { get ; set ; }
111
+ }
112
+
113
+ internal enum SomeEnum
114
+ {
115
+ PossiblityOne ,
116
+ PossibilityTwo
117
+ }
49
118
}
0 commit comments