question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DateTime Should().BeLessThan(...).After(b) not check After

See original GitHub issue

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.

https://github.com/fluentassertions/fluentassertions/blob/0a37562a3eebc9a3269a8f5965259cdc170306c8/Src/FluentAssertions/Primitives/DateTimeRangeAssertions.cs#L75-L80

https://github.com/fluentassertions/fluentassertions/blob/0a37562a3eebc9a3269a8f5965259cdc170306c8/Src/FluentAssertions/Primitives/DateTimeRangeAssertions.cs#L116-L121

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jonathann92commented, Apr 19, 2020

@jnyrup @dennisdoomen

I’ve created a PR for this request. Can you take a look whenever you guys get a chance?

#1313

1reaction
jnyrupcommented, Apr 16, 2020

@jonathann92 To our knowledge no one is working on this issue, but we’re open to contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues
DateTimeAssertions.BeWithin and BeLessThan do not work if date is on the opposite side of reference date in .Before/.After #1467.
Read more >
c# - Fluent Assertions: Using BeCloseTo on a collection of ...
As a direct answer to your question, you can do something like items.Should().OnlyContain(i => (i - DateTime.Now) < TimeSpan.FromMilliseconds( ...
Read more >
Tips - Fluent Assertions
By having Should() as early as possible in the assertion, we are able to include more information in the failure messages.
Read more >
datetime — Basic date and time types
A datetime object d is aware if both of the following hold: d.tzinfo is not None. d.tzinfo.utcoffset(d) does not return None. Otherwise, d...
Read more >
Fluent Assertions - RSSing.com
As explained in this article, floating point variables are inheritably inaccurate and should never be compared for equality. Instead, either use the Should()....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found