Beispiel #1
0
        public void WhenValueToday_ValidationSucceeds()
        {
            var validator = new PastDateAttribute();

            var instance = new object();

            var datetime = (DateTime?)DateTime.UtcNow;

            var context             = new ValidationContext(instance, null, null);
            ValidationResult result = validator.GetValidationResult(datetime, context);

            Assert.Same(ValidationResult.Success, result);
        }
Beispiel #2
0
        public void WhenValueFuture_ValidationFails()
        {
            var validator = new PastDateAttribute();

            var instance = new object();

            var datetime = (DateTime?)DateTime.UtcNow.AddDays(2);

            var context = new ValidationContext(instance, null, null);

            context.MemberName = "MyDate";
            ValidationResult result = validator.GetValidationResult(datetime, context);

            Assert.NotSame(ValidationResult.Success, result);
            Assert.NotNull(result.ErrorMessage);
        }