Skip to content

Commit

Permalink
xunit/xunit#2913: Assert.Equivalent behaves incorrectly with decimal …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
bradwilson committed Apr 9, 2024
1 parent 1c6ea08 commit 884e685
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Sdk/AssertHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma warning disable CS8603
#pragma warning disable CS8604
#pragma warning disable CS8621
#pragma warning disable CS8625
#endif

using System;
Expand Down Expand Up @@ -266,8 +267,16 @@ static IEnumerable<T> ToEnumerableImpl<T>(IAsyncEnumerable<T> data)
out object converted)
#endif
{
converted = Convert.ChangeType(value, targetType, CultureInfo.CurrentCulture);
return converted != null;
try
{
converted = Convert.ChangeType(value, targetType, CultureInfo.CurrentCulture);
return converted != null;
}
catch (InvalidCastException)
{
converted = null;
return false;
}
}

#if XUNIT_NULLABLE
Expand Down Expand Up @@ -335,7 +344,7 @@ static IEnumerable<T> ToEnumerableImpl<T>(IAsyncEnumerable<T> data)
var actualTypeInfo = actualType.GetTypeInfo();

// Primitive types, enums and strings should just fall back to their Equals implementation
if (expectedTypeInfo.IsPrimitive || expectedTypeInfo.IsEnum || expectedType == typeof(string))
if (expectedTypeInfo.IsPrimitive || expectedTypeInfo.IsEnum || expectedType == typeof(string) || expectedType == typeof(decimal))
return VerifyEquivalenceIntrinsics(expected, actual, prefix);

// DateTime and DateTimeOffset need to be compared via IComparable (because of a circular
Expand Down

0 comments on commit 884e685

Please sign in to comment.