will mocking mscorlib types ever be supported?

0 votes
will mocking mscorlib types ever be supported?
asked Apr 4, 2006 by servotest bob (440 points)

15 Answers

0 votes
Hi,
It will be supported, but not in the next release that is due next week.
answered Apr 4, 2006 by scott (29,040 points)
0 votes
Hi,
Can you be more precise. When to expect mocking mscorlib types?
answered May 30, 2006 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 May 31, 2006 by richard (3,900 points)
0 votes
Thank you for the reply Richard.

I'm trying to mock StreamWriter.

Best Regards
Stephan Zahariev
answered May 31, 2006 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 May 31, 2006 by richard (3,900 points)
0 votes
Thanks for the help.

Stephan Zahariev
answered May 31, 2006 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 Jul 5, 2006 by dagilleland (180 points)
+1 vote
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 Jul 6, 2006 by ohad (37,060 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 Jul 6, 2006 by scott (29,040 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 Nov 19, 2007 by kenn (140 points)
...