1
+ using System ;
2
+ using NHibernate . Cfg . MappingSchema ;
3
+ using NHibernate . Mapping . ByCode ;
4
+ using NUnit . Framework ;
5
+ using System . Linq ;
6
+
7
+ namespace NHibernate . Test . NHSpecificTest . NH3491
8
+ {
9
+ [ TestFixture ]
10
+ public class FixtureByCode
11
+ {
12
+ class SomeComponent
13
+ {
14
+ public virtual string PropertyOne { get ; set ; }
15
+ public virtual string PropertyTwo { get ; set ; }
16
+ public virtual string PropertyThree { get ; set ; }
17
+ }
18
+
19
+ class ClassWithComponents
20
+ {
21
+ public virtual Guid Id { get ; set ; }
22
+
23
+ public virtual SomeComponent Component1 { get ; set ; }
24
+
25
+ public virtual SomeComponent Component2 { get ; set ; }
26
+ }
27
+
28
+ [ Test ( Description = "NH-3491" ) , KnownBug ( "NH-3491" ) ]
29
+ public void ShouldProperlyMapComponentWhenMappingOnlyPartOfItInSomePlaces ( )
30
+ {
31
+ var mapper = new ModelMapper ( ) ;
32
+ mapper . Class < ClassWithComponents > ( cm =>
33
+ {
34
+ cm . Component ( x => x . Component1 , c =>
35
+ {
36
+ c . Property ( x => x . PropertyOne , p => p . Column ( "OnePropertyOne" ) ) ;
37
+ } ) ;
38
+
39
+ cm . Component ( x => x . Component2 , c =>
40
+ {
41
+ c . Property ( x => x . PropertyOne , p => p . Column ( "TwoPropertyOne" ) ) ;
42
+ c . Property ( x => x . PropertyTwo , p => p . Column ( "TwoPropertyTwo" ) ) ;
43
+ } ) ;
44
+ } ) ;
45
+
46
+ //Compile, and get the component property in which we mapped only one inner property
47
+ var mappings = mapper . CompileMappingForAllExplicitlyAddedEntities ( ) ;
48
+
49
+ var component1PropertyMapping = ( HbmComponent ) mappings . RootClasses [ 0 ] . Properties . Single ( x => x . Name == "Component1" ) ;
50
+
51
+ //There should be only one inner property in the mapping of this component
52
+ // Note: take a look at how CURRENTLY the test fails with 1 expected vs 2, instead of vs 3.
53
+ // This means that the "PropertyThree" property of the component that was never mapped, is not taken into account (which is fine).
54
+ Assert . That ( component1PropertyMapping . Items . Length , Is . EqualTo ( 1 ) ) ;
55
+ }
56
+ }
57
+ }
0 commit comments