Thanks again for clarifying the issue. Doing a bit more investigation, I found that MSTest starts the development server for WCF projects and somehow intializes the client proxy. Therefore, JustMock fails to intercept the call in certain cases.
To get around this issue, i have cooked up a project which initializes the service host with mocked contract using JM MultiMock feature.
Accordingly, first I created a class that sets the context mode (to be used with ServiceHost):
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
Next, during the test initialization, I created the mock of PartialService that implements the target WCF contract and added it to the service host created for the specific purpose. In this case the contract is TestService.IService1 and test initialization looks like :
service = Mock.Create<PartialService>(x =>
var host =
Here to note that the url passed in host.AddServiceEndpoint must also contain in the client section of app.config:
Now, let's say we have a client project with the service reference of TestService.IService1 and invokes a service method:
(Service1Client client =
When a test method (like below) is written asserting the expected, it passes both in Debug and Run mode:
Mock.Arrange(() => service.GetData(Arg.AnyInt)).DoInstead(() => called =
TheFacade facade =
However, this issue occurs with MSTest
only. If you run your tests using TestDriven.Net (provided that asp net development server is not running) tests will run as expected.
Finally, I am attaching the project to let you have a look and hopefully this will resolve your issue. Also, this is a generic implementation and uses only proxy therefore should work in all cases and wont's have any initialization issues at all.
Please do feel free to write us for any exceptions.
the Telerik team