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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:24:00+00:00 2026-06-18T06:24:00+00:00

Is it possible to use the auto mocking framework provided in StructureMap.AutoMocking to test

  • 0

Is it possible to use the auto mocking framework provided in StructureMap.AutoMocking to test an internal virtual method within the CUT? I have already added InternalsVisibleTo to the appropriate AssemblyInfo.cs files. Here’s what I’m trying to do:

public ClassA {
    public void Method1() { Method2(); }
    internal virtual void Method2() { /* do work */ }
}

[Test]
public void TestClassA() {

    // Arrange
    var mockedClass = new RhinoAutoMocker<ClassA>();
    mockedClass.PartialMockTheClassUnderTest();
    mockedClass.ClassUnderTest.Expect(x => x.Method2());

    // Act
    mockedClass.ClassUnderTest.Method1();

    // Assert
    mockedClass.ClassUnderTest.VerifyAllExpectations();
}

I already know that changing the internal method to public works, but I don’t feel that this is an acceptable way to perform this test. Perhaps I am missing something fundamental about the way RhinoMocks and StructureMap interact but I figured based on other unit tests I’ve written that this type of thing should work.

Edit I suppose it would help to provide the error message I get when I try this:

System.InvalidOperationException : Invalid call, the last call has been used or no call       
has been made (make sure that you are calling a virtual (C#) / Overridable (VB) 
method).
at Rhino.Mocks.LastCall.GetOptions()
at Rhino.Mocks.RhinoMocksExtensions.Expect(T mock, Func`2 action)
at Rhino.Mocks.RhinoMocksExtensions.Expect(T mock, Action`1 action)
at ClassATest.TestClassA() in ClassA.cs      
  • 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-18T06:24:01+00:00Added an answer on June 18, 2026 at 6:24 am

    EDIT
    I am wrong in my below statements. I finally circled back to this and used the keyword protected on all of my unit tests that were testing internal virtual methods within my class under test. This DOES work in structure map and is the only reason why I was receiving the error I was receiving.


    After a bit of research on this, there seems to be some elements of Rhino.Mocks that are not accessible via StructureMap.Automocker. When I re-worked my unit tests to make use of only the Rhino.Mocks framework, I was able to expose `internal virtual` methods to the test runner. Not an ideal situation and I would like to see support for this in newer versions of StructureMap, but that may be a long way off if there’s other more important things that precede adding support for `internal virtual` methods.

    I re-worked my unit tests based on the following posts:

    http://ayende.com/Wiki/Rhino+Mocks+-+Internal+Methods.ashx

    How to mock protected virtual members with Rhino.Mocks?

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

Sidebar

Related Questions

Possible Duplicate: Is there any reason to use the 'auto' keyword in C /
Is it possible to use Auto Layout to position a window on the screen?
Is it possible to use XSD.exe to auto generate a class which has a
I have an table which use an auto-increment field (ID) as primary key. The
Possible Duplicate: How much is too much with C++0x auto keyword Have we (as
I have gleaned that it is possible to use conditional compiler directives and constants
Is It possible To Use ASP.NET TextBox With Jquery UI Auto CompletE? I am
Is it possible to use startActivityForResult() from a status bar notification? Say I have
When using auto-generated documentation for Google apps script libraries it's possible to use the
Is it possible use mod_rewrite to resolve addresses hosted on another server? Say I

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.