chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes

Still getting used to mocking. I want to use TypeMock to mock the Initialize method and validate that the parameters I pass in are correct. If you aren't familiar with what this method does, check this out: (note that I'm not writing a membership provider, but the results are the same).

Basically, it gets a set of configuration files, which I pass off to private variables. I want to use TypeMock to validate that the values coming in and being assigned are correct.

How do I do this?

asked by bmains (13.2k points)

1 Answer

0 votes
Most of the time you might want to avoid doing so:
- Checking passed arguments can result in fragile tests
- Unit tests should be "black box testing" - check for result and not execution.

For Example you could check if the object was initialized correctly instead.

There are several ways to check if a certain method was called with sepcific arguments:
1. Isolate.Verify.WasCalledWithExactArguments: using Verify will work if the passed arguments are either value-type or has override Equals method that makes sense for your test.

2. Isolate.WhenCalled(() => ..).DoInstead(...): you can use the DoInstead method to run custom verification logic when then method is called

3. Method re-direction: Isolator has a feature that enable the use to redirect method calls from code under test to custom class. You can use that feature to call you method where you can check the parameters passed.
answered by dhelper (11.9k points)