在我的项目中,我正在使用:SL5 + MVVM + Prism + WCF + Rx + Moq + Silverlight单元测试框架.
我是单元测试的新手,最近开始使用DI,模式(MVVM)等.因此,下面的代码有很大的改进空间(如果您这么认为,请随意拒绝我正在采取的整个方法).
为了访问我的WCF服务,我创建了一个如下所示的工厂类(再次,它可能有缺陷,但请看一下):
namespace SomeSolution
{
public class ServiceClientFactory:IServiceClientFactory
{
public CourseServiceClient GetCourseServiceClient()
{
var client = new CourseServiceClient();
client.ChannelFactory.Faulted += (s, e) => client.Abort();
if(client.State== CommunicationState.Closed){client.InnerChannel.Open();}
return client;
}
public ConfigServiceClient GetConfigServiceClient()
{
var client = new ConfigServiceClient();
client.ChannelFactory.Faulted += (s, e) => client.Abort();
if (client.State == CommunicationState.Closed) { client.InnerChannel.Open(); }
return client;
}
public ContactServiceClient GetContactServiceClient()
{
var client = new ContactServiceClient();
client.ChannelFactory.Faulted += (s, e) …
Run Code Online (Sandbox Code Playgroud)