Skip to content

Instantly share code, notes, and snippets.

@AldeRoberge
Created June 29, 2025 02:32
Show Gist options
  • Save AldeRoberge/5e413fbc68c60e760b421f3db7a785dc to your computer and use it in GitHub Desktop.
Save AldeRoberge/5e413fbc68c60e760b421f3db7a785dc to your computer and use it in GitHub Desktop.
Adds Shouldly shoulds for DateTime.
using Shouldly;
namespace ADG.Server.AppHost.Tests.Utilities;
public static class DateTimeTestingExtensions
{
public static void ShouldBeAfter(this DateTime actual, DateTime expected)
{
if (actual <= expected)
throw new ShouldAssertException($"Expected {actual} to be after {expected}");
}
public static void ShouldBeAfter(this TimeSpan actual, TimeSpan expected)
{
if (actual <= expected)
throw new ShouldAssertException($"Expected {actual} to be after {expected}");
}
public static void ShouldBeAfter(this DateTime actual, TimeSpan expected)
{
if (actual <= DateTime.UtcNow.Add(expected))
throw new ShouldAssertException($"Expected {actual} to be after {DateTime.UtcNow.Add(expected)}");
}
public static void ShouldBeAfter(this TimeSpan actual, DateTime expected)
{
if (actual <= expected - DateTime.UtcNow)
throw new ShouldAssertException($"Expected {actual} to be after {expected - DateTime.UtcNow}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment