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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:58:40+00:00 2026-05-24T01:58:40+00:00

I am using Rhino Mocks as a mocking framework for unit testing. I have

  • 0

I am using Rhino Mocks as a mocking framework for unit testing.

I have a class called Subject which is the class I want to test. It has a dependency on IStore.

IStore is defined as follows:

//internal interface : has InternalsVisible to both "Subject" 
//and "StoreTests" class namespaces
internal interface IStore {
    void Store(string name);
    //other methods
}

and the Subject class is defined as follows:

class Subject : IStore {
    private IStore internalStore;

    //constructor injection
    void Subject(IStore store) {
        internalStore = store;
    }

    void Store(string name) {
        internalStore.Store(name);
    }

    //other methods
}

My test class using RhinoMocks is as follows:

//test class
class StoreTests {
    Subject subject = new Subject();

    [Test]
    public StoreTest() {
        //Arrange
        var mockStore = MockRepository.GenerateMock<IStore>();
        string testName = "test";
        mockStore.Expect(x => x.Store(testName)).Returns(null);

        //Act
        subject.Store(testName);

        //Assert
        mockStore.VerifyAllExpectations();
    }

    //other test methods
}

In my setup, the interface is defined as internal and it has InternalsVisible set for both Subject class and StoreTests class. However, when the test case executes, it throws an exception at var mockStore = MockRepository.GenerateMock();
saying that IStore is not public and therefore it could not generate a Mock.

I think this is because the IStore is not public. However, since I have set InternalsVisibleTo on the IStore dll, will it not be sufficent for StoreTests to create a mock for that class?

Now I think this problem may be solved by making the IStore interface public. However given that this is not an option for me, is there any other way I can create a mock for IStore ?

  • 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-24T01:58:41+00:00Added an answer on May 24, 2026 at 1:58 am

    Did you try making the assembly internals visible to Rhino mocks?

    [assembly: InternalsVisibleTo ("DynamicProxyGenAssembly2")]
    

    See Rhino Mocks Internal Members for details.

    When a class is mocked, a new class is generated at run-time which is derived from the mocked class. This generated class resides in a separate "temporary" assembly which is called "DynamicProxyGenAssembly2". So, the InternalsVisibleTo attribute needs to be set on the target assembly to allow access to its internal members from the temporary assembly; otherwise, the mock object can’t override the internal member as it doesn’t have access to it (which is also why the mocked method must be marked as virtual). Note that this is true even if the unit test and the tested class are in the same assembly.

    So, you need to make sure that the target class’ assembly makes its internals visible to the proxy assembly as such (in AssemblyInfo.cs for example):

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

Sidebar

Related Questions

I am using .NET 4, NUnit and Rhino mocks. I want to unit test
I am using Rhino mocks for unit test mocking of objects. Our DAL uses
(C#, Rhino Mocks, MbUnit). I have a class called AccountManager that has a RegisterUser()
I have just crafted the following test using Rhino mocks. Does my test look
I've been experimenting with Rhino Mocks for unit testing my .Net Compact Framework application,
I'm using Visual Studio unit testing framework and have the need to using a
I have read a lot about mocking, particularly using Rhino Mocks and have learned
I have been looking at examples of mocking using Moq and Rhino Mocks and
I've a problem with partial mocking using Rhino Mocks: var authentication = (FormsAuthenticationService)_mocks.PartialMock( typeof(FormsAuthenticationService));
Are there any ways to mock a WCF client proxy using Rhino mocks framework

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.