forked from AutoMapper/AutoMapper.Archive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxDepthTests.cs
More file actions
101 lines (87 loc) · 3.05 KB
/
Copy pathMaxDepthTests.cs
File metadata and controls
101 lines (87 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
namespace AutoMapper.UnitTests;
public class MaxDepthTests
{
public class Source
{
public int Level { get; set; }
public IList<Source> Children { get; set; }
public Source Parent { get; set; }
public Source(int level)
{
Children = new List<Source>();
Level = level;
}
public void AddChild(Source child)
{
Children.Add(child);
child.Parent = this;
}
}
public class Destination
{
public int Level { get; set; }
public IList<Destination> Children { get; set; }
public Destination Parent { get; set; }
}
private readonly Source _source;
public MaxDepthTests()
{
var nest = new Source(1);
nest.AddChild(new Source(2));
nest.Children[0].AddChild(new Source(3));
nest.Children[0].AddChild(new Source(3));
nest.Children[0].Children[1].AddChild(new Source(4));
nest.Children[0].Children[1].AddChild(new Source(4));
nest.Children[0].Children[1].AddChild(new Source(4));
nest.AddChild(new Source(2));
nest.Children[1].AddChild(new Source(3));
nest.AddChild(new Source(2));
nest.Children[2].AddChild(new Source(3));
_source = nest;
}
[Fact]
public void Second_level_children_is_empty_with_max_depth_1()
{
var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Destination>().MaxDepth(1));
var destination = config.CreateMapper().Map<Source, Destination>(_source);
destination.Children.ShouldBeEmpty();
}
[Fact]
public void Second_level_children_are_not_null_with_max_depth_2()
{
var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Destination>().MaxDepth(2));
var destination = config.CreateMapper().Map<Source, Destination>(_source);
foreach (var child in destination.Children)
{
2.ShouldBe(child.Level);
child.ShouldNotBeNull();
destination.ShouldBe(child.Parent);
}
}
[Fact]
public void Third_level_children_is_empty_with_max_depth_2()
{
var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Destination>().MaxDepth(2));
var destination = config.CreateMapper().Map<Source, Destination>(_source);
foreach (var child in destination.Children)
{
child.Children.ShouldBeEmpty();
}
}
[Fact]
public void Third_level_children_are_not_null_max_depth_3()
{
var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Destination>().MaxDepth(3));
var destination = config.CreateMapper().Map<Source, Destination>(_source);
foreach (var child in destination.Children)
{
child.Children.ShouldNotBeNull();
foreach (var subChild in child.Children)
{
3.ShouldBe(subChild.Level);
subChild.Children.ShouldNotBeNull();
child.ShouldBe(subChild.Parent);
}
}
}
}