Specify Ruleset in XML Configuration File

Topics: Developer Forum
Apr 9, 2007 at 3:37 PM
Do you have an example of this?

Thanks,

- Andrew
Apr 9, 2007 at 4:03 PM
I assume syntax like this is what I'm looking for?

<rule errorMessage='hello' initialValue='Two' typeName='RequiredEnumRuleConfigReader' ruleSet='foo' />

Thanks,

- Andrew
Apr 9, 2007 at 10:54 PM
That’s correct. Although you should know that RuleSet is case insensitive and will be converted to uppercase on construction of a rule.
I will updating the doco and chm in the next couple of days to include RuleSet functionality.

-Simon
Apr 12, 2007 at 3:36 PM
Simon,

I have the following: -

<?xml version="1.0" encoding="utf-8" ?>
<validationMapping xmlns="urn:validationFramework-validationDefinition-1.5">
  <class typeName="Common.Entities.PersonPOC, Common.Entities">
    <property name="OtherTitle">
      <rule ruleset ="MANDATORY" typeName="CustomRuleConfigReader" ruleInterpretation="Custom Rule" validationMethod="CheckOtherTitleSpecifiedIfTitleIsOther" validationTypeName="Common.PropertyRuleServices.PersonPOCRules,Common.PropertyRuleServices" />
    </property>
  </class>
</validationMapping>
 

And use it via this: -

     PersonPOC poc = new PersonPOC();
     poc.Title = POCTitleEnum.Other;
     poc.OtherTitle = "His Highness";
 
     PropertyValidationManager propertyValidationManager = new PropertyValidationManager(poc,"MANDATORY");
     propertyValidationManager.Validate("OtherTitle");
 
 


But get this on the Validate call: -

A property named 'OtherTitle' can not be found containing rules with the ruleSet 'MANDATORY'.
Parameter name: propertyName

Don't understand:(

- Andrew
Apr 12, 2007 at 5:46 PM
Edited Apr 13, 2007 at 7:36 AM
Another question, sorry!

    <property name="Surname">
      <rule ruleset ="MANDATORY_BEFORE_ASSIGN" typeName="CustomRuleConfigReader" ruleInterpretation="MANDATORY_BEFORE_ASSIGN Policy Holder Surname" validationMethod="CheckSurname_PolicyHolder" validationTypeName="Property.Common.PropertyRuleServices.PersonPOCRules,Property.Common.PropertyRuleServices" />
      <rule ruleset ="MANDATORY_BEFORE_EXIT" typeName="CustomRuleConfigReader" ruleInterpretation="MANDATORY_BEFORE_EXIT Policy Holder Surname" validationMethod="CheckSurname_PolicyHolder" validationTypeName="Property.Common.PropertyRuleServices.PersonPOCRules,Property.Common.PropertyRuleServices" />
    </property>
 

I wanted to have the same custom rule fired on the Surname property for different rule sets but I get this error: -

TestCase 'Property.Server.UnitTests.PropertyRuleServices_Tests.AssignAssessorRuleSet_CheckSurname_PolicyHolder_SurnameStringEmpty'
failed: TestFixtureSetUp Failed
TestFixture failed: Could not configure datastore from resource Common.PropertyRuleServices.PersonPOC.validation.xml'
   at ValidationFramework.Configuration.ConfigurationService.AddResource(String path, Assembly assembly) in C:\MainBranch\Architectural\ValidationFramework\Validation\ValidationFramework\Configuration\ConfigurationService.cs:line 433
   at ValidationFramework.Configuration.ConfigurationService.AddAssembly(Assembly assembly) in C:\MainBranch\Architectural\ValidationFramework\Validation\ValidationFramework\Configuration\ConfigurationService.cs:line 499
   at Property.Server.UnitTests.PropertyRuleServices_Tests.TestFixtureSetup() in C:\MainBranch\Property\Server\PropertyServer_UnitTests\PropertyRuleServices_Tests.cs:line 32

Any ideas?

Thanks,

- Andrew
Apr 12, 2007 at 10:49 PM
Andrew

A couple of question first.

For your “can not be found containing rules with the ruleSet” problem. Are you adding the xml using the ConfigurationService before using the PropertyValidationManager?

For your “Could not configure datastore from resource” problem. I assume you are calling the ConfigurationService from your unit test. If this is the case it only accepts fully qualified xml definitions. So it would have to have <validationMapping ...> <class...

I notice you are writing unit tests. If you do find bugs or problems it would be much quicker for me respond if you post your unit tests. I could then simply include it is the core tests to diagnose the problem.

regards
Simon
Apr 13, 2007 at 7:35 AM
Morning Simon,

The information you requested....

    [TestFixtureSetUp]
    public void TestFixtureSetup()
    {
      TypeCache.Clear();
      MethodCache.Clear();
      ConfigurationService.AddAssembly(Assembly.Load("Property.Common.PropertyRuleServices"));
    }
 
    [TestFixtureTearDown]
    public void TestFixtureTearDown()
    {
      TypeCache.Clear();
      MethodCache.Clear();
    }


    [Test]
    public void AssignAssessorRuleSet_CheckSurname_PolicyHolder_SurnameStringEmpty()
    {
 
      PersonPOC poc = new PersonPOC();
      poc.POCType = POCTypeEnum.PolicyHolder;
      poc.Surname = string.Empty;
 
      PropertyValidationManager propertyValidationManager = new PropertyValidationManager(poc,"MANDATORY_BEFORE_ASSIGN");
      propertyValidationManager.Validate(PersonPOC.Attribute.Surname);
      IList<ValidationResult> results = propertyValidationManager.GetResultsInErrorForProperty(PersonPOC.Attribute.Surname);
 
      Assert.AreEqual(1, results.Count, "Surname is string.empty, 1 error expected");
    }
 
    [Test]
    public void ExitRuleSet_CheckSurname_PolicyHolder_SurnameStringEmpty()
    {
 
      PersonPOC poc = new PersonPOC();
      poc.POCType = POCTypeEnum.PolicyHolder;
      poc.Surname = string.Empty;
 
      PropertyValidationManager propertyValidationManager = new PropertyValidationManager(poc,"MANDATORY_BEFORE_EXIT");
      propertyValidationManager.Validate(PersonPOC.Attribute.Surname);
      IList<ValidationResult> results = propertyValidationManager.GetResultsInErrorForProperty(PersonPOC.Attribute.Surname);
 
      Assert.AreEqual(1, results.Count, "Surname is string.empty, 1 error expected");
    }

 
<?xml version="1.0" encoding="utf-8" ?>
<validationMapping xmlns="urn:validationFramework-validationDefinition-1.5">
  <class typeName="Property.Common.Entities.PersonPOC, Property.Common.Entities">
    <property name="OtherTitle">
      <rule ruleset ="MANDATORY_BEFORE_ASSIGN" typeName="CustomRuleConfigReader" ruleInterpretation="Custom Rule" validationMethod="CheckOtherTitleSpecifiedIfTitleIsOther_PolicyHolder" validationTypeName="Property.Common.PropertyRuleServices.PersonPOCRules,Property.Common.PropertyRuleServices" />
    </property>
    <property name="Surname">
      <rule ruleset ="MANDATORY_BEFORE_ASSIGN" typeName="CustomRuleConfigReader" ruleInterpretation="MANDATORY_BEFORE_ASSIGN Policy Holder Surname" validationMethod="CheckSurname_PolicyHolder" validationTypeName="Property.Common.PropertyRuleServices.PersonPOCRules,Property.Common.PropertyRuleServices" />
      <rule ruleset ="MANDATORY_BEFORE_EXIT" typeName="CustomRuleConfigReader" ruleInterpretation="MANDATORY_BEFORE_EXIT Policy Holder Surname" validationMethod="CheckSurname_PolicyHolder" validationTypeName="Property.Common.PropertyRuleServices.PersonPOCRules,Property.Common.PropertyRuleServices" />
    </property>
  </class>
</validationMapping>
 

Thanks,

- Andrew
Apr 13, 2007 at 10:06 AM
Edited Apr 13, 2007 at 10:07 AM
“can not be found containing rules with the ruleSet” problem
Xml attributes are case sensitive hence "<rule ruleset ='MANDATORYBEFOREEXIT'" should be "<rule ruleSet ='MANDATORYBEFOREEXIT'".
That’s due to the implementation of XmlAttribute .

“Could not configure datastore from resource” problem
I am not certain what your other problem is. I could not run your unit test without the validation class "PersonPOCRules".
One thing that could be the problem is that validation methods should be static.
So CheckSurnamePolicyHolder should be static.
It could also be related to the lowercase ruleset attribute.
Either way I have checked in some code in ConfigurationService which should give a better
stack trace and hopefully diagnose your problem. So could you download the latest and let me know how you go.

Also, although ruleset values are converted to uppercase internally for performance reasons you do not have to do so from your point of view.
So it is ok to use camel or pascal case when referring to rulesets.
So you can write
PropertyValidationManager propertyValidationManager = new PropertyValidationManager(poc,"MandatoryBeforeAssign");
and
<property name="Surname"> <rule ruleSet ="MandatoryBeforeAssign"...
etc.


And there is no need to apologize for asking questions.
I realise most of these questions are due to my lack of doco and/or bugs.
So thanks for helping me produce a better product.

Regards
Simon

Apr 13, 2007 at 12:52 PM
Re. the rule set thing, a typo, oops!

I'll update my xml files and give it another whirl!

Thanks,

- Andrew
Apr 13, 2007 at 1:00 PM
Rule set stuff seems fine now thanks! - Andrew