Welcome to Typemock Answers. Here you can ask and receive answers from other community members. And if you liked or disliked an answer or thread: react with an up- or downvote Enjoy!

Is it possible to mock a form?

0 votes
I use the following code:
----------------------------------------
MockManager.Init();
Mock fM=MockManager.Mock(typeof(MyForm), Constructor.NotMocked));
fM.ExpectAndReturn("ShowDialog", DialogResult.OK);

MyForm frm=new MyForm();
DialogResult res=frm.ShowDialog();

MockManager.Verify();
-----------------------------------------
The code fails with TypeMock exception:
"ShowDialog has 1 more expected calls"

I CANNOT UNDERSTAND WHY!!! PLEASE HELP! :?
________
Toyota Innova specifications
asked Dec 20, 2007 by PowerBoots (160 points)

3 Answers

+1 vote
Hi,

This should work.
Try to isolate the problem by running this test alone.
look at the tracer and see if everything is in order (ill send you a mail with instructions on how to produce the tracer output so you can send it to us)

Are you able to mock other objects without any problems?
answered Dec 20, 2007 by lior (18,340 points)
0 votes
Hi Lior,

To your question:
1) I run this test alone, I am a beginner, I don't have other tests
2) I created a very simple class that outputs a MessageBox to the screen, I played around with TypeMock and it works fine. TypeMock is realy great!
3) I don't know how to start the tracer. Thanks in advance for instructions.
4) I have to test some legacy code. I try to use TypeMock to mock all calls to System.Windows.Forms so I can concentrate on unit testing the buisness logic. Do you think it can work?
Regards,
Dan Lupu :)
________
BMW R16
answered Dec 20, 2007 by PowerBoots (160 points)
+1 vote
Lets take this offline. ive sent you a mail with instructions on how to produce the trace we will continue from there.
answered Dec 21, 2007 by lior (18,340 points)
...