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

  • Home
  • SEARCH
  • 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 7642291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:09:06+00:00 2026-05-31T09:09:06+00:00

How can I mock a method with two signatures? sudo code: public Class ClassA{

  • 0

How can I mock a method with two signatures?

sudo code:

public Class ClassA{
  //... do stuff
}

public Class ClassB{
  //... do stuff
}

public Class BigClass
{
  public BigClass(){}

  public ClassB MapMe(ClassA a)
  {
     //... do stuff
     return new ClassB();
  }

  public ClassA MapMe(ClassB a)  
  {
     //... do stuff    
     return new ClassA();
  }
}

public Class ClassToTest
{
  public void DoSomething()
  {
     var ResultA = BigClass.MapMe(new ClassA());

     //... do some more stuff

     ResultA = BigClass.MapMe(new ClassB());
  }
}

Apologies for the poor code example, doing this on IPad, but hopefully gives you the idea.

  • 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-05-31T09:09:08+00:00Added an answer on May 31, 2026 at 9:09 am

    Just use Argument Constraints

    Argument constraints also define the method’s signature by specifying
    the arguments types. That’s why they can’t be omitted.

    mock.Expect(x => x.MapMe(Arg<ClassB>.Is.Anything).Return(resultB);
    mock.Expect(x => x.MapMe(Arg<ClassA>.Is.Anything).Return(resultA);
    

    EDIT:

    I believe an other issue you faced – you’ve mocked BigClass without backing interface so obviously RhinoMocks does not allow setting expectations on such a mock. So just abstract a BigClass by interface and mock based on it:

    public interface IMapper
    {
        ClassB MapMe(ClassA entity);
        ClassA MapMe(ClassB entity);
    }
    
    public class BigClass : IMapper
    
    
    [Test]
    public void MapperTest()
    {
        // !!! Below I've used WhenCalled() to show you that correct  
        // expectation is called based on argument type, just see in debugger
        IMapper mapperMock = MockRepository.GenerateMock<IMapper>();
        mapperMock.Expect(x => x.MapMe(Arg<ClassA>.Is.Anything))
                  .WhenCalled((mi) =>
                            {
                                Debug.WriteLine("MapMe - ClassA parameter");
                            })
                  .Return(null /*TODO: return correct instance*/);
        mapperMock.Expect(x => x.MapMe(Arg<ClassB>.Is.Anything))
                  .WhenCalled((mi) =>
                            {
                                Debug.WriteLine("MapMe - ClassB parameter");
                            })
                  .Return(null /*TODO: return correct instance*/);
    
        var resultB = mapperMock.MapMe(new ClassA());
        var resultA = mapperMock.MapMe(new ClassB());
    
       // TODO: Asserts
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering how I can mock the ClaimseReponse class in DotNetOpenAuth? This is
I have the following code(simplified). public class OrderProcessor { public virtual string PlaceOrder(string test)
One of my base repository classes contains a method: public abstract class RepositoryBase<T, TDb>
Look at https://github.com/rails/rails/commit/1408b942d9c2c131a1cdcab97f49d74ce84dae38 I thought mocking meant you can mock any method. Did not
When using jmock, you can mock a concrete class if you set the class
Please consider the following code: type TFoo1 = class public procedure DoSomething1; end; TFoo2
If I mock a method to return a new instance of some object, how
How can I mock one method with RhinoMocks in VB.Net? The reference I found
How can I mock my location on a physical device (Nexus One)? I know
I want to make a mock installer using NSIS so we can demo what

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.