Skip to content

Commit

Permalink
BeEquivalentTo on normal tuples should use structural equivalency (#1206
Browse files Browse the repository at this point in the history
)

Unlinke ValueTuple<>, the older Tuple<> was treated as a value type instead of something that requires a structural equality check.
  • Loading branch information
dennisdoomen committed Dec 18, 2019
1 parent 1a87adb commit f60927f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Src/FluentAssertions/Common/TypeExtensions.cs
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions Tests/Shared.Specs/BasicEquivalencySpecs.cs
Expand Up @@ -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<string, bool, int[]>("Hello", true, new int[] { 3, 2, 1 });
var expected = new Tuple<string, bool, int[]>("Hello", true, new int[] { 1, 2, 3 });

// Act
Action act = () => actual.Should().BeEquivalentTo(expected);

// Assert
act.Should().NotThrow();
}

#endregion

#region Enums
Expand Down

0 comments on commit f60927f

Please sign in to comment.