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

Add Comment

Required fields are marked *. Your email address will not be published.