0

私はこのエラーを理解しようと輪になって行きます。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");

App.Configファイルには次のバインディングがあります

<system.serviceModel>
    <services>
      <service name="ChatInterfaces.IChatService">
        <endpoint address="net.tcp://localhost:8080/ChatService" binding="netTcpBinding" bindingConfiguration="BindingConfiguration" name="ChatServiceEndPoint" contract="ChatInterfaces.IChatService">
        </endpoint>
      </service>
    </services>

    <bindings>
      <netTcpBinding>
        <binding name="BindingConfiguration" transferMode="Buffered"/>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

実行すると、次のエラーが発生します。

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]]'.

私はここで何を間違っているのですか、そしてそれを修正する方法は?ありがとう

4

1 に答える 1

1

オブジェクトではなく、mk.Object実際に実装を取得するためにを使用してみてください。IChatServiceMock<T>

Mock<ChatInterfaces.IChatService> mk = new Mock<ChatInterfaces.IChatService>();
host = new ServiceHost(mk.Object);
于 2013-02-18T00:29:47.977 に答える