public void RequiredIf_Property_Should_Be_Invalid_If_Condition_Not_Met() { var model = new RequiredIfAttributeTestModel { DependencyProp = true, TestProp = null }; var isValid = Validator.TryValidateObject(model, new ValidationContext(model), new List <ValidationResult>(), true); isValid.Should().BeFalse(); }
public void RequiredIf_Property_Should_Be_Valid_If_Not_Required() { var model = new RequiredIfAttributeTestModel { DependencyProp = false, TestProp = null }; var isValid = Validator.TryValidateObject(model, new ValidationContext(model), new List <ValidationResult>(), true); isValid.Should().BeTrue(); model.TestProp = "some string"; isValid = Validator.TryValidateObject(model, new ValidationContext(model), new List <ValidationResult>(), true); isValid.Should().BeTrue(); }