Table of Contents

Class DateTimeOffsetAssertions

Namespace
TimeAssertions.TUnit
Assembly
TimeAssertions.TUnit.dll

TimeProvider-aware DateTimeOffset assertions for recency / past / future checks against a (possibly fake) clock. TUnit core already provides IsInPast() / IsInFuture() using Now; these complement them with explicit TimeProvider injection so Microsoft.Extensions.Time.Testing.FakeTimeProvider-driven tests can verify time-relative state deterministically.

public static class DateTimeOffsetAssertions
Inheritance
DateTimeOffsetAssertions
Inherited Members

Methods

IsAfterNow(DateTimeOffset, TimeProvider)

Asserts that the timestamp is strictly after the TimeProvider's notion of "now". Distinct from TUnit core's IsInFuture() in that the comparison source is explicit (suitable for Microsoft.Extensions.Time.Testing.FakeTimeProvider-driven tests).

[GenerateAssertion(ExpectationMessage = "to be strictly after the supplied time provider's UTC now", InlineMethodBody = true)]
public static bool IsAfterNow(this DateTimeOffset value, TimeProvider timeProvider)

Parameters

value DateTimeOffset
timeProvider TimeProvider

Returns

bool

IsBeforeNow(DateTimeOffset, TimeProvider)

Asserts that the timestamp is strictly before the TimeProvider's notion of "now". Distinct from TUnit core's IsInPast() in that the comparison source is explicit (suitable for Microsoft.Extensions.Time.Testing.FakeTimeProvider-driven tests).

[GenerateAssertion(ExpectationMessage = "to be strictly before the supplied time provider's UTC now", InlineMethodBody = true)]
public static bool IsBeforeNow(this DateTimeOffset value, TimeProvider timeProvider)

Parameters

value DateTimeOffset
timeProvider TimeProvider

Returns

bool

IsRecent(DateTimeOffset, TimeSpan, TimeProvider?)

Asserts that the timestamp is within the last window of the TimeProvider's notion of "now". When timeProvider is null, System is used. Returns false for timestamps in the future relative to "now".

[GenerateAssertion(ExpectationMessage = "to be within the last {window} relative to the supplied time provider", InlineMethodBody = true)]
public static bool IsRecent(this DateTimeOffset value, TimeSpan window, TimeProvider? timeProvider = null)

Parameters

value DateTimeOffset

The timestamp under test.

window TimeSpan

The recency window. Must be non-negative.

timeProvider TimeProvider

The time source to compare against, or null to use System.

Returns

bool