public void IsValid_external_validator_doesnt_add_broken_rule_when_object_is_valid() { var obj = new StubObject { IntProperty = 2, StringProperty = "abc", GuidProperty = Guid.NewGuid() }; IsValid <StubObject, StubObjectValidator>(obj, PropertyName); Assert.True(ValidationResult.IsValid); }
public void ValidateThrowIfInvalid_throws_exception_if_invalid_object_provided() { var obj = new StubObject { GuidProperty = Guid.NewGuid(), IntProperty = 1, StringProperty = "abc" }; var validator = new StubObjectValidator(); validator.ValidateThrowIfInvalid(obj); }
public void IsValid_external_validator_adds_broken_rule_with_nested_broken_rules_if_obj_is_not_valid() { var obj = new StubObject(); IsValid <StubObject, StubObjectValidator>(obj, PropertyName); Assert.False(ValidationResult.IsValid); Assert.Equal(1, ValidationResult.BrokenRules.Count); Assert.Equal(PropertyName, ValidationResult.BrokenRules[0].Name); Assert.Equal(2, ValidationResult.BrokenRules[0].BrokenRules.Count); Assert.Equal(1, ValidationResult.BrokenRules[0].BrokenRules.Count(x => x.Name == nameof(obj.StringProperty))); Assert.Equal(1, ValidationResult.BrokenRules[0].BrokenRules.Count(x => x.Name == nameof(obj.IntProperty))); }
public void ValidateThrowIfInvalid_doesnt_throw_if_object_is_valid() { var obj = new StubObject(); var validator = new StubObjectValidator(); var ex = Record.Exception(() => validator.ValidateThrowIfInvalid(obj)); Assert.NotNull(ex); Assert.IsType <InvalidObjectException>(ex); Assert.True(((InvalidObjectException)ex).ValidationResult.IsNotValid); Assert.Equal(2, ((InvalidObjectException)ex).ValidationResult.BrokenRules.Count); }