0
var dte = "2021-12-18T15:06:33.2677927Z"
dte.Should(). 

I want to check that this dte is not empty.

Currently I am using :

dte.Should().BeAfter(new DateTime());
Fabio
  • 31,528
  • 4
  • 33
  • 72
purplized
  • 61
  • 1
  • 7

1 Answers1

0

From the example, your definition of an "empty" DateTime seems to be one different from the default value.

If you're looking for a more readable/idiomatic way to express that, I would go with

DateTime subject = MethodUnderTest();
subject.Should().NotBe(default);

For the general case, one cannot speak of an "empty" DateTime since even the default value is just the minimum representable valid datetime, namely 0001-01-01T00:00:00.

So all of these are identical.

  • DateTime.Parse("0001-01-01T00:00:00")
  • default(DateTime)
  • new DateTime()
  • DateTime.MinValue
  • DateTime.FromBinary(0)
Jonas Nyrup
  • 2,376
  • 18
  • 25