EDN Admin
Well-known member
Please indulge me with a quick stupid question. Im investing heavily in learning testing, which means DI and mocks etc for isolation. Im also already a heavy user of WCF. My question is:
Given that I see many people complaining on the Internet about the WCF proxy client not being "mockable" and many other articles going to great and complicated lengths to create "mockable" versions of this client for injection into tests that require the
service client as a dependency... why is it that people dont just use the service interface that is provided with the proxy object?
Say I setup 3 default project types... 1 wcf service library, 1 wpf application and 1 test against the wpf application. Then I add the service reference in the wpf application. Then I create a test method and inject an IService1 into, say, MainWindowViewModel.
Now in test, I can focus on the functionality of the MainWindowViewModel by creating my own mock such as:
<pre class="prettyprint internal class bogusService1Client : IService1
{
#region IService1 Members
public string GetData(int value)
{
throw new NotImplementedException();
}
public System.Threading.Tasks.Task<string> GetDataAsync(int value)
{
throw new NotImplementedException();
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
throw new NotImplementedException();
}
public System.Threading.Tasks.Task<CompositeType> GetDataUsingDataContractAsync(CompositeType composite)
{
throw new NotImplementedException();
}
#endregion
}[/code]
Now in test cant I just use bogusService1Client instead of new Service1Client()? Cant I now put whatever junk I want for testing into that class and doesnt it stand in well for the concrete WCFProxyClient?
I know Im new to this stuff and I must be missing something, but every time I try to search on how to start WCF testing, I get the nth degree about mocking and ioc frameworks... which I know have their place for many other good reasons, but I dont understand
why it is that WCF presents a problem that they must solve... yet I havent been successful at starting my own WCF test first project so I must not be understand something critical.
Thank you for the indulgance.
-Ethan Nelson
View the full article
Given that I see many people complaining on the Internet about the WCF proxy client not being "mockable" and many other articles going to great and complicated lengths to create "mockable" versions of this client for injection into tests that require the
service client as a dependency... why is it that people dont just use the service interface that is provided with the proxy object?
Say I setup 3 default project types... 1 wcf service library, 1 wpf application and 1 test against the wpf application. Then I add the service reference in the wpf application. Then I create a test method and inject an IService1 into, say, MainWindowViewModel.
Now in test, I can focus on the functionality of the MainWindowViewModel by creating my own mock such as:
<pre class="prettyprint internal class bogusService1Client : IService1
{
#region IService1 Members
public string GetData(int value)
{
throw new NotImplementedException();
}
public System.Threading.Tasks.Task<string> GetDataAsync(int value)
{
throw new NotImplementedException();
}
public CompositeType GetDataUsingDataContract(CompositeType composite)
{
throw new NotImplementedException();
}
public System.Threading.Tasks.Task<CompositeType> GetDataUsingDataContractAsync(CompositeType composite)
{
throw new NotImplementedException();
}
#endregion
}[/code]
Now in test cant I just use bogusService1Client instead of new Service1Client()? Cant I now put whatever junk I want for testing into that class and doesnt it stand in well for the concrete WCFProxyClient?
I know Im new to this stuff and I must be missing something, but every time I try to search on how to start WCF testing, I get the nth degree about mocking and ioc frameworks... which I know have their place for many other good reasons, but I dont understand
why it is that WCF presents a problem that they must solve... yet I havent been successful at starting my own WCF test first project so I must not be understand something critical.
Thank you for the indulgance.
-Ethan Nelson
View the full article