public void InvalidIfValueIsNullOrEmptyString() { var model = new Mock { Property = "value" }; var context = new ValidationContext(model); var attr = new RequiredIfAttribute("Property", "value"); var result = attr.GetValidationResult(" ", context); Assert.Equal("'Mock' is required because 'Property' has a value 'value'.", result.ErrorMessage); result = attr.GetValidationResult(null, context); Assert.Equal("'Mock' is required because 'Property' has a value 'value'.", result.ErrorMessage); }
public void ShallThrowIfValidationContextIsNull() { var attr = new RequiredIfAttribute("test", "value"); Assert.Throws <ArgumentNullException>(() => { attr.GetValidationResult("value", null); }); }
public void SuccessfulValidationWithoutTargetedValue() { var model = new Mock { Property = "not the expected target" }; var context = new ValidationContext(model); var attr = new RequiredIfAttribute("Property", "value"); var result = attr.GetValidationResult("value", context); Assert.Equal(ValidationResult.Success, result); }
public void ShallThrowIfPropertyIsNotFound() { var model = new Mock { Property = null }; var context = new ValidationContext(model); var attr = new RequiredIfAttribute("UnknownProperty", "value"); Assert.Throws <ArgumentNullException>(() => { attr.GetValidationResult("value", context); }); }