public void DateTimeRangeAttribute_IsValid_returns_the_expected_result(string value, bool expectedResult) { var dateTimeValue = DateTime.Parse(value); var dateTimeRangeAttribute = new DateTimeRangeAttribute("1900-01-01", "1999-12-31 23:59:59"); dateTimeRangeAttribute.IsValid(dateTimeValue).Should().Be(expectedResult); }
public void DateTimeRangeAttribute_FormattedErrorMessage_returns_the_expected_result(string memberName, string minimum, string maximum) { var dateTimeRangeAttribute = new DateTimeRangeAttribute(minimum, maximum); var expectedResult = string.Format(CultureInfo.CurrentCulture, "The field {0} must be between {1} and {2}.", memberName, DateTime.Parse(minimum), DateTime.Parse(maximum)); dateTimeRangeAttribute.FormatErrorMessage(memberName).Should().Be(expectedResult); }
public void DateTimeRangeAttribute_IsValid_throws_for_non_datetime_values(object value) { var dateTimeRangeAttribute = new DateTimeRangeAttribute("1900-01-01", "1999-12-31 23:59:59"); Invoking(() => dateTimeRangeAttribute.IsValid(value)) .Should() .Throw <InvalidCastException>() .WithMessage(@"The [DateTimeRange] attribute must be used on a DateTime member. [MemberName: """"]"); }
public void DateTimeRangeAttribute_IsValid_returns_true_for_a_null_value() { var dateTimeRangeAttribute = new DateTimeRangeAttribute("1900-01-01", "1999-12-31 23:59:59"); dateTimeRangeAttribute.IsValid(null).Should().Be(true); }