コード例 #1
0
        public void OneInterface_TryValidate_Fail()
        {
            var person = new BinocularPerson {
                Name = "Cyclops", EyeCount = 1
            };

            ModelValidator.TryValidateObject(person, Results).Should().BeFalse();
            Results[0].ErrorMessage.Should().Match("*EyeCount*2*");
        }
コード例 #2
0
        public void TwoInterfaces_TryValidate_Ok()
        {
            var person = new HumanPerson {
                Name = "Hyacinth", EyeCount = 2, FootCount = 2
            };

            ModelValidator.TryValidateObject(person, Results).Should().BeTrue();
            Results.Should().BeEmpty();
        }
コード例 #3
0
        public void Concrete_TryValidate_Fail()
        {
            var person = new Person {
                Name = null
            };

            ModelValidator.TryValidateObject(person, Results).Should().BeFalse();
            Results.Count.Should().BePositive();
            Results[0].ErrorMessage.Should().Match("*Name*required*");
        }
コード例 #4
0
        public void Subclass_TryValidate_Fail()
        {
            var person = new BinocularPerson {
                Name = null, EyeCount = 2, FootCount = 2
            };

            ModelValidator.TryValidateObject(person, Results).Should().BeFalse();
            Results.Count.Should().BePositive();
            Results[0].ErrorMessage.Should().Match("*Name*required*");
        }
コード例 #5
0
        public void TwoInterfaces_TryValidate_Fail()
        {
            var person = new HumanPerson {
                Name = "Clumsy Cyclops", EyeCount = 1, FootCount = 1
            };

            ModelValidator.TryValidateObject(person, Results).Should().BeFalse();
            Results.Select(x => x.ErrorMessage).Should().Contain(m => m.Contains("EyeCount"));
            Results.Select(x => x.ErrorMessage).Should().Contain(m => m.Contains("FootCount"));
            Results.Count.Should().Be(2);
        }