diff --git a/Src/FluentAssertions/Numeric/ByteAssertions.cs b/Src/FluentAssertions/Numeric/ByteAssertions.cs index 9f52c51fb4..94198140ef 100644 --- a/Src/FluentAssertions/Numeric/ByteAssertions.cs +++ b/Src/FluentAssertions/Numeric/ByteAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,10 +14,10 @@ internal ByteAssertions(byte value) { } - private protected override byte? CalculateDifferenceForFailureMessage(byte expected) + private protected override string CalculateDifferenceForFailureMessage(byte subject, byte expected) { - var difference = (byte?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/DecimalAssertions.cs b/Src/FluentAssertions/Numeric/DecimalAssertions.cs index 473fa3a164..69a9ebe924 100644 --- a/Src/FluentAssertions/Numeric/DecimalAssertions.cs +++ b/Src/FluentAssertions/Numeric/DecimalAssertions.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,12 +15,12 @@ internal DecimalAssertions(decimal value) { } - private protected override decimal? CalculateDifferenceForFailureMessage(decimal expected) + private protected override string CalculateDifferenceForFailureMessage(decimal subject, decimal expected) { try { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; + decimal difference = checked(subject - expected); + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } catch (OverflowException) { diff --git a/Src/FluentAssertions/Numeric/DoubleAssertions.cs b/Src/FluentAssertions/Numeric/DoubleAssertions.cs index 55692c3270..d75f09e911 100644 --- a/Src/FluentAssertions/Numeric/DoubleAssertions.cs +++ b/Src/FluentAssertions/Numeric/DoubleAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -15,10 +16,10 @@ internal DoubleAssertions(double value) private protected override bool IsNaN(double value) => double.IsNaN(value); - private protected override double? CalculateDifferenceForFailureMessage(double expected) + private protected override string CalculateDifferenceForFailureMessage(double subject, double expected) { - var difference = Subject - expected; - return difference != 0 ? difference : null; + var difference = subject - expected; + return difference != 0 ? difference.ToString("R", CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/Int16Assertions.cs b/Src/FluentAssertions/Numeric/Int16Assertions.cs index 6daa7c61a3..5d0961ba2c 100644 --- a/Src/FluentAssertions/Numeric/Int16Assertions.cs +++ b/Src/FluentAssertions/Numeric/Int16Assertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,15 +14,15 @@ internal Int16Assertions(short value) { } - private protected override short? CalculateDifferenceForFailureMessage(short expected) + private protected override string CalculateDifferenceForFailureMessage(short subject, short expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - var difference = (short?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/Int32Assertions.cs b/Src/FluentAssertions/Numeric/Int32Assertions.cs index 2c0bad1167..df0910e45c 100644 --- a/Src/FluentAssertions/Numeric/Int32Assertions.cs +++ b/Src/FluentAssertions/Numeric/Int32Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal Int32Assertions(int value) { } - private protected override int? CalculateDifferenceForFailureMessage(int expected) + private protected override string CalculateDifferenceForFailureMessage(int subject, int expected) { - if (Subject is > 0 and < 10 && expected is > 0 and < 10) + if (subject is > 0 and < 10 && expected is > 0 and < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + long difference = (long)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/Int64Assertions.cs b/Src/FluentAssertions/Numeric/Int64Assertions.cs index 58c079eada..d681163ed4 100644 --- a/Src/FluentAssertions/Numeric/Int64Assertions.cs +++ b/Src/FluentAssertions/Numeric/Int64Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal Int64Assertions(long value) { } - private protected override long? CalculateDifferenceForFailureMessage(long expected) + private protected override string CalculateDifferenceForFailureMessage(long subject, long expected) { - if (Subject is > 0 and < 10 && expected is > 0 and < 10) + if (subject is > 0 and < 10 && expected is > 0 and < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + decimal difference = (decimal)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableByteAssertions.cs b/Src/FluentAssertions/Numeric/NullableByteAssertions.cs index edb94b684d..ca5075ea8a 100644 --- a/Src/FluentAssertions/Numeric/NullableByteAssertions.cs +++ b/Src/FluentAssertions/Numeric/NullableByteAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,10 +14,10 @@ internal NullableByteAssertions(byte? value) { } - private protected override byte? CalculateDifferenceForFailureMessage(byte expected) + private protected override string CalculateDifferenceForFailureMessage(byte subject, byte expected) { - var difference = (byte?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableDecimalAssertions.cs b/Src/FluentAssertions/Numeric/NullableDecimalAssertions.cs index 8c79f7145f..4cfdca86f9 100644 --- a/Src/FluentAssertions/Numeric/NullableDecimalAssertions.cs +++ b/Src/FluentAssertions/Numeric/NullableDecimalAssertions.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,12 +15,12 @@ internal NullableDecimalAssertions(decimal? value) { } - private protected override decimal? CalculateDifferenceForFailureMessage(decimal expected) + private protected override string CalculateDifferenceForFailureMessage(decimal subject, decimal expected) { try { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; + decimal difference = checked(subject - expected); + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } catch (OverflowException) { diff --git a/Src/FluentAssertions/Numeric/NullableDoubleAssertions.cs b/Src/FluentAssertions/Numeric/NullableDoubleAssertions.cs index 084e0ea8d0..4e836ca6bb 100644 --- a/Src/FluentAssertions/Numeric/NullableDoubleAssertions.cs +++ b/Src/FluentAssertions/Numeric/NullableDoubleAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -15,10 +16,10 @@ internal NullableDoubleAssertions(double? value) private protected override bool IsNaN(double value) => double.IsNaN(value); - private protected override double? CalculateDifferenceForFailureMessage(double expected) + private protected override string CalculateDifferenceForFailureMessage(double subject, double expected) { - var difference = Subject - expected; - return difference != 0 ? difference : null; + double difference = subject - expected; + return difference != 0 ? difference.ToString("R", CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableInt16Assertions.cs b/Src/FluentAssertions/Numeric/NullableInt16Assertions.cs index 11d00d3c48..5d00f8332e 100644 --- a/Src/FluentAssertions/Numeric/NullableInt16Assertions.cs +++ b/Src/FluentAssertions/Numeric/NullableInt16Assertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,15 +14,15 @@ internal NullableInt16Assertions(short? value) { } - private protected override short? CalculateDifferenceForFailureMessage(short expected) + private protected override string CalculateDifferenceForFailureMessage(short subject, short expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - var difference = (short?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableInt32Assertions.cs b/Src/FluentAssertions/Numeric/NullableInt32Assertions.cs index f01cb6b35b..bfafe4afe6 100644 --- a/Src/FluentAssertions/Numeric/NullableInt32Assertions.cs +++ b/Src/FluentAssertions/Numeric/NullableInt32Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal NullableInt32Assertions(int? value) { } - private protected override int? CalculateDifferenceForFailureMessage(int expected) + private protected override string CalculateDifferenceForFailureMessage(int subject, int expected) { - if (Subject is > 0 and < 10 && expected is > 0 and < 10) + if (subject is > 0 and < 10 && expected is > 0 and < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + long difference = (long)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableInt64Assertions.cs b/Src/FluentAssertions/Numeric/NullableInt64Assertions.cs index e6dbce9df1..11e75f63e9 100644 --- a/Src/FluentAssertions/Numeric/NullableInt64Assertions.cs +++ b/Src/FluentAssertions/Numeric/NullableInt64Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal NullableInt64Assertions(long? value) { } - private protected override long? CalculateDifferenceForFailureMessage(long expected) + private protected override string CalculateDifferenceForFailureMessage(long subject, long expected) { - if (Subject is > 0 and < 10 && expected is > 0 and < 10) + if (subject is > 0 and < 10 && expected is > 0 and < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + decimal difference = (decimal)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableSByteAssertions.cs b/Src/FluentAssertions/Numeric/NullableSByteAssertions.cs index 5c3a8d11fc..c6dc825954 100644 --- a/Src/FluentAssertions/Numeric/NullableSByteAssertions.cs +++ b/Src/FluentAssertions/Numeric/NullableSByteAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,10 +14,10 @@ internal NullableSByteAssertions(sbyte? value) { } - private protected override sbyte? CalculateDifferenceForFailureMessage(sbyte expected) + private protected override string CalculateDifferenceForFailureMessage(sbyte subject, sbyte expected) { - var difference = (sbyte?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableSingleAssertions.cs b/Src/FluentAssertions/Numeric/NullableSingleAssertions.cs index b6fbd9f799..82ba336201 100644 --- a/Src/FluentAssertions/Numeric/NullableSingleAssertions.cs +++ b/Src/FluentAssertions/Numeric/NullableSingleAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -15,10 +16,10 @@ internal NullableSingleAssertions(float? value) private protected override bool IsNaN(float value) => float.IsNaN(value); - private protected override float? CalculateDifferenceForFailureMessage(float expected) + private protected override string CalculateDifferenceForFailureMessage(float subject, float expected) { - var difference = Subject - expected; - return difference != 0 ? difference : null; + float difference = subject - expected; + return difference != 0 ? difference.ToString("R", CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableUInt16Assertions.cs b/Src/FluentAssertions/Numeric/NullableUInt16Assertions.cs index fcf363b640..03ab0f1b25 100644 --- a/Src/FluentAssertions/Numeric/NullableUInt16Assertions.cs +++ b/Src/FluentAssertions/Numeric/NullableUInt16Assertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,15 +14,15 @@ internal NullableUInt16Assertions(ushort? value) { } - private protected override ushort? CalculateDifferenceForFailureMessage(ushort expected) + private protected override string CalculateDifferenceForFailureMessage(ushort subject, ushort expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - var difference = (ushort?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableUInt32Assertions.cs b/Src/FluentAssertions/Numeric/NullableUInt32Assertions.cs index 1c18e30afb..b4b220c6af 100644 --- a/Src/FluentAssertions/Numeric/NullableUInt32Assertions.cs +++ b/Src/FluentAssertions/Numeric/NullableUInt32Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal NullableUInt32Assertions(uint? value) { } - private protected override uint? CalculateDifferenceForFailureMessage(uint expected) + private protected override string CalculateDifferenceForFailureMessage(uint subject, uint expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + long difference = (long)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NullableUInt64Assertions.cs b/Src/FluentAssertions/Numeric/NullableUInt64Assertions.cs index 3eda339eb0..99c31fa0b1 100644 --- a/Src/FluentAssertions/Numeric/NullableUInt64Assertions.cs +++ b/Src/FluentAssertions/Numeric/NullableUInt64Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal NullableUInt64Assertions(ulong? value) { } - private protected override ulong? CalculateDifferenceForFailureMessage(ulong expected) + private protected override string CalculateDifferenceForFailureMessage(ulong subject, ulong expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + decimal difference = (decimal)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/NumericAssertions.cs b/Src/FluentAssertions/Numeric/NumericAssertions.cs index a103da0162..62d06e1d7d 100644 --- a/Src/FluentAssertions/Numeric/NumericAssertions.cs +++ b/Src/FluentAssertions/Numeric/NumericAssertions.cs @@ -6,7 +6,6 @@ using System.Linq.Expressions; using FluentAssertions.Common; using FluentAssertions.Execution; -using static System.FormattableString; namespace FluentAssertions.Numeric { @@ -486,23 +485,24 @@ public AndConstraint NotBeOfType(Type unexpectedType, string becaus /// /// A method to generate additional information upon comparison failures. /// + /// The current numeric value verified to be non-null. /// The value to compare the current numeric value with. /// /// Returns the difference between a number value and the value. /// Returns `null` if the compared numbers are small enough that a difference message is irrelevant. /// - private protected virtual T? CalculateDifferenceForFailureMessage(T expected) => null; + private protected virtual string CalculateDifferenceForFailureMessage(T subject, T expected) => null; private string GenerateDifferenceMessage(T? expected) { const string noDifferenceMessage = "."; - if (!Subject.HasValue || !expected.HasValue) + if (Subject is not T subject || expected is not T expectedValue) { return noDifferenceMessage; } - var difference = CalculateDifferenceForFailureMessage(expected.Value); - return difference is null ? noDifferenceMessage : Invariant($" (difference of {difference})."); + var difference = CalculateDifferenceForFailureMessage(subject, expectedValue); + return difference is null ? noDifferenceMessage : $" (difference of {difference})."; } } } diff --git a/Src/FluentAssertions/Numeric/SByteAssertions.cs b/Src/FluentAssertions/Numeric/SByteAssertions.cs index b45b8ba695..b7ebbc8686 100644 --- a/Src/FluentAssertions/Numeric/SByteAssertions.cs +++ b/Src/FluentAssertions/Numeric/SByteAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,10 +14,10 @@ internal SByteAssertions(sbyte value) { } - private protected override sbyte? CalculateDifferenceForFailureMessage(sbyte expected) + private protected override string CalculateDifferenceForFailureMessage(sbyte subject, sbyte expected) { - var difference = (sbyte?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/SingleAssertions.cs b/Src/FluentAssertions/Numeric/SingleAssertions.cs index ceecf183cb..876012cd09 100644 --- a/Src/FluentAssertions/Numeric/SingleAssertions.cs +++ b/Src/FluentAssertions/Numeric/SingleAssertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -15,10 +16,10 @@ internal SingleAssertions(float value) private protected override bool IsNaN(float value) => float.IsNaN(value); - private protected override float? CalculateDifferenceForFailureMessage(float expected) + private protected override string CalculateDifferenceForFailureMessage(float subject, float expected) { - var difference = Subject - expected; - return difference != 0 ? difference : null; + float difference = subject - expected; + return difference != 0 ? difference.ToString("R", CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/UInt16Assertions.cs b/Src/FluentAssertions/Numeric/UInt16Assertions.cs index b08824d4ba..db1fbb33c0 100644 --- a/Src/FluentAssertions/Numeric/UInt16Assertions.cs +++ b/Src/FluentAssertions/Numeric/UInt16Assertions.cs @@ -1,4 +1,5 @@ using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -13,15 +14,15 @@ internal UInt16Assertions(ushort value) { } - private protected override ushort? CalculateDifferenceForFailureMessage(ushort expected) + private protected override string CalculateDifferenceForFailureMessage(ushort subject, ushort expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - var difference = (ushort?)(Subject - expected); - return difference != 0 ? difference : null; + int difference = subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/UInt32Assertions.cs b/Src/FluentAssertions/Numeric/UInt32Assertions.cs index e18abeb342..fa64455b5d 100644 --- a/Src/FluentAssertions/Numeric/UInt32Assertions.cs +++ b/Src/FluentAssertions/Numeric/UInt32Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal UInt32Assertions(uint value) { } - private protected override uint? CalculateDifferenceForFailureMessage(uint expected) + private protected override string CalculateDifferenceForFailureMessage(uint subject, uint expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + long difference = (long)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Src/FluentAssertions/Numeric/UInt64Assertions.cs b/Src/FluentAssertions/Numeric/UInt64Assertions.cs index b55f3abecf..86c3366154 100644 --- a/Src/FluentAssertions/Numeric/UInt64Assertions.cs +++ b/Src/FluentAssertions/Numeric/UInt64Assertions.cs @@ -1,5 +1,5 @@ -using System; -using System.Diagnostics; +using System.Diagnostics; +using System.Globalization; namespace FluentAssertions.Numeric { @@ -14,22 +14,15 @@ internal UInt64Assertions(ulong value) { } - private protected override ulong? CalculateDifferenceForFailureMessage(ulong expected) + private protected override string CalculateDifferenceForFailureMessage(ulong subject, ulong expected) { - if (Subject < 10 && expected < 10) + if (subject < 10 && expected < 10) { return null; } - try - { - var difference = checked(Subject - expected); - return difference != 0 ? difference : null; - } - catch (OverflowException) - { - return null; - } + decimal difference = (decimal)subject - expected; + return difference != 0 ? difference.ToString(CultureInfo.InvariantCulture) : null; } } } diff --git a/Tests/FluentAssertions.Specs/Numeric/NumericDifferenceAssertionsSpecs.cs b/Tests/FluentAssertions.Specs/Numeric/NumericDifferenceAssertionsSpecs.cs index 0cb5979c56..3403a0bc1d 100644 --- a/Tests/FluentAssertions.Specs/Numeric/NumericDifferenceAssertionsSpecs.cs +++ b/Tests/FluentAssertions.Specs/Numeric/NumericDifferenceAssertionsSpecs.cs @@ -756,119 +756,119 @@ public void The_difference_between_ints_is_included_in_the_message() public class Overflow { [Fact] - public void The_difference_between_overflowed_ints_is_not_included_in_the_message() + public void The_difference_between_overflowed_ints_is_included_in_the_message() { // Act Action act = () => - int.MinValue.Should().Be(int.MaxValue, "because we want to test the failure {0}", "message"); + int.MinValue.Should().Be(int.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected int.MinValue to be 2147483647 because we want to test the failure message, but found -2147483648."); + .WithMessage("Expected int.MinValue to be 2147483647*found -2147483648 (difference of -4294967295)."); } [Fact] - public void The_difference_between_overflowed_nullable_ints_is_not_included_in_the_message() + public void The_difference_between_overflowed_nullable_ints_is_included_in_the_message() { // Arrange int? minValue = int.MinValue; // Act Action act = () => - minValue.Should().Be(int.MaxValue, "because we want to test the failure {0}", "message"); + minValue.Should().Be(int.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected minValue to be 2147483647 because we want to test the failure message, but found -2147483648."); + .WithMessage("Expected minValue to be 2147483647*found -2147483648 (difference of -4294967295)."); } [Fact] - public void The_difference_between_overflowed_uints_is_not_included_in_the_message() + public void The_difference_between_overflowed_uints_is_included_in_the_message() { // Act Action act = () => - uint.MinValue.Should().Be(uint.MaxValue, "because we want to test the failure {0}", "message"); + uint.MinValue.Should().Be(uint.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected uint.MinValue to be 4294967295u because we want to test the failure message, but found 0u."); + .WithMessage("Expected uint.MinValue to be 4294967295u*found 0u (difference of -4294967295)."); } [Fact] - public void The_difference_between_overflowed_nullable_uints_is_not_included_in_the_message() + public void The_difference_between_overflowed_nullable_uints_is_included_in_the_message() { // Arrange uint? minValue = uint.MinValue; // Act Action act = () => - minValue.Should().Be(uint.MaxValue, "because we want to test the failure {0}", "message"); + minValue.Should().Be(uint.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected minValue to be 4294967295u because we want to test the failure message, but found 0u."); + .WithMessage("Expected minValue to be 4294967295u*found 0u (difference of -4294967295)."); } [Fact] - public void The_difference_between_overflowed_longs_is_not_included_in_the_message() + public void The_difference_between_overflowed_longs_is_included_in_the_message() { // Act Action act = () => - long.MinValue.Should().Be(long.MaxValue, "because we want to test the failure {0}", "message"); + long.MinValue.Should().Be(long.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected long.MinValue to be 9223372036854775807L because we want to test the failure message, but found -9223372036854775808L."); + .WithMessage("Expected long.MinValue to be 9223372036854775807L*found -9223372036854775808L (difference of -18446744073709551615)."); } [Fact] - public void The_difference_between_overflowed_nullable_longs_is_not_included_in_the_message() + public void The_difference_between_overflowed_nullable_longs_is_included_in_the_message() { // Arrange long? minValue = long.MinValue; // Act Action act = () => - minValue.Should().Be(long.MaxValue, "because we want to test the failure {0}", "message"); + minValue.Should().Be(long.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected minValue to be 9223372036854775807L because we want to test the failure message, but found -9223372036854775808L."); + .WithMessage("Expected minValue to be 9223372036854775807L*found -9223372036854775808L (difference of -18446744073709551615)."); } [Fact] - public void The_difference_between_overflowed_ulongs_is_not_included_in_the_message() + public void The_difference_between_overflowed_ulongs_is_included_in_the_message() { // Act Action act = () => - ulong.MinValue.Should().Be(ulong.MaxValue, "because we want to test the failure {0}", "message"); + ulong.MinValue.Should().Be(ulong.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected ulong.MinValue to be 18446744073709551615UL because we want to test the failure message, but found 0UL."); + .WithMessage("Expected ulong.MinValue to be 18446744073709551615UL*found 0UL (difference of -18446744073709551615)."); } [Fact] - public void The_difference_between_overflowed_nullable_ulongs_is_not_included_in_the_message() + public void The_difference_between_overflowed_nullable_ulongs_is_included_in_the_message() { // Arrange ulong? minValue = ulong.MinValue; // Act Action act = () => - minValue.Should().Be(ulong.MaxValue, "because we want to test the failure {0}", "message"); + minValue.Should().Be(ulong.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected minValue to be 18446744073709551615UL because we want to test the failure message, but found 0UL."); + .WithMessage("Expected minValue to be 18446744073709551615UL*found 0UL (difference of -18446744073709551615)."); } [Fact] @@ -876,12 +876,12 @@ public void The_difference_between_overflowed_decimals_is_not_included_in_the_me { // Act Action act = () => - decimal.MinValue.Should().Be(decimal.MaxValue, "because we want to test the failure {0}", "message"); + decimal.MinValue.Should().Be(decimal.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected decimal.MinValue to be 79228162514264337593543950335M because we want to test the failure message, but found -79228162514264337593543950335M."); + .WithMessage("Expected decimal.MinValue to be 79228162514264337593543950335M*found -79228162514264337593543950335M."); } [Fact] @@ -892,12 +892,12 @@ public void The_difference_between_overflowed_nullable_decimals_is_not_included_ // Act Action act = () => - minValue.Should().Be(decimal.MaxValue, "because we want to test the failure {0}", "message"); + minValue.Should().Be(decimal.MaxValue); // Assert act .Should().Throw() - .WithMessage("Expected minValue to be 79228162514264337593543950335M because we want to test the failure message, but found -79228162514264337593543950335M."); + .WithMessage("Expected minValue to be 79228162514264337593543950335M*found -79228162514264337593543950335M."); } } }