Add `DateTime.Should().Be(DateTime?)` and `DateTimeOffset.Should().Be(DateTimeOffset?)` overloads
See original GitHub issueDescription
Some overloads of Be
for primitive types have a nullable version to facilitate calling them against standard and nullable versions of the value. For example:
Normal:
Nullable:
However, these nullable overloads do not exist currently for both DateTime
and DateTimeOffset
.
I propose the overloads be added to help with testing these types of properties and for consistency in the FluentAssertions API.
Expected behavior:
2 overloads be added, one for DateTime
and another for DateTimeOffset
, allowing to compare (Be
) with their nullable counterparts. When the values are null
, the assertion should obviously fail.
Actual behavior:
Overloads do not exist, forcing extra logic inside assertions to get the .Value
.
Versions
- FluentAssertions 5.10.3
- Net Core 3.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Add `DateTime.Should().Be(DateTime?)` ...
Expected behavior: 2 overloads be added, one for DateTime and another for DateTimeOffset, allowing to compare (Be) with their nullable ...
Read more >Converting between DateTime and DateTimeOffset
The method's single parameter is the DateTime value that represents the date and time to be converted. If the time zone supports daylight...
Read more >Instantiating a DateTimeOffset object
Read how to instantiate (make an instance of) a DateTimeOffset object in .NET. Learn about date & time literals, constructors, implicit type ...
Read more >c# - Change DateTimeOffset.Offset Property?
I would parse from JS normally, then do the following: Strip OffSet from DateTimeOffset by returning DateTime; Set OffSet by instantiating ...
Read more >c# - parsing a datetime with timezone to DateTimeOffset ...
With Parse() you should use the overload that takes a DateTimeStyles value. Then you can control how time zones are handled (e.g. DateTimeStyles...
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
Ah, yes, now I get it.
To mimic the behavior of NumericAssertions. I have added the cases marked in bold to DateTimeAssertions and DateTimeOffsetAssertions. Below examples are for Datetime, but same logic was followed for DatetimeOffset.
subject.Be(expected)
subject.NotBe(expected)