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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:59:18+00:00 2026-05-13T15:59:18+00:00

I use RhinoMocks for a very simple test (I have to say I’m a

  • 0

I use RhinoMocks for a very simple test (I have to say I’m a beginner here). I tried to mock my object like this

var mock = MockRepository.GenerateMock<MyClass>();

create a helper stub :

var stubLinkedObject = MockRepository.GenerateStub<MyClass>();

then execute some logic which should call the method AddLink of the class MyClass with my stub argument. At the end of the test I simply assert that this method was actually called with

mockAction.AssertWasCalled(a => a.AddLink(stubLinkedObject));

I injected the correct dependency and the method is actually called. However, the problem is that the real implementation in MyClass is called and results in crash because some logic just can’t be executed (link collection is not available etc.). How can I bypass the execution and simply check whether a method is called ? I have tried something like

mockAction.Stub(a => a.AddLink(null)).IgnoreArguments().Do(null);

before I go into the execution but this doesn’t seem to work(I only get some exceptions). Any ideas and probably an explanation why the mock is executing the method logic at all ?

  • 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-13T15:59:19+00:00Added an answer on May 13, 2026 at 3:59 pm

    I’ve tried to reproduce. Here is the code which works fine for me

    [Test]
    public void Test()
    {
        var classMock = MockRepository.GenerateMock<MyClass>();
        var linkedMock = MockRepository.GenerateStub<MyClass>();
    
        classMock.Expect(c => c.MyMethod(linkedMock));
    
        classMock.MyMethod(linkedMock);
    
        classMock.AssertWasCalled(c => c.MyMethod(linkedMock));
    }
    
    public class MyClass
    {
        public virtual void MyMethod(MyClass linkedClass)
        {
            Console.WriteLine("MyMethod is called");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have the following class, how do I use RhinoMocks to mock the
We use RhinoMocks. I have a type into whose constructor 9 types are injected.
I am trying to use Rhino.Mocks to mock up a ControllerContext object to gain
I would like to mock a class (i.e. with RhinoMocks) for which I don't
I am getting this error when I try to set a mock to have
I have some code that I use with Entity Framework like class Person{ pubic
Use trap to capture signals like this: i=-1;while((++i<33)); do trap echo $i >> log.txt
During this semester my professor tried to convince us why is good to use
I'm trying to use RhinoMock for mocking out a wcf service. Say I have
I'm trying to use Rhinomocks 3.5 and the new lambda notation to mock some

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.