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); }
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); }
public void PastDateAttribute_Returns_True_When_Date_Is_In_Past() { //Arrange var entryRequest = new EntryRequest { EntryTime = DateTime.Now.AddHours(-1), ExitTime = DateTime.Now, RegistrationNo = "Test" }; var pastDateAttribute = new PastDateAttribute(); // Act var result = pastDateAttribute.IsValid(entryRequest.EntryTime); //Assert Assert.IsTrue(result); }