| 
1 | 1 | using System;  | 
 | 2 | +using System.CodeDom;  | 
2 | 3 | using System.Collections.Generic;  | 
3 | 4 | using System.Linq;  | 
4 | 5 | using Shouldly;  | 
5 | 6 | using Xunit;  | 
6 | 7 | 
 
  | 
7 | 8 | namespace AutoMapper.UnitTests  | 
8 | 9 | {  | 
 | 10 | +    public class CyclesWithInheritance : AutoMapperSpecBase  | 
 | 11 | +    {  | 
 | 12 | +        class FlowChart  | 
 | 13 | +        {  | 
 | 14 | +            public FlowNode[] Nodes;  | 
 | 15 | +        }  | 
 | 16 | +        class FlowNode  | 
 | 17 | +        {  | 
 | 18 | +        }  | 
 | 19 | +        class FlowStep : FlowNode  | 
 | 20 | +        {  | 
 | 21 | +            public FlowNode Next;  | 
 | 22 | +        }  | 
 | 23 | +        class FlowDecision : FlowNode  | 
 | 24 | +        {  | 
 | 25 | +            public FlowNode True;  | 
 | 26 | +            public FlowNode False;  | 
 | 27 | +        }  | 
 | 28 | +        class FlowSwitch<T> : FlowNode  | 
 | 29 | +        {  | 
 | 30 | +            public IDictionary<T, object> Connections;  | 
 | 31 | +        }  | 
 | 32 | +        class FlowChartModel  | 
 | 33 | +        {  | 
 | 34 | +            public FlowNodeModel[] Nodes;  | 
 | 35 | +        }  | 
 | 36 | +        class FlowNodeModel  | 
 | 37 | +        {  | 
 | 38 | +            public Connection[] Connections;  | 
 | 39 | +        }  | 
 | 40 | +        class Connection  | 
 | 41 | +        {  | 
 | 42 | +            public FlowNodeModel Node;  | 
 | 43 | +        }  | 
 | 44 | +        protected override MapperConfiguration Configuration => new MapperConfiguration(cfg=>  | 
 | 45 | +        {  | 
 | 46 | +            cfg.CreateMap<FlowChart, FlowChartModel>();  | 
 | 47 | +            cfg.CreateMap<FlowNode, FlowNodeModel>()  | 
 | 48 | +                .Include<FlowStep, FlowNodeModel>()  | 
 | 49 | +                .Include<FlowDecision, FlowNodeModel>()  | 
 | 50 | +                .Include(typeof(FlowSwitch<>), typeof(FlowNodeModel))  | 
 | 51 | +                .ForMember(d=>d.Connections, o=>o.Ignore());  | 
 | 52 | +            cfg.CreateMap<FlowStep, FlowNodeModel>().ForMember(d => d.Connections, o => o.MapFrom(s => new[] { s.Next }));  | 
 | 53 | +            cfg.CreateMap<FlowDecision, FlowNodeModel>().ForMember(d => d.Connections, o => o.MapFrom(s => new[] { s.True, s.False }));  | 
 | 54 | +            cfg.CreateMap(typeof(FlowSwitch<>), typeof(FlowNodeModel));  | 
 | 55 | +            cfg.CreateMap<FlowNode, Connection>().ForMember(d => d.Node, o => o.MapFrom(s => s));  | 
 | 56 | +            cfg.CreateMap(typeof(KeyValuePair<,>), typeof(Connection)).ForMember("Node", o => o.MapFrom("Key"));  | 
 | 57 | +        });  | 
 | 58 | +        [Fact]  | 
 | 59 | +        public void Should_map_ok()  | 
 | 60 | +        {  | 
 | 61 | +            var flowStep = new FlowStep();  | 
 | 62 | +            var flowDecision = new FlowDecision { False = flowStep, True = flowStep };  | 
 | 63 | +            flowStep.Next = flowDecision;  | 
 | 64 | +            var source = new FlowChart { Nodes = new FlowNode[] { flowStep, flowDecision } };  | 
 | 65 | +            var dest = Map<FlowChartModel>(source);  | 
 | 66 | +        }  | 
 | 67 | +    }  | 
9 | 68 |     public class When_the_source_has_cyclical_references_with_dynamic_map : AutoMapperSpecBase  | 
10 | 69 |     {  | 
11 | 70 |         public class CDataTypeModel<T>  | 
 | 
0 commit comments