Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 模拟测试时找不到合同名称。_C#_Wcf_Testing_Moq - Fatal编程技术网

C# 模拟测试时找不到合同名称。

C# 模拟测试时找不到合同名称。,c#,wcf,testing,moq,C#,Wcf,Testing,Moq,我在兜圈子,试图找出这个错误。我正在使用moq框架执行模拟测试。测试代码是 [TestFixture] [ServiceContract] public class UnitTest1 { private ServiceHost host; [Test] public void TestMethod() { Mock mk = new Mock<ChatInterfaces.IChatService>(); host

我在兜圈子,试图找出这个错误。我正在使用moq框架执行模拟测试。测试代码是

[TestFixture]
[ServiceContract]
public class UnitTest1
{

    private ServiceHost host;
    [Test]
    public void TestMethod()
    {
        Mock mk = new Mock<ChatInterfaces.IChatService>();
        host = new ServiceHost(mk);
        host.AddServiceEndpoint(typeof(IChatService), new NetTcpBinding()
            , "net.tcp://localhost:8080/ChatService");
        host.Open();
        Console.WriteLine("Testing");

我在这里做错了什么?如何修复它?谢谢

尝试使用
mk.Object
来实际获取
IChatService
实现,而不是
Mock
对象

Mock<ChatInterfaces.IChatService> mk = new Mock<ChatInterfaces.IChatService>();
host = new ServiceHost(mk.Object);
Mock mk=new Mock();
主机=新服务主机(mk.Object);
Result Message: System.InvalidOperationException : The contract name     'ChatInterfaces.IChatService' could not be found in the list of contracts implemented by the service 'Moq.Mock`1[[ChatInterfaces.IChatService, ChatInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'.
Mock<ChatInterfaces.IChatService> mk = new Mock<ChatInterfaces.IChatService>();
host = new ServiceHost(mk.Object);