title: All invocation on the mock must have a corresponding setup
body: <p>I have some legacy code I want to unit test. I created a first moq test but I am getting the following exception:</p>
  
  <blockquote>
    <p>Moq.MockException:IConnection.SendRequest(ADF.Messaging.Contract.ConfigServer.GetDataVersionRequest)
    invocation failed with mock behavior Strict. All invocations on the
    mock must have a corresponding setup.</p>
  </blockquote>
  
  <p>Important pieces of code:</p>
  
  <p>Property on class:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Property Connection() As IConnection
      Get
          Return _connection
      End Get
      Set(ByVal value As IConnection)
          _connection = value
      End Set
  End Property
  </code></pre>
  
  <p>The method that should be tested: (_connection) is a actually a class that creates a tcp socket and I want to mock that property so the SendRequest returns what I want.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Function GetVersion(ByVal appID As Contract.ApplicationID) As Contract.DataVersion
      EnsureConnected()
      Dim req As GetDataVersionRequest = New GetDataVersionRequest(appID)
  
      Dim reply As CentralServiceReply = _connection.SendRequest(req) //code I want to mock
      Utils.Check.Ensure(TypeOf reply Is GetDataVersionReply, String.Format("Unexpected type: {0}, expected GetDataVersionReply!", reply.GetType()))
  
      Dim version As Contract.DataVersion = CType(reply, GetDataVersionReply).Version
      version.UpgradeOwners()
      If (Not version.IsSupported) Then
          Return Contract.DataVersion.UNSUPPORTED
      End If
  
      Return version
  End Function
  </code></pre>
  
  <p>Test Method:</p>
  
  <pre><code>[TestMethod]
  public void TestMethod2()
  {
      Contract.CentralServiceRequest req = new Contract.ConfigServer.GetDataVersionRequest(new ApplicationID("AMS", "QA"));
  
      DataVersion v = new DataVersion();
      v.AppVersion = "16";
      CentralServiceReply reply = new GetDataVersionReply(v);
  
      var ConnectionMock = new Mock&lt;IConnection&gt;(MockBehavior.Strict);
      ConnectionMock.Setup(f =&gt; f.SendRequest(req)).Returns(reply);
  
      var proxy = new ConfigServerProxy(new ApplicationID("AMS", "QA"), "ws23545", 8001);
      proxy.Connection = ConnectionMock.Object; //assign mock object
  
      DataVersion v2 = proxy.GetVersion(new ApplicationID("AMS", "QA"));
      Assert.AreEqual(v.AppVersion, v2.AppVersion);
  }
  </code></pre>
  
  <p>When I debug the unit test I see that when proxy.GetVersion is executed on the line _connection.SendRequest we get the error. Also when I watch the variable (_connection) in the watch window I see it's the moq object. So I suppose that property assignment went well. </p>
  
  <p>Does anybody see where I went wrong? </p>