From f60927f3c55afac2288f6f9fc9b527da619c40e2 Mon Sep 17 00:00:00 2001 From: Dennis Doomen Date: Wed, 18 Dec 2019 21:43:51 +0100 Subject: [PATCH] BeEquivalentTo on normal tuples should use structural equivalency (#1206) Unlinke ValueTuple<>, the older Tuple<> was treated as a value type instead of something that requires a structural equality check. --- Src/FluentAssertions/Common/TypeExtensions.cs | 10 +++++++++- Tests/Shared.Specs/BasicEquivalencySpecs.cs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Src/FluentAssertions/Common/TypeExtensions.cs b/Src/FluentAssertions/Common/TypeExtensions.cs index ebb4d23e0e..63754fcd60 100644 --- a/Src/FluentAssertions/Common/TypeExtensions.cs +++ b/Src/FluentAssertions/Common/TypeExtensions.cs @@ -531,7 +531,15 @@ private static bool IsTuple(this Type type) || openType == typeof(ValueTuple<,,,,>) || openType == typeof(ValueTuple<,,,,,>) || openType == typeof(ValueTuple<,,,,,,>) - || (openType == typeof(ValueTuple<,,,,,,,>) && IsTuple(type.GetGenericArguments()[7])); + || (openType == typeof(ValueTuple<,,,,,,,>) && IsTuple(type.GetGenericArguments()[7])) + || openType == typeof(Tuple<>) + || openType == typeof(Tuple<,>) + || openType == typeof(Tuple<,,>) + || openType == typeof(Tuple<,,,>) + || openType == typeof(Tuple<,,,,>) + || openType == typeof(Tuple<,,,,,>) + || openType == typeof(Tuple<,,,,,,>) + || (openType == typeof(Tuple<,,,,,,,>) && IsTuple(type.GetGenericArguments()[7])); } internal static bool IsAssignableToOpenGeneric(this Type type, Type definition) diff --git a/Tests/Shared.Specs/BasicEquivalencySpecs.cs b/Tests/Shared.Specs/BasicEquivalencySpecs.cs index feb8da2590..7bee36ec6a 100644 --- a/Tests/Shared.Specs/BasicEquivalencySpecs.cs +++ b/Tests/Shared.Specs/BasicEquivalencySpecs.cs @@ -3134,6 +3134,20 @@ public void When_a_nested_member_is_a_tuple_it_should_compare_its_property_for_e act.Should().NotThrow(); } + [Fact] + public void When_a_tuple_is_compared_it_should_compare_its_components() + { + // Arrange + var actual = new Tuple("Hello", true, new int[] { 3, 2, 1 }); + var expected = new Tuple("Hello", true, new int[] { 1, 2, 3 }); + + // Act + Action act = () => actual.Should().BeEquivalentTo(expected); + + // Assert + act.Should().NotThrow(); + } + #endregion #region Enums