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.

DateTimeOffset?.Should().BeCloseTo(...)

See original GitHub issue

It would be helpful to have .Should().BeCloseTo(...) available for DateTimeOffset? (nullable).

Currently I’ve had to do:

if (request.PreferredAt == null)
{
    response.PreferredAt.Should().BeNull();
}
else
{
    request.PreferredAt.Should()
        .BeCloseTo(response.PreferredAt.Value, TestConstants.MaxAllowedClockDriftMs);
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
dennisdoomencommented, Sep 11, 2019

I did, now I need to convince @jnyrup 😉

1reaction
ajeckmanscommented, Jul 15, 2021

I went with a similar approach to @eFse7en, but I always check that either both nearbyTime and subject are null or both are not null, and then just continue with the normal becloseto.

In my use case the nearbytime (expectation) can be null, because I’m comparing lists of graphs against each other. In some of the expected graphs there are nullable datetimeoffsets that should be null, but in other cases not. And AFAIK there is no support for or-conditions like “value.Should().BeNull().Or().Be(1)” in FluentAssertions (though it would be awesome if it was possible in an intuitive way)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dates & Times
To assert that a date/time is (not) within a specified time span from another date/time value you can use this method. theDatetime.Should().BeCloseTo(1.March ...
Read more >
c# - Fluent Assertions: Using BeCloseTo on a collection of ...
You can do this in 3.5 by configuring the options to ShouldBeEquivalentTo . For example: result.ShouldBeEquivalentTo(expected, options ...
Read more >
How to Check if Two DateTimes Are Close in Fluent Assertions
Luckily for us, Fluent Assertions allows us to modify the equivalency comparison behaviour and we can use the BeCloseTo() method with an ...
Read more >
Assertions comparing objects with difference in the datetime
Hi, Im currently comparing an object with below Should().ContainEquivalentOf(myObj, options => options.Excluding(person => person.
Read more >
105091: DateTimeOffset is Inappropriately Shifted on ...
DateTimeOffset.Should().BeCloseTo(now, 30_000); // fails due to invalid shift ``` Suggested fix: DateTimeOffset should deserialize using the UTC ...
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