public async Task UtcDateAfterNowIsNotValidIfMoreThanAllowedSkew() { var clock = new FakeClock(Instant.FromUtc(2015, 2, 2, 12, 0)); var validDate = new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Utc).AddSeconds(DateTimeIsNowOrEarlierValidator.SkewAllowanceSeconds + 1); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().Contain(e => e.Code == ErrorCode.InvalidValue.ToString()); }
public async Task UtcDateAfterNowIsValidIfWithinSkew() { var clock = new FakeClock(Instant.FromUtc(2015, 2, 2, 12, 0)); var validDate = new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Utc).AddSeconds(DateTimeIsNowOrEarlierValidator.SkewAllowanceSeconds); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().BeEmpty(); }
public async Task NullableUnspecifiedDateBeforeNowIsNotValid() { var clock = new FakeClock(Instant.FromUtc(2015, 2, 2, 12, 0)); var validDate = (DateTime?)new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Unspecified); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().Contain(e => e.Code == ErrorCode.InvalidValue.ToString()); }
public async Task UtcDateBeforeNowIsValid() { var clock = new FakeClock(Instant.FromUtc(2015, 2, 2, 12, 0)); var validDate = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Utc); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().BeEmpty(); }
public async Task LocalDateAfterNowIsValidIfWithinSkew() { var clockDate = new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Local); var clockLocal = LocalDateTime.FromDateTime(clockDate); var clockZoned = clockLocal.InZoneStrictly(DateTimeZoneProviders.Tzdb.GetSystemDefault()); var clock = new FakeClock(clockZoned.ToInstant()); var validDate = new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Local).AddSeconds(DateTimeIsNowOrEarlierValidator.SkewAllowanceSeconds); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().BeEmpty(); }
public async Task LocalDateBeforeNowIsValid() { var clockDate = new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Local); var clockLocal = LocalDateTime.FromDateTime(clockDate); var clockZoned = clockLocal.InZoneStrictly(DateTimeZoneProviders.Tzdb.GetSystemDefault()); var clock = new FakeClock(clockZoned.ToInstant()); var validDate = new DateTime(2015, 1, 1, 0, 0, 0, DateTimeKind.Local); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().BeEmpty(); }
public async Task NullableLocalDateAfterNowIsNotValidIfMoreThanAllowedSkew() { var clockDate = new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Local); var clockLocal = LocalDateTime.FromDateTime(clockDate); var clockZoned = clockLocal.InZoneStrictly(DateTimeZoneProviders.Tzdb.GetSystemDefault()); var clock = new FakeClock(clockZoned.ToInstant()); var validDate = (DateTime?)new DateTime(2015, 2, 2, 12, 0, 0, DateTimeKind.Local).AddSeconds(DateTimeIsNowOrEarlierValidator.SkewAllowanceSeconds + 1); var validator = new FakeDateTimeValidator(clock); var actual = await validator.ValidateAsync(validDate); actual.Should().Contain(e => e.Code == ErrorCode.InvalidValue.ToString()); }