I use CSLA almost exclusively. In our tests, to keep them from being brittle I want to make sure I'm only turning on the rules I'm interested in checking. so ideally, part of my Arrange step would be to:
ValidationRules fakeRules = Isolate.Fake.Instance<ValidationRules>();
And since this object may have child objects (whose quantify might change depending on the test) who in turn have there own instances of ValidationRules I really need:
Isolate.Swap.AllInstances<ValidationRules>().With(fakeRules);
Now because I still want the rule I want to test to be ran (not faked) I need a specific call to call the original, not all - so in the below code, we don't care about rules X and Y, but we do want rule Z to be added (because we're testing against.
ValidationRules.AddRule(CheckRuleX, "X");
ValidationRules.AddRule(CheckRuleY, "Y");
ValidationRules.AddRule(CheckRuleZ, "Z");
So back to my test (and 'CheckRuleZ' is a delegate) I want:
Isolate.WhenCalled(() => fakeRules.AddRules(Arg.Is.Anything(), Arg<string>.Equals("Z"))).CallOriginal();
Yes, I borrowed the Arg thing from Rhino mocks, but when I'm working in that tool it is a helpful way of doing things. Basically I'm saying I want all AddRules call to be faked except for when I'm calling with specific parameters, and that first item of the parameter just to be anything (would be hard to pass what I'm looking for in this case), the second parameter I want to be 'Z'.
Let me know.