diff --git a/src/StronglyTypedIds/EquatableArray.cs b/src/StronglyTypedIds/EquatableArray.cs index fd4d15123..d3970db05 100644 --- a/src/StronglyTypedIds/EquatableArray.cs +++ b/src/StronglyTypedIds/EquatableArray.cs @@ -37,7 +37,7 @@ public bool Equals(EquatableArray array) /// public override bool Equals(object? obj) { - return obj is EquatableArray array && Equals(array); + return obj is EquatableArray array && this.Equals(array); } /// diff --git a/test/StronglyTypedIds.Tests/EqualityTests.cs b/test/StronglyTypedIds.Tests/EqualityTests.cs index 8b2eddc14..bfdc1c7a8 100644 --- a/test/StronglyTypedIds.Tests/EqualityTests.cs +++ b/test/StronglyTypedIds.Tests/EqualityTests.cs @@ -151,10 +151,61 @@ public void ResultWithDiagnosticHasExpectedEqualityBehaviour() } [Fact] - public void EquatableArrayOverridenEqualsComparesAsExpected() { - var instance = new EquatableArray(["A"]); - object comparand = new EquatableArray(["A"]); + public void EquatableArray_PrimitiveComparison() + { + int[] val1 = [1, 2, 3, 4, 5]; + int[] val2 = [1, 2, 3, 4, 5]; + + var arr1 = new EquatableArray(val1); + var arr2 = new EquatableArray(val2); + + Assert.True(arr1.Equals(arr2)); + } + + [Fact] + public void EquatableArray_RecordComparison() + { + Record[] val1 = [new(1), new(2), new(3), new(4), new(5)]; + Record[] val2 = [new(1), new(2), new(3), new(4), new(5)]; + + var arr1 = new EquatableArray(val1); + var arr2 = new EquatableArray(val2); + + Assert.True(arr1.Equals(arr2)); + } + + [Fact] + public void EquatableArray_NestedEquatableArrayComparison() + { + EquatableArray[] val1 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + EquatableArray[] val2 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + + var arr1 = new EquatableArray>(val1); + var arr2 = new EquatableArray>(val2); + + Assert.True(arr1.Equals(arr2)); + } + + [Fact] + public void EquatableArray_BoxedNestedEquatableArrayComparison() + { + EquatableArray[] val1 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + EquatableArray[] val2 = [new([1]), new([2]), new([3]), new([4]), new([5])]; + + object arr1 = new EquatableArray>(val1); + var arr2 = new EquatableArray>(val2); + + Assert.True(arr1.Equals(arr2)); + Assert.True(arr2.Equals(arr1)); + } + + public record Record + { + public Record(int value) + { + Value = value; + } - Assert.True(instance.Equals(comparand)); + public int Value { get; } } } \ No newline at end of file