A New Trick

I have read this post Interaction based testing using TypeMock.

This code:

Mock clientMock = MockManager.Mock(typeof (Client)); clientMock.Strict = true; Client client = new Client();

Is exactly the same as this code:

MockObject<Client> clientMock = MockManager.MockObject<Client>(); Client client = clientMock.Object;

I prefer the latter, the main reason being that using MockObject  ensures that the Object is the one being mocked.

Here is an example that won’t work because we added a new Mock before the previous code:

Mock firstClientMock = MockManager.Mock(typeof (Client)); Mock clientMock = MockManager.Mock(typeof (Client)); clientMock.Strict = true; Client client = new Client(); // this will be contolled by firstClientMock

In this case our client is controlled by the firstClientMock instead of the clientMock. This won’t happen if we use MockObject

Bookmark at:
Add 'A New Trick' to Del.icio.us Add 'A New Trick' to digg Add 'A New Trick' to reddit Add 'A New Trick' to Feed Me Links! Add 'A New Trick' to Technorati Add 'A New Trick' to Yahoo My Web Add 'A New Trick' to Newsvine Add 'A New Trick' to FURL Add 'A New Trick' to blinklist Add 'A New Trick' to My-Tuts 

7 August 2007 | TDD, .NET Tests | Comments | Print This Post

Leave a Reply

  1.  
  2.  
  3.  
Search Eli Lopian’s Blog (TypeMock)

Navigation

Recent Posts

Categories

Archives

Managment