public void GetValue(object item, bool expected) { //Arrange var testModel = new TestModel(); //Act var value = IsDefaultValue.Value(item); //Assert Assert.AreEqual(expected, value); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (!IsDefaultValue.Value(value)) { return(ValidationResult.Success); } else { var model = validationContext.ObjectInstance; if (!IsDefaultValue.Value(GetProperty.Value(model, otherProperty))) { var memberDisplayName = GetDisplayNameAttribute.Value(model, validationContext.MemberName); var otherPropertyDisplayName = GetDisplayNameAttribute.Value(model, otherProperty); return(new ValidationResult($"{memberDisplayName} must have value, when {otherPropertyDisplayName} has value.")); } return(ValidationResult.Success); } }