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.

Add `DateTime.Should().Be(DateTime?)` and `DateTimeOffset.Should().Be(DateTimeOffset?)` overloads

See original GitHub issue

Description

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: image

Nullable: image

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:closed
  • Created 3 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisdoomencommented, Nov 7, 2020

Ah, yes, now I get it.

0reactions
facundo91commented, Nov 16, 2020

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 expected result
16/11/2020 16/11/2020 true
16/11/2020 null false
null 16/11/2020 false
null null true

subject.NotBe(expected)

subject expected result
16/11/2020 16/11/2020 false
16/11/2020 null true
null 16/11/2020 true
null null false
Read more comments on GitHub >

github_iconTop 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 >

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