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
Hello,

What I want to do is mock System.IO.Directory.Exists, to ensure that this method returns false, so that in my code, it enters the process of creating a new directory (through Directory.CreateDirectory method). I want to have typemock return a false value, and not call the CreateDirectory method.

However, If I use recorder.ExpectAndReturn method on the RecordExpectations object in natural approach, it says System.Boolean not supported with the ExpectAndReturn method (I also had no success with recorder.Return either).

How can I mock this statement?

Thanks.
asked by bmains (13.2k points)

1 Answer

0 votes
Hi,

Unfortunately, the Directory class is part of the MSCorLib.dll in which we currently don't have the ability to mock.

you can bypass this issue by doing one of two things:
1) Write a very simple wrapper for the Directory class (or just the specific methods you want to mock) and mock that instead.

2) Do it the old fashion way. At the start of the test create the directory, and remove it at the end. I know that this solution is not very elegant but in simple scenarios it will do the job.
answered by lior (13.2k points)
...