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
Could you please offer some assistance.

I have a situation where I have a file parsing class that I am testing.

I want to be able to substitute out one of the method calls with a mock.

How might I mock this method within the class I am actually testing?

FileParser fileParser = new FileParser(fileName);
int recordCount = fileParser.GetRecordCount();

So, in the example above I would like to test the concrete implementation of FileParser but replace the method GetRecordCount with a mock method.

Hope someone can enlighten me.

Thanks for what so far I have found to be an intuitive product.
asked by AnthonyS (640 points)

2 Answers

0 votes
Here is how:
int fakeResult = 9;
Mock futureInstance = MockManager.Mock(typeof(FileParser));

You could also use MockManager.MockAll to mock All instances.
If you are having problems with this, please use the TypeMock Tracer that will help you see the instances and methods begin mocked
answered by scott (32k points)
0 votes

The Tracer certainly does make things clearer. Thanks for your help.
answered by AnthonyS (640 points)