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

I am just wondering whether or not it is possible to mock the Random class, something like this:

using (RecordExpectations recorder = RecorderManager.StartRecording())
{
   Random rand = new Random();
   rand.Next(0,9999);
   recorder.Return(1234);
}


Thanks,

Morten
asked by petteroe (3k points)

1 Answer

0 votes
Hi Morten,

Alas, Random is defined in MSCorLib, and therefore cannot be mocked. Best course of action - wrap it in your own method, then mock that method.
answered by gilz (14.5k points)
...