Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Closed Issue: Fluent assertions v1.7.1 fails to compare nullable timespans [12462]

$
0
0
Not tested with latest version. It seems that an overload on SimpleTimeSpanAssertions which accepts a Nullable<TimeSpan> is missing. I was able to work around this by writing the next extension method:

public static class SimpleTimeSpanAssertionsExtensions
{
// The current version of Fluent Assertions (v1.7.1) seems unable to compare nullable timespans.
// Example: myObject.OptionalTime.Should().Be(expectedOptionalTime);
// This method implements a workaround for this problem.
public static void Be(this SimpleTimeSpanAssertions source, TimeSpan? expected)
{
if (expected == null)
{
source.Subject.As<object>().Should().BeNull();
}
else
{
source.Subject.Should().Be(expected.Value);
}
}
}

I am aware that the return type should not be void and that this method does not have parameters for describing the error. But for the moment it fixes my problem at hand.

Best regards,
Bart Koelman
Comments: Continued at https://github.com/dennisdoomen/fluentassertions/issues/5

Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>