@@ -203,6 +203,57 @@ public void should_prefix_property_columns()
203
203
}
204
204
}
205
205
206
+ [ TestFixture ]
207
+ public class when_the_component_column_prefix_visitor_processes_a_component_with_a_prefix_using_field_alias : ComponentColumnPrefixVisitorSpec
208
+ {
209
+ PersistenceModel model ;
210
+ IEnumerable < HibernateMapping > mappings ;
211
+ ClassMapping targetMapping ;
212
+ const string columnPrefix = "{property}" ;
213
+
214
+ public override void establish_context ( )
215
+ {
216
+ model = new PersistenceModel ( ) ;
217
+
218
+ var componentMap = new ComponentMap < FieldComponent > ( ) ;
219
+ componentMap . Map ( x => x . X ) ;
220
+ componentMap . Map ( x => x . Y ) ;
221
+
222
+ model . Add ( componentMap ) ;
223
+
224
+ var classMapping = new ClassMap < Root > ( ) ;
225
+ classMapping . Id ( r => r . Id ) ;
226
+ classMapping . Component ( Reveal . Member < Root , FieldComponent > ( "component" ) , cpt => cpt . Access . Field ( ) . ColumnPrefix ( columnPrefix ) ) ;
227
+ model . Add ( classMapping ) ;
228
+ }
229
+
230
+ public override void because ( )
231
+ {
232
+ mappings = model . BuildMappings ( ) . ToList ( ) ;
233
+ targetMapping = mappings . SelectMany ( x => x . Classes ) . FirstOrDefault ( x => x . Type == typeof ( Root ) ) ;
234
+ }
235
+
236
+ [ Test ]
237
+ public void should_prefix_field_columns ( )
238
+ {
239
+ targetMapping . Components . Single ( )
240
+ . Properties . SelectMany ( x => x . Columns )
241
+ . Each ( c => c . Name . ShouldStartWith ( "component" ) ) ;
242
+ }
243
+ }
244
+
245
+ class Root
246
+ {
247
+ FieldComponent component ;
248
+ public int Id { get ; set ; }
249
+ }
250
+
251
+ class FieldComponent
252
+ {
253
+ public string X { get ; set ; }
254
+ public int ? Y { get ; set ; }
255
+ }
256
+
206
257
public abstract class ComponentColumnPrefixVisitorSpec : Specification
207
258
{
208
259
protected AnyMapping any_with_column ( string column )
0 commit comments