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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:17:35+00:00 2026-05-28T07:17:35+00:00

I am new to RhinoMocks, and I am trying to write a test as

  • 0

I am new to RhinoMocks, and I am trying to write a test as shown
I have classes like these

public class A
{
    public void methodA(){}
}
public class B
{
    public void methodB(A a)
    {
      a.methodA();
    }
}

And i am trying to test it like this

A a = MockRepository.GenerateMock<A>();
public void ShouldTest()
{
    B b = new B();
    b.methodB(a);
    a.AssertWasCalled(x=>x.methodA());
    a.VerifyAllExpectations();
}

But it is giving the error as shown:
System.InvalidOperationException : No expectations were setup to be verified, ensure that the method call in the action is a virtual (C#) / overridable (VB.Net) method call.

How do I test methodB then?? Can someone help??

  • 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-28T07:17:36+00:00Added an answer on May 28, 2026 at 7:17 am

    Rhino mock creates proxy class when you call MockRepository.Generate *** method. This means that it extends your type. If you don’t declare any abstraction you cannot make any derivation which is essential in any mocking framework.

    You can do two things

    1. Create an interface (better design)
    2. Make the member virtual (this will allow RhinoMocks to derive from your type and create a proxy for the virtual member

    Sample code

    public interface IA { void methodA();}
    public class A:IA{public void methodA() { }}
    public class B
    {
        public void methodB(IA a)
        {
            a.methodA();
        }
    }
    
    [TestFixture]
    public class Bar
    {
        [Test]
        public void BarTest()
        {
            //Arrange
            var repo = MockRepository.GenerateMock<IA>();
    
            //Act
            B b = new B();
            b.methodB(repo);
    
            //Assert
            repo.AssertWasCalled(a => a.methodA());
            repo.VerifyAllExpectations();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a Rhino Mocks test to verify that I have
I am trying to test the logic from some existing classes. It is not
We are not able to mock this class in RhinoMocks. public class Service {
I'm new to RhinoMocks, and trying to get a grasp on the syntax in
I have a controller in C# using the ASP.Net MVC framework public class HomeController:Controller{
I am trying to write a test method to check if the List is
I have some code that I use with Entity Framework like class Person{ pubic
I am trying to test how my class reacts on to what happens when
I have an extension method with the following signature (in BuildServerExtensions class):: public static
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.