DateTimeOffset?.Should().BeCloseTo(...)
See original GitHub issueIt 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:
- Created 4 years ago
- Comments:17 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did, now I need to convince @jnyrup 😉
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)