-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Labels
Description
Hello!
It seems strange for me that DateTimeAssertions works in this way:
[Test]
public void Test_before_and_after()
{
var a = new DateTime(2019, 01, 01, 12, 0, 0, DateTimeKind.Utc);
var b = new DateTime(2019, 01, 01, 12, 30, 0, DateTimeKind.Utc);
a.Should().BeLessThan(1.Hours()).Before(b);
a.Should().BeLessThan(1.Hours()).After(b);
}These methods check that difference is less than value, and it is true when difference is negative. But is not correct to say that a is less than an hour after b when a - b == -30.Minutes()
I think there should be assertion that difference (TimeSpan actual) should be not negative in methods DateTimeRangeAssertions.Before and DateTimeRangeAssertions.After.
fluentassertions/Src/FluentAssertions/Primitives/DateTimeRangeAssertions.cs
Lines 75 to 80 in 0a37562
| TimeSpan actual = target - subject.Value; | |
| if (!predicate.IsMatchedBy(actual, timeSpan)) | |
| { | |
| Execute.Assertion | |
| .BecauseOf(because, becauseArgs) |
fluentassertions/Src/FluentAssertions/Primitives/DateTimeRangeAssertions.cs
Lines 116 to 121 in 0a37562
| TimeSpan actual = subject.Value - target; | |
| if (!predicate.IsMatchedBy(actual, timeSpan)) | |
| { | |
| Execute.Assertion | |
| .BecauseOf(because, becauseArgs) |
jon-is-me