-
Notifications
You must be signed in to change notification settings - Fork 53
DateTime checks
Checks that the sut is equal to the expected DateTime, disregarding milliseconds.
var sut = new DateTime(2018, 2, 6, 9, 18, 12, 152);
// This check succeeds
Check.That(sut).IsEqualToIgnoringMilliseconds(new DateTime(2018, 2, 6, 9, 18, 12, 870));
// This check fails
Check.That(sut).IsEqualToIgnoringMilliseconds(new DateTime(2018, 2, 6, 9, 18, 13, 152));
Checks that the sut is equal to the expected DateTime, disregarding seconds.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsEqualToIgnoringSeconds(new DateTime(2018, 2, 6, 9, 18, 15));
// This check fails
Check.That(sut).IsEqualToIgnoringSeconds(new DateTime(2018, 2, 6, 9, 17, 12));
Checks that the sut is equal to the expected DateTime, disregarding minutes.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsEqualToIgnoringMinutes(new DateTime(2018, 2, 6, 9, 17, 15));
// This check fails
Check.That(sut).IsEqualToIgnoringMinutes(new DateTime(2018, 2, 6, 8, 18, 12));
Checks that the sut is equal to the expected DateTime, disregarding minutes.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsEqualToIgnoringHours(new DateTime(2018, 2, 6, 8, 17, 15));
// This check fails
Check.That(sut).IsEqualToIgnoringHours(new DateTime(2018, 2, 7, 9, 18, 12));
Checks that sut has the same month as expected; fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsSameDayAs(new DateTime(2014, 11, 6, 8, 17, 15));
// This check fails
Check.That(sut).IsSameDayAs(new DateTime(2018, 2, 7, 9, 18, 12));
Checks that sut has the same day of month as expected; fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsSameMonthAs(new DateTime(2014, 2, 12, 8, 17, 15));
// This check fails
Check.That(sut).IsSameMonthAs(new DateTime(2018, 6, 7, 9, 18, 12));
Checks that sut has the same year as expected; fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsSameYearAs(new DateTime(2018, 11, 6, 8, 17, 15));
// This check fails
Check.That(sut).IsSameYearAs(new DateTime(2014, 2, 7, 9, 18, 12));
Checks that sut is close to the expected date time, within +/- tolerance. The tolerance can be a Timespan or a Duration.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsCloseTo(new DateTime(2018, 2, 6, 9, 18, 15), new Duration(5, TimeUnit.Minutes));
// This check succeeds
Check.That(sut).IsCloseTo(new DateTime(2018, 2, 6, 9, 18, 15), TimeSpan.FromMinutes(5));
// This check fails
Check.That(sut).IsCloseTo(new DateTime(2018, 2, 6, 9, 18, 02), new Duration(5, TimeUnit.Minutes));
Checks that the sut represents a date time earlier than reference, fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsBefore(new DateTime(2018, 11, 6, 8, 17, 15);
// This check fails
Check.That(sut).IsBefore(new DateTime(2014, 2, 5, 9, 18, 12);
Checks that the sut represents a date time later than reference, fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// This check succeeds
Check.That(sut).IsAfter(new DateTime(2018, 2, 5, 8, 17, 15);
// This check fails
Check.That(sut).IsAfter(new DateTime(2014, 2, 8, 9, 18, 12);
Checks that the sut represents a date time earlier than reference, fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// Those checks succeed
Check.That(sut).IsBeforeOrEqualTo(new DateTime(2018, 11, 6, 8, 17, 15);
Check.That(sut).IsBeforeOrEqualTo(new DateTime(018, 2, 6, 9, 18, 12);
// This check fails
Check.That(sut).IsBeforeOrEqualTo(new DateTime(2014, 2, 5, 9, 18, 12);
Checks that the sut represents a date time later than reference, fails otherwise.
var sut = new DateTime(2018, 2, 6, 9, 18, 12);
// Those checks succeed
Check.That(sut).IsAfterOrEqualTo(new DateTime(2018, 2, 5, 8, 17, 15);
Check.That(sut).IsAfterOrEqualTo(new DateTime(2018, 2, 6, 9, 18, 12);
// This check fails
Check.That(sut).IsAfterOrEqualTo(new DateTime(2014, 2, 8, 9, 18, 12);
- Welcome
- How to start
- Customising error messages
-
Check.That
- All (Equality, Type)
- Reference types
- Members based
- IEnumerable (Properties, Content, Elements)
- String (Properties, Content, RegExp )
- Numeric Type(Properties, Comparisons, Floating)
- Dictionary
- Char (Properties, Value)
- IComparable
- DateTime
- DateTimeOffset
- Misc: Boolean, TimeSpan, Stream, Enum, EventWaitHandle
- Check.ThatCode
- Check.ThatDynamic
- Extensibility
- Auxiliary types (TimeUnit)
- Mocks