I have a set of unit tests testing the properties and rules of my business object. My business object has a string property called Frequency, and I attach a rule to that property that checks the string against a regular expression. That regular expression is pulled out of a config file based on a value that gets passed into my objects constructor. In the test setup portion of my unit tests (MSTest), I create two instances of my business object. The only difference between the two is that the regular expression used in the frequency rule is different for each of the two objects. Now for each row of the test I set a value to the Frequency property of these two objects. What I am seeing is that when I set a value to either of the business objects, BOTH of the instances of the rule attached to the Frequency properties are run, and not just the one specific to each business object. I was thinking that this has something to do with the fact that they are both attached to the same property, even though there are two distinct business objects. The second thing I noticed is that every time a row is run for my test method, I recreate the the two business objects and the BusinessRules collection still maintains the rules from the previous test run. I have 8 rows for this test, so the list of rules gets quite large. By the time I get to the 8th row and my test sets a value to the frequency property those regular expression rules are running 8 times each! I must be doing something wrong??
↧