public void GivenNumbersEqual_AndDontAllowEquality_AndValidationContext_WhenValidate_ThenThrowException() { TestEntity toValidate = new TestEntity { Value = "20" }; ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" }; var target = new NumericLessThanAttribute("Value") { AllowEquality = false }; ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("20", validationContext)); Assert.AreEqual("AllowEquality has been set to false so values cannot be equal.", actual.Message); }
public void GivenInvalidValue_AndValidationContext_WhenValidate_ThenThrowException() { TestEntity toValidate = new TestEntity { Value = "blah" }; ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" }; var target = new NumericLessThanAttribute("Value"); ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("20", validationContext)); Assert.AreEqual("Value is not a numeric value.", actual.Message); }
public void GivenInvalidProperty_AndValidationContext_WhenValidate_ThenThrowException() { TestEntity toValidate = new TestEntity { Value = "10" }; ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" }; var target = new NumericLessThanAttribute("blah"); ValidationException actual = target.ExpectException <ValidationException>(() => target.Validate("10", validationContext)); Assert.AreEqual("Could not find a property named blah.", actual.Message); }
public void GivenPropertyIsGreaterThan_AndValidationContext_WhenValidate_ThenThrowException() { TestEntity toValidate = new TestEntity { Value = "10" }; ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" }; var target = new NumericLessThanAttribute("Value"); ValidationException actual = target.ExpectException <ValidationException>(() => target.Validate("20", validationContext)); Assert.AreEqual("Test Entity Value must be less than Value.", actual.Message); }
public void GivenNumbersEqual_AndDontAllowEquality_AndValidationContext_WhenValidate_ThenThrowException() { TestEntity toValidate = new TestEntity { Value = "20" }; ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" }; var target = new NumericLessThanAttribute("Value") { AllowEquality = false }; ValidationException actual = target.ExpectException <ValidationException>(() => target.Validate("20", validationContext)); Assert.AreEqual("AllowEquality has been set to false so values cannot be equal.", actual.Message); }
public void GivenPropertyIsGreaterThan_AndAllowEquality_AndValidationContext_WhenValidate_ThenThrowExceptionWithEqualityMessage() { TestEntity toValidate = new TestEntity { Value = "10" }; ValidationContext validationContext = new ValidationContext(toValidate) { DisplayName = "Test Entity Value", MemberName = "Value" }; var target = new NumericLessThanAttribute("Value") { AllowEquality = true }; ValidationException actual = target.ExpectException<ValidationException>(() => target.Validate("20", validationContext)); Assert.AreEqual("Test Entity Value must be less than or equal to Value.", actual.Message); }