@@ -395,19 +395,19 @@ public void ShouldMapNestedMultiplyRecursiveRelationships()
395395 [ Fact ]
396396 public void ShouldMapChildOneToManyRecursiveRelationships ( )
397397 {
398- var sourceLocation1 = new Location { Id = 1 } ;
399- var sourceLocation2 = new Location { Id = 2 } ;
398+ var sourceLocation1 = new Issue62 . Location { Id = 1 } ;
399+ var sourceLocation2 = new Issue62 . Location { Id = 2 } ;
400400
401- sourceLocation1 . LocationPlace = sourceLocation2 . LocationPlace = new Place
401+ sourceLocation1 . LocationPlace = sourceLocation2 . LocationPlace = new Issue62 . Place
402402 {
403403 Locations = new [ ] { sourceLocation1 , sourceLocation2 }
404404 } ;
405405
406- var source = new [ ] { sourceLocation1 , sourceLocation2 } ;
406+ IEnumerable < Issue62 . Location > source = new [ ] { sourceLocation1 , sourceLocation2 } ;
407407
408408 var result = Mapper
409- . Map < IEnumerable < Location > > ( source )
410- . ToANew < IEnumerable < DtoLocation > > ( )
409+ . Map ( source )
410+ . ToANew < IEnumerable < Issue62 . DtoLocation > > ( )
411411 . ToArray ( ) ;
412412
413413 result . Length . ShouldBe ( 2 ) ;
@@ -427,6 +427,44 @@ public void ShouldMapChildOneToManyRecursiveRelationships()
427427 dtoLocation2 . LocationPlace . Locations . Second ( ) . ShouldBe ( dtoLocation2 ) ;
428428 }
429429
430+ [ Fact ]
431+ public void ShouldMatchConfiguredSourceEnumerablesInRecursiveRelationships ( )
432+ {
433+ using ( var mapper = Mapper . CreateNew ( ) )
434+ {
435+ mapper
436+ . GetPlanFor < IEnumerable < Issue63 . Location > > ( )
437+ . ToANew < IEnumerable < Issue63 . DtoLocation > > ( cfg => cfg
438+ . WhenMapping
439+ . From < Issue63 . Place > ( )
440+ . To < Issue63 . DtoPlace > ( )
441+ . Map ( ( p , dto ) => p . PlaceLabels . Select ( x => x . Label ) )
442+ . To ( dto => dto . Labels ) ) ;
443+
444+ mapper
445+ . GetPlanFor < Issue63 . Location > ( )
446+ . ToANew < Issue63 . DtoLocation > ( ) ;
447+
448+ var sourceLocation = new Issue63 . Location { Id = 1 } ;
449+ var sourcePlace = new Issue63 . Place ( ) ;
450+ var sourceLabel = new Issue63 . Label { Id = 1 , Name = "Mr Label" } ;
451+ var sourcePlaceLabel = new Issue63 . PlaceLabel { Place = sourcePlace , Label = sourceLabel } ;
452+
453+ sourceLocation . Place = sourcePlace ;
454+ sourcePlace . PlaceLabels = new [ ] { sourcePlaceLabel } ;
455+ sourcePlace . Locations = new [ ] { sourceLocation } ;
456+
457+ var source = new [ ] { sourceLocation } ;
458+
459+ var result = mapper
460+ . Map < IEnumerable < Issue63 . Location > > ( source )
461+ . ToANew < IEnumerable < Issue63 . DtoLocation > > ( )
462+ . ToArray ( ) ;
463+
464+ result . Length . ShouldBe ( 1 ) ;
465+ }
466+ }
467+
430468 [ Fact ]
431469 public void ShouldUseConfiguredRecursiveDataSources ( )
432470 {
@@ -583,28 +621,83 @@ internal class SubjectPresenter
583621 public Presenter Presenter { get ; set ; }
584622 }
585623
586- public class Location
624+ public class Issue62
587625 {
588- public int Id { get ; set ; }
626+ public class Location
627+ {
628+ public int Id { get ; set ; }
589629
590- public Place LocationPlace { get ; set ; }
591- }
630+ public Place LocationPlace { get ; set ; }
631+ }
592632
593- public class Place
594- {
595- public IEnumerable < Location > Locations { get ; set ; }
596- }
633+ public class Place
634+ {
635+ public IEnumerable < Location > Locations { get ; set ; }
636+ }
597637
598- public class DtoLocation
599- {
600- public int Id { get ; set ; }
638+ public class DtoLocation
639+ {
640+ public int Id { get ; set ; }
601641
602- public DtoPlace LocationPlace { get ; set ; }
642+ public DtoPlace LocationPlace { get ; set ; }
643+ }
644+
645+ public class DtoPlace
646+ {
647+ public IEnumerable < DtoLocation > Locations { get ; set ; }
648+ }
603649 }
604650
605- public class DtoPlace
651+ public class Issue63
606652 {
607- public IEnumerable < DtoLocation > Locations { get ; set ; }
653+ public class Location
654+ {
655+ public int Id { get ; set ; }
656+
657+ public Place Place { get ; set ; }
658+ }
659+ public class Place
660+ {
661+ public IEnumerable < PlaceLabel > PlaceLabels { get ; set ; }
662+
663+ public IEnumerable < Location > Locations { get ; set ; }
664+ }
665+
666+ public class PlaceLabel
667+ {
668+ public virtual Label Label { get ; set ; }
669+
670+ public virtual Place Place { get ; set ; }
671+ }
672+
673+ public class Label
674+ {
675+ public int Id { get ; set ; }
676+
677+ public string Name { get ; set ; }
678+ }
679+
680+ public class DtoLocation
681+ {
682+ public int Id { get ; set ; }
683+
684+ // ReSharper disable once MemberHidesStaticFromOuterClass
685+ public DtoPlace Place { get ; set ; }
686+ }
687+
688+ public class DtoPlace
689+ {
690+ public IEnumerable < DtoLabel > Labels { get ; set ; }
691+
692+ public IEnumerable < DtoLocation > Locations { get ; set ; }
693+ }
694+
695+ public class DtoLabel
696+ {
697+ public int Id { get ; set ; }
698+
699+ public string Name { get ; set ; }
700+ }
608701 }
609702
610703 #endregion
0 commit comments