CSLA 4.3.13 (old) - Remove rules?

CSLA 4.3.13 (old) - Remove rules?

Old forum URL: forums.lhotka.net/forums/t/12680.aspx


MSherman posted on Monday, June 23, 2014

Hi,

I know I am using an older version, but is there a way to remove rules? We have many unit test drivers testing various rule states and scenarios - our problems come on every rebuild the rules may be added in different orders because the tests run in a pseudorandom order based on the rebuild. We have no way to control when our objects have different rules, and because we no longer have instance rules, we need to be able to remove the active rules before we add more rules to test those specific rules. Is this possible?

Thanks,

Matt

JonnyBee replied on Monday, June 23, 2014

Hi,

In short - no you cannot remove or clear rules. 

But: you can create multiple complete RuleSet and switch between these in your code. 

By default all rules are added to a "default" RuleSet.

I would however recommend to unit test your rules as well. Have a look at the RuleTutorial sample that includes some helper classes to make it easier to unit test BusinessRules. 

MSherman replied on Friday, August 01, 2014

Thanks for responding (sorry for the time difference).

I can't give you actual code snippets for many reasons, including the sheer amount of code, but if I understand what you say, maybe this hypothetical situation might be answered using rulesets.

We have cases where config files decide how the application can be run. If the user wants to switch to a different config file, a different set of rules may be run. Since we're unable to remove rules, could we use rulesets by, when loading/adding all rules, adding them to a specific ruleset relative to that config only (each one has a unique ID), and upon switching, no rules would be on the new config?

Would something like that work?

thanks,

Matt

JonnyBee replied on Saturday, August 02, 2014

You would actually have to register all rulesets when AddBusinessRules is called (just once per-type). And then you could switch between rulesets.

 

 

 

Copyright (c) Marimer LLC