From 4ea4bce28fce4d9e766b195e217dc55e7ac42e67 Mon Sep 17 00:00:00 2001 From: digitaldirk <22691956+digitaldirk@users.noreply.github.com> Date: Mon, 17 Jun 2024 10:25:31 -0700 Subject: [PATCH] Test for nested collection exclude by name string Add test for excluding nested collection properties by name string. Related to #28 --- AnyDiff/AnyDiff.Tests/IgnoreTests.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/AnyDiff/AnyDiff.Tests/IgnoreTests.cs b/AnyDiff/AnyDiff.Tests/IgnoreTests.cs index 5466e19..87924d1 100644 --- a/AnyDiff/AnyDiff.Tests/IgnoreTests.cs +++ b/AnyDiff/AnyDiff.Tests/IgnoreTests.cs @@ -91,6 +91,26 @@ public void ShouldExclude_ByPropertyPathList() Assert.AreEqual(0, diff.Count); } + [Test] + public void ShouldExclude_NestedCollectionByName() + { + // 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. + var basicChild = new BasicChild(1, "Basic Child"); + // Notice "Child 2" at index [1] + var childrenList1 = new List { new ComplexChild(1, "Child 1", basicChild), new ComplexChild(2, "Child 2", basicChild) }; + // Notice "Child 3" at index [1] + var childrenList2 = new List { new ComplexChild(1, "Child 1", basicChild), new ComplexChild(2, "Child 3", basicChild) }; + + // Notice id 1 + var object1 = new ComplexObjectWithListChildren(1, "Name 1", childrenList1, basicChild); + // Notice id 2 + var object2 = new ComplexObjectWithListChildren(2, "Name 1", childrenList2, basicChild); + + var diff = object1.Diff(object2, ".Children.ChildName"); + // There are 2 differences between the objects, but the difference count should be 1, because child name should be ignored. + Assert.AreEqual(1, diff.Count); + } + [Test] public void ShouldInclude_ByPropertyList() {