@@ -391,6 +391,42 @@ public void ShouldMapNestedMultiplyRecursiveRelationships()
391391 resultTwo . ChildRecursor . ShouldBeSameAs ( resultOne ) ;
392392 }
393393
394+ // See https://github.com/agileobjects/AgileMapper/issues/62
395+ [ Fact ]
396+ public void ShouldMapChildOneToManyRecursiveRelationships ( )
397+ {
398+ var sourceLocation1 = new Location { Id = 1 } ;
399+ var sourceLocation2 = new Location { Id = 2 } ;
400+
401+ sourceLocation1 . LocationPlace = sourceLocation2 . LocationPlace = new Place
402+ {
403+ Locations = new [ ] { sourceLocation1 , sourceLocation2 }
404+ } ;
405+
406+ var source = new [ ] { sourceLocation1 , sourceLocation2 } ;
407+
408+ var result = Mapper
409+ . Map < IEnumerable < Location > > ( source )
410+ . ToANew < IEnumerable < DtoLocation > > ( )
411+ . ToArray ( ) ;
412+
413+ result . Length . ShouldBe ( 2 ) ;
414+
415+ var dtoLocation1 = result . First ( ) ;
416+ dtoLocation1 . Id . ShouldBe ( 1 ) ;
417+ dtoLocation1 . LocationPlace . ShouldNotBeNull ( ) ;
418+
419+ var dtoLocation2 = result . Second ( ) ;
420+ dtoLocation2 . Id . ShouldBe ( 2 ) ;
421+ dtoLocation2 . LocationPlace . ShouldNotBeNull ( ) ;
422+ dtoLocation2 . LocationPlace . Locations . Count ( ) . ShouldBe ( 2 ) ;
423+
424+ dtoLocation2 . LocationPlace . ShouldBeSameAs ( dtoLocation1 . LocationPlace ) ;
425+ dtoLocation2 . LocationPlace . Locations . Count ( ) . ShouldBe ( 2 ) ;
426+ dtoLocation2 . LocationPlace . Locations . First ( ) . ShouldBe ( dtoLocation1 ) ;
427+ dtoLocation2 . LocationPlace . Locations . Second ( ) . ShouldBe ( dtoLocation2 ) ;
428+ }
429+
394430 [ Fact ]
395431 public void ShouldUseConfiguredRecursiveDataSources ( )
396432 {
@@ -547,6 +583,30 @@ internal class SubjectPresenter
547583 public Presenter Presenter { get ; set ; }
548584 }
549585
586+ public class Location
587+ {
588+ public int Id { get ; set ; }
589+
590+ public Place LocationPlace { get ; set ; }
591+ }
592+
593+ public class Place
594+ {
595+ public IEnumerable < Location > Locations { get ; set ; }
596+ }
597+
598+ public class DtoLocation
599+ {
600+ public int Id { get ; set ; }
601+
602+ public DtoPlace LocationPlace { get ; set ; }
603+ }
604+
605+ public class DtoPlace
606+ {
607+ public IEnumerable < DtoLocation > Locations { get ; set ; }
608+ }
609+
550610 #endregion
551611 }
552612}
0 commit comments