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
will mocking mscorlib types ever be supported?
asked by servotest bob (3.8k points)

15 Answers

0 votes
Hi,
It will be supported, but not in the next release that is due next week.
answered by scott (32k points)
0 votes
Hi,
Can you be more precise. When to expect mocking mscorlib types?
answered by stephan (220 points)
0 votes
Hi,
This is still in the works :-).
What types would you like to mock, perhaps we can mock these first?
answered by richard (3.9k points)
0 votes
Thank you for the reply Richard.

I'm trying to mock StreamWriter.

Best Regards
Stephan Zahariev
answered by stephan (220 points)
0 votes
I will add this to our list.

We used the following technique when our tests need to mock Streams.

What we did was to change the file that was being opened and we pointed to another file.

We did this by having a Property with the filename and mocking the property.
e.g. We want to see how we behave with a non existing file

private string Filename 
{
    get { return theFileName; }
}

StreamWriter writer = new StreamWriter(Filename);

// in our tests
mock.ExpectGet("FileName","a_file_that_doesnt_exist');
answered by richard (3.9k points)
0 votes
Thanks for the help.

Stephan Zahariev
answered by stephan (220 points)
0 votes
Hi,
This is still in the works :-).
What types would you like to mock, perhaps we can mock these first?

Is it possible to mock the Today property of Date or DateTime?

I've got some tests that have special circumstances for special dates (like range validating when the current date is 1/1/2006), and if I could write mocks to handle those cases, my testing would truly be complete.
answered by dagilleland (200 points)
0 votes
Hi stephan

Unfortunately DateTime is part of the mscorlib :x
As richard wrote mocking mscorlib is still in the works.
Don't lose your hope! :)
answered by ohad (35.4k points)
0 votes
although DateTime.Now cannot be mocked there is a workaround.

You can define the following static property in your code.
public class DataUtils
{
   public static Now 
   {
       get { return DataTime.Now; }
   }
}


This is already very easy to mock
answered by scott (32k points)
0 votes
Hi Scott,

But does this mean that in the code that I am testing, I will need to use the DataUtils class instead of the DateTime class? If so, that's not very desirable.

Since your post was made over a year ago, has there been a change on whether the mscorlib types be supported for mocking?

Ken
answered by kenn (140 points)
...