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'm having trouble with (this really cool feature) Natural Mocks.

I am trying to Mock the MailMessage class in order to verify it's parameters. I intend to let it continue, I only want to see if the parameters are correct. So I wrote the following:

using (RecordExpectations r = RecorderManager.StartRecording())
MailMessage mail = new MailMessage("","", "a subject", "my body");

I expect that this will verify the arguments are as they are typed in the test, and then proceed to call the real MailMessage constructor.

The problem is that TypeMock seems to catch a MailMessage(string, string). It eventually throws a TypeMock exception stating that it caught a call to MailMessage with only 2 parameters when it actually expected four.

using r.Repeat(1) didn't help.

Adding a check for "new MailMessage("", "") fixed the problem. Looks like MailMessage uses constructor chaining. It seems to me that I shouldn't have to be aware of that; TypeMock should ignore the chained constructor.

What am I doing wrong or how do I get TypeMock to ignore the second constructor call?

Thanks for the help!

BTW.. Natural Mocks: very cool.
asked by erichorne (3.4k points)

1 Answer

0 votes
8) Natural TypeMocks are cool.

You have found a :twisted: bug. You have found a good workaround but this should be fixed. I have added it to our feature list.
answered by scott (32k points)