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
How can I mock such a way that the return value is null.

For eg.

clients.ExpectAndReturn ( "GetClient", null ).Args ( dest );

This will not work at runtime, it throws an error saying ExpectAndReturn cannot return null. In this case:

*** No method GetClient in type MockIClients can return null

Please help.

Thanks,
asked by tiptop (1.8k points)

7 Answers

0 votes
I hacked my way through, don't know if there is a better way:


clients.ExpectAndReturn ( "GetClient", new TypeMock.DynamicReturnValue(returnNull) ).Args ( source );


public static object returnNull(object[] parameters, object context)
{
return null;
}
answered by tiptop (1.8k points)
0 votes
Thanks for pointing this out.
This is actually a bug and it will be fixed in the next patch release. :twisted:

If you want I can send you the fix.
answered by scott (32k points)
0 votes
Im having the same problem can I get the patch as well?
answered by jnapier (9.6k points)
0 votes
We will be issuing a patch early next week
answered by scott (32k points)
0 votes
Hi Scott,

test code that is running on another pc where we still have 3.0.1 does complain about
ReloadDatabase_Test : TypeMock.TypeMockException :
*** No method CreateProgressOutput in type MockIProgressOutputService can return null

even if I code like this:
IProgressOutput ProgressOutput = null;
this.progressOutputServiceMock.ExpectAndReturn("CreateProgressOutput", ProgressOutput);

Should I use the workaround mentioned above in this thread or do you expect to release a new version soon?
answered by mknaup (8.5k points)
0 votes
Hi,
This problem is a new one and was not introduced in version 3.0.2

We are working on the next patch and it should be out any time. I would still recommend using the workaround untill we deliver the patch.
answered by scott (32k points)
0 votes
This issue is fixed in version 3.0.3 :D
answered by scott (32k points)
...