You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
System.ArgumentException : Both arguments must be DateTime, DateTimeOffset or TimeSpan
at NUnit.Framework.Constraints.DateTimes.Difference(Object x, Object y)
at NUnit.Framework.Internal.TextMessageWriter.WriteDifferenceLine(Object expected, Object actual, Tolerance tolerance)
at NUnit.Framework.Internal.TextMessageWriter.DisplayDifferences(Object expected, Object actual, Tolerance tolerance)
at NUnit.Framework.Constraints.EqualConstraintResult.DisplayDifferences(MessageWriter writer, Object expected, Object actual, Int32 depth)
at NUnit.Framework.Constraints.EqualConstraintResult.WriteMessageTo(MessageWriter writer)
at NUnit.Framework.Assert.ReportFailure(ConstraintResult result, String message, Object[] args)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.That[TActual](TActual actual, IResolveConstraint expression)
at MyUnitTests.DatesShouldBeTheSame(Nullable`1 value, Nullable`1 expectedDateTime, Int32 toleranceInSeconds) in ...
The exception happens when the "Off by:" is calculated. It seems DateTimes.Difference does not consider/expect that one of the values might be null.
internalstaticobjectDifference(object?x,object?y){if(xisDateTimexDateTime&&yisDateTimeyDateTime)return(xDateTime-yDateTime).Duration();if(xisTimeSpanxTimeSpan&&yisTimeSpanyTimeSpan)return(xTimeSpan-yTimeSpan).Duration();if(xisDateTimeOffsetxDateTimeOffset&&yisDateTimeOffsetyDateTimeOffset)return(xDateTimeOffset-yDateTimeOffset).Duration();thrownewArgumentException("Both arguments must be DateTime, DateTimeOffset or TimeSpan");}
Is this the intended behavior? It would be nice if Within could support DateTime? as well. The message could simply omit the "Off by:" part and just read
Expected: 2023-01-01 13:00:00 +/- 00:00:10
But was: null
The text was updated successfully, but these errors were encountered:
We tried to compare
Nullable<DateTime>
with a tolerance usingWithin
. If the actual value is null, we get an ArgumentException.Example:
Callstack:
The exception happens when the "Off by:" is calculated. It seems DateTimes.Difference does not consider/expect that one of the values might be null.
Is this the intended behavior? It would be nice if
Within
could supportDateTime?
as well. The message could simply omit the "Off by:" part and just readThe text was updated successfully, but these errors were encountered: