示例#1
0
        public void WhenValidatingInstanceWithInvalidPropertyValid_ThenResultIsNotValid()
        {
            var instance = new TypeWithValidationAttributes {
                MyProperty = 20, MyField = "valid"
            };

            var result = this.validator.Validate(instance);

            Assert.IsFalse(result.IsValid);
        }
示例#2
0
        public void WhenValidatingValidInstance_ThenResultIsValid()
        {
            var instance = new TypeWithValidationAttributes {
                MyProperty = 6, MyField = "valid"
            };

            var result = this.validator.Validate(instance);

            Assert.IsTrue(result.IsValid);
        }
示例#3
0
        public void WhenValidatingInstanceWithInvalidPropertyAccordingToTheRules_ThenResultIsValid()
        {
            var instance = new TypeWithValidationAttributes {
                MyProperty = 20, MyField = "valid"
            };

            var result = this.validator.Validate(instance);

            Assert.IsTrue(result.IsValid);
        }
        public void WhenValidatingValidTarget_ThenGetsValidResult()
        {
            var instance = new TypeWithValidationAttributes {
                MyProperty = 6, MyField = "aaaaaa"
            };

            var results = this.validator.Validate(instance);

            Assert.IsTrue(results.IsValid);
        }
        public void WhenValidatingTargetWithInvalidProperty_ThenGetsNotValidResultWithResultsForEachFailedRule()
        {
            var instance = new TypeWithValidationAttributes {
                MyProperty = 0, MyField = "aaaaa"
            };

            var results = this.validator.Validate(instance);

            Assert.IsFalse(results.IsValid);
            Assert.AreEqual(1, results.Count);
            Assert.IsTrue(results.Where(vr => vr.Key == "MyProperty").Any(vr => vr.Message == "range"));
        }
        public void WhenValidatingTargetWithInvalidField_ThenGetsNotValidResultWithResultsForEachFailedRule()
        {
            var instance = new TypeWithValidationAttributes {
                MyProperty = 6, MyField = "some invalid string"
            };

            var results = this.validator.Validate(instance);

            Assert.IsFalse(results.IsValid);
            Assert.AreEqual(2, results.Count);
            Assert.IsTrue(results.Where(vr => vr.Key == "MyField").Any(vr => vr.Message == "regex"));
            Assert.IsTrue(results.Where(vr => vr.Key == "MyField").Any(vr => vr.Message == "length"));
        }