コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }