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 543461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:33:14+00:00 2026-05-13T10:33:14+00:00

Using RhinoMocks, I have a catch-22 situation: I want to verify that a method

  • 0

Using RhinoMocks, I have a catch-22 situation: I want to verify that a method is called, but this method needs to have an object returned on it because the returned object is acted on in the next line. In other words, mocking on the interface just returns a null value, but not mocking it up doesn’t give me any way to verify that the method was called apart from some kind of integration test.

Therefore, looking at the contrived sample below that I threw together, is there a way to do what I’m wanting? I thought there might be a way to set the AssertWasCalled method to actually return something as when stubbing a method, but…thanks for any pointers (especially if it’s simply a design flaw that should be addressed instead).

public class SomeClass
{
    private readonly ISomeMapper _someMapper;
    [Inject]
    public Test(ISomeMapper someMapper)
    {
        _someMapper = someMapper;
    }

    public SomeReturnType SomeMethod(IEnumerable<ISomethingToMap> somethings)
    {
        //foreach over somethings and do something based on various properties for each

        MappedSomething mappedSomething = _someMapper.Map(something); // AssertWasCalled here
        mappedSomething.SomeProperty = somethingFromSomewhere; // Which gets a null reference exception here (understandably) if _someMapper is mocked
        //end foreach after more stuff
    }

}

  ///...
    [Test]
    public void the_mapper_should_be_called()
    {
        //If mock or stub, then can AssertWasCalled, but then only null object returned.
        // If don't mock, then cannot assert whether was called.
        var mapper = MockRepository.GenerateStub<ISomeMapper>();

        var somethingToMap = _someListOfSomethings[0];

        var sut = new SomeClass(mapper);

        sut.SomeMethod(_someListOfSomethings);

        mapper.AssertWasCalled(x => x.Map(somethingToMap));
    }
  • 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-13T10:33:14+00:00Added an answer on May 13, 2026 at 10:33 am

    You can set an expectation on the mock object that the method was called along with the return value:

    MappedSomething fakeMappedSomething = //whatever
    mapper.Expect(m => m.Map(something)).Return(fakeMappedSomething);
    ...
    sut.SomeMethod(_someListOfSomethings);
    

    Then verify the expectations at the end of the test.

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

Sidebar

Related Questions

No related questions found

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.