예제 #1
0
        public void Should_be_able_to_actually_validate_an_object_that_implements_ICanBeValidated_using_the_default_conventions()
        {
            DefaultPropertyConvention defaultPropertyConvention1 = new DefaultPropertyConvention(x => x.Name.Contains("Url"));

            defaultPropertyConvention1.AddValidationRule <IsUrl <CanBeAnyViewModel> >();
            _validationConfiguration.DefaultPropertyConventions.AddDefaultPropertyConvention(defaultPropertyConvention1);

            DefaultPropertyConvention defaultPropertyConvention2 = new DefaultPropertyConvention(x => x.Name.Contains("Email"));

            defaultPropertyConvention2.AddValidationRule <IsEmail <CanBeAnyViewModel> >();
            _validationConfiguration.DefaultPropertyConventions.AddDefaultPropertyConvention(defaultPropertyConvention2);

            _validationConfiguration.DiscoveredTypes.AddDiscoveredType <TestViewModel>();

            IValidationResults <TestViewModel> validationResults = _validationConfiguration.Validate(_testViewModel);

            validationResults.ShouldNotBeNull();
            validationResults.GetInvalidFields().Count().ShouldEqual(3);
            validationResults.GetInvalidFields().First().ShouldEqual("property => property.False_Email_1");
            validationResults.GetInvalidFields().Last().ShouldEqual("property => property.False_Url");
            validationResults.GetBrokenRulesFor(validationResults.GetInvalidFields().First()).Count().ShouldEqual(1);
            validationResults.GetBrokenRulesFor(validationResults.GetInvalidFields().First()).First().ShouldBeOfType <IsEmail <TestViewModel> >();
            validationResults.GetBrokenRulesFor(validationResults.GetInvalidFields().Last()).Count().ShouldEqual(1);
            validationResults.GetBrokenRulesFor(validationResults.GetInvalidFields().Last()).First().ShouldBeOfType <IsUrl <TestViewModel> >();
        }
예제 #2
0
        public void Should_be_able_to_validate_a_view_model_that_implements_ICanBeValidated()
        {
            IValidationResults <TestViewModel> validationResults = _validationConfiguration.Validate(_testViewModel);

            validationResults.ShouldNotBeNull();
        }