public void WhenValueToday_ValidationSucceeds() { var validator = new FutureDateAttribute(); 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); }
public void WhenValueInPast_ValidationFails() { var validator = new FutureDateAttribute(); 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); }