Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:35:57+00:00 2026-06-09T21:35:57+00:00

I have some legacy code I want to unit test. I created a first

  • 0

I have some legacy code I want to unit test. I created a first moq test but I am getting the following exception:

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.

Important pieces of code:

Property on class:

Public Property Connection() As IConnection
    Get
        Return _connection
    End Get
    Set(ByVal value As IConnection)
        _connection = value
    End Set
End Property

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.

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

Test Method:

[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<IConnection>(MockBehavior.Strict);
    ConnectionMock.Setup(f => 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);
}

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.

Does anybody see where I went wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:35:58+00:00Added an answer on June 9, 2026 at 9:35 pm

    I suppose the problem is in the following thing:

    Contract.CentralServiceRequest req = new Contract.ConfigServer.GetDataVersionRequest(new ApplicationID("AMS", "QA"));
    

    Proxy makes the call to get application version, but doesn’t use this same request object (it probably creates another one with same parameters). Since it’s different objects and mock is set up to expect the same, it fails.

    Reasonable solution would be to expect any request of type CentralServiceRequest. I’m not well versed in Moq, but I suppose it’s something like this:

    ConnectionMock.Setup(f => f.SendRequest(ItExpr.IsAny<Contract.CentralServiceRequest>())).Returns(reply);
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some legacy classic ASP code (not ASP.Net, but ASP), and I want
I have some legacy code that was used to monitor my applications cpu,memory etc
I have some legacy C++ code that I am trying to understand a bit
We have some legacy ASP.NET code that detects if a request is secure, and
In support of some legacy code, I have to read a text file and
I have encountered a weird situation while updating/upgrading some legacy code. I have a
I need to integrate some legacy 32-bit code - for which I don't have
I'm trying to debug some legacy Integration Services code, and really want some confirmation
I have some legacy scientific code running on a Rocks cluster, with SGE. I
I have inherited some legacy vb6 code. It's a tool which generates a local

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.