@@ -77,6 +77,82 @@ public void Should_validate_successfully()
7777 }
7878 }
7979
80+ public class When_specifying_reverse_map_with_sourcemember_attribute : NonValidatingSpecBase
81+ {
82+ public class Source
83+ {
84+ public int Value { get ; set ; }
85+ }
86+
87+ [ AutoMap ( typeof ( Source ) , ReverseMap = true ) ]
88+ public class Destination
89+ {
90+ [ SourceMember ( "Value" ) ]
91+ public int Value2 { get ; set ; }
92+ }
93+
94+ protected override MapperConfiguration Configuration { get ; } = new MapperConfiguration ( cfg =>
95+ {
96+ cfg . AddMaps ( typeof ( When_specifying_reverse_map_with_sourcemember_attribute ) ) ;
97+ } ) ;
98+
99+ [ Fact ]
100+ public void Should_reverse_map ( )
101+ {
102+ var destination = new Destination { Value2 = 5 } ;
103+ var source = Mapper . Map < Source > ( destination ) ;
104+ source . Value . ShouldBe ( 5 ) ;
105+ }
106+
107+ [ Fact ]
108+ public void Should_validate_successfully ( )
109+ {
110+ typeof ( AutoMapperConfigurationException ) . ShouldNotBeThrownBy ( ( ) => Configuration . AssertConfigurationIsValid ( Configuration . FindTypeMapFor < Source , Destination > ( ) ) ) ;
111+ typeof ( AutoMapperConfigurationException ) . ShouldNotBeThrownBy ( ( ) => Configuration . AssertConfigurationIsValid ( Configuration . FindTypeMapFor < Destination , Source > ( ) ) ) ;
112+ }
113+ }
114+
115+ public class When_specifying_generic_reverse_map_with_sourcemember_attribute : NonValidatingSpecBase
116+ {
117+ public class Source < T >
118+ {
119+ public T Value { get ; set ; }
120+
121+ public string StringValue { get ; set ; }
122+ }
123+
124+ [ AutoMap ( typeof ( Source < > ) , ReverseMap = true ) ]
125+ public class Destination < T >
126+ {
127+ [ SourceMember ( "Value" ) ]
128+ public int Value2 { get ; set ; }
129+
130+ [ SourceMember ( "StringValue" ) ]
131+ public string StringValue2 { get ; set ; }
132+ }
133+
134+ protected override MapperConfiguration Configuration { get ; } = new MapperConfiguration ( cfg =>
135+ {
136+ cfg . AddMaps ( typeof ( When_specifying_generic_reverse_map_with_sourcemember_attribute ) ) ;
137+ } ) ;
138+
139+ [ Fact ]
140+ public void Should_reverse_map ( )
141+ {
142+ Destination < int > destination = new Destination < int > { Value2 = 5 , StringValue2 = "Joe" } ;
143+ Source < int > source = Mapper . Map < Source < int > > ( destination ) ;
144+ source . Value . ShouldBe ( 5 ) ;
145+ source . StringValue . ShouldBe ( "Joe" ) ;
146+ }
147+
148+ [ Fact ]
149+ public void Should_validate_successfully ( )
150+ {
151+ typeof ( AutoMapperConfigurationException ) . ShouldNotBeThrownBy ( ( ) => Configuration . AssertConfigurationIsValid ( Configuration . FindTypeMapFor ( typeof ( Source < > ) , typeof ( Destination < > ) ) ) ) ;
152+ typeof ( AutoMapperConfigurationException ) . ShouldNotBeThrownBy ( ( ) => Configuration . AssertConfigurationIsValid ( Configuration . FindTypeMapFor ( typeof ( Destination < > ) , typeof ( Source < > ) ) ) ) ;
153+ }
154+ }
155+
80156 public class When_duplicating_map_configuration_with_code_and_attribute : NonValidatingSpecBase
81157 {
82158 public class Source
0 commit comments