Skip to content

Commit 4ea4bce

Browse files
authored
Test for nested collection exclude by name string
Add test for excluding nested collection properties by name string. Related to replaysMike#28
1 parent d03f685 commit 4ea4bce

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

AnyDiff/AnyDiff.Tests/IgnoreTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ public void ShouldExclude_ByPropertyPathList()
9191
Assert.AreEqual(0, diff.Count);
9292
}
9393

94+
[Test]
95+
public void ShouldExclude_NestedCollectionByName()
96+
{
97+
// If nested collection excluding with propertiesToExcludeOrInclude is working this test should output only 1 difference because the Child 2/Child 3 difference would be ignored. The values that are different are object1 and object2 id and the 2nd complex child name.
98+
var basicChild = new BasicChild(1, "Basic Child");
99+
// Notice "Child 2" at index [1]
100+
var childrenList1 = new List<ComplexChild> { new ComplexChild(1, "Child 1", basicChild), new ComplexChild(2, "Child 2", basicChild) };
101+
// Notice "Child 3" at index [1]
102+
var childrenList2 = new List<ComplexChild> { new ComplexChild(1, "Child 1", basicChild), new ComplexChild(2, "Child 3", basicChild) };
103+
104+
// Notice id 1
105+
var object1 = new ComplexObjectWithListChildren(1, "Name 1", childrenList1, basicChild);
106+
// Notice id 2
107+
var object2 = new ComplexObjectWithListChildren(2, "Name 1", childrenList2, basicChild);
108+
109+
var diff = object1.Diff(object2, ".Children.ChildName");
110+
// There are 2 differences between the objects, but the difference count should be 1, because child name should be ignored.
111+
Assert.AreEqual(1, diff.Count);
112+
}
113+
94114
[Test]
95115
public void ShouldInclude_ByPropertyList()
96116
{

0 commit comments

Comments
 (0)