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> >(); }
public void CloneFrom <TOtherViewModel>(IValidationResults <TOtherViewModel> validationResults) where TOtherViewModel : class { validationResults.GetInvalidFields() .Each(propertyString => { var rules = new List <IValidationRule <TViewModel> >(); validationResults.GetBrokenRulesFor(propertyString).Each(rule => rules.Add(_validationRuleConvertor.ConvertValidationRuleModelTo <TViewModel, TOtherViewModel>(rule))); _invalidFields.Add(propertyString, rules); }); }