예제 #1
0
        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());
        }
예제 #2
0
        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();
        }
예제 #3
0
        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());
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
        }
예제 #6
0
        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();
        }
예제 #7
0
        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());
        }