Created
June 29, 2025 02:32
-
-
Save AldeRoberge/5e413fbc68c60e760b421f3db7a785dc to your computer and use it in GitHub Desktop.
Adds Shouldly shoulds for DateTime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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