Example #1
0
        public void IsValid_doesnt_add_broken_rule_when_object_is_valid()
        {
            StubObjectWithValidation = new StubObjectWithValidation
            {
                IntProperty    = 2,
                StringProperty = "abc",
                GuidProperty   = Guid.NewGuid()
            };
            IsValid(StubObjectWithValidation, nameof(StubObjectWithValidation));

            Assert.True(ValidationResult.IsValid);
        }
Example #2
0
        public void IsValid_adds_broken_rule_with_nested_broken_rules_if_obj_is_not_valid()
        {
            StubObjectWithValidation = new StubObjectWithValidation();
            IsValid(StubObjectWithValidation, nameof(StubObjectWithValidation));

            Assert.False(ValidationResult.IsValid);
            Assert.Equal(1, ValidationResult.BrokenRules.Count);
            Assert.Equal(nameof(StubObjectWithValidation), ValidationResult.BrokenRules[0].Name);
            Assert.Equal(2, ValidationResult.BrokenRules[0].BrokenRules.Count);
            Assert.Equal(1, ValidationResult.BrokenRules[0].BrokenRules.Count(x => x.Name == nameof(StubObjectWithValidation.StringProperty)));
            Assert.Equal(1, ValidationResult.BrokenRules[0].BrokenRules.Count(x => x.Name == nameof(StubObjectWithValidation.IntProperty)));
        }