小编Dha*_*esh的帖子

如何使用Moq模拟WCF客户端?

在我的项目中,我正在使用: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)

wcf unit-testing asynchronous moq system.reactive

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

asynchronous ×1

moq ×1

system.reactive ×1

unit-testing ×1

wcf ×1