Skip to content

When CollectionAssert.AreEqual do compare each element, it will ignore the IEquatable of the element too #2271

Closed
@LiyueWang-zz

Description

@LiyueWang-zz

With the code changes #2118 for Issue2097, the test below still will fail, since when the NUnitEqualityComparer does each item comparison, the property compareAsCollection is still true, so it will not get in the condition, which ignoring the IEquatable of the element and will fail the assertion.

namespace Nunit3TestsSamples {
	[TestFixture]
	class TestSample1 {

		[Test]
		public void test() {
			var set1 = new List<TestObject>() {
				new TestObject { Value = "test1" },
				new TestObject { Value = "test2" },
				new TestObject { Value = "test3" }
			};
			var set2 = new List<TestObject>() {
				new TestObject { Value = "test1" },
				new TestObject { Value = "test2" },
				new TestObject { Value = "test3" }
			};

			CollectionAssert.AreEqual( set1, set2 );
		}

		class TestObject : IEquatable<TestObject> {
			public string Value { get; set; }

			public bool Equals( TestObject other ) {
				return Value.Equals( other.Value );
			}
		}
	}
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions