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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:59:39+00:00 2026-05-27T05:59:39+00:00

I am testing a class that has two dependencies on IFoo. Both instances of

  • 0

I am testing a class that has two dependencies on IFoo. Both instances of IFoo should be MOCK objects so that I can VerifyExpectations on each. Each instance is created and managed by the RhinoMocksMockingKernel.

I think that the mocking kernel is getting confused about which instance it should be verifying.

I also think that I may be confused about the proper way to setup RhinoMocksMockingKernel for this case.

I do know that I can use dep1.AssertWasCalled… vs. dep1.VerifyAllExpectations().

Here is the sample code.

public interface IFoo
{
    void DoX();
    void DoY();
}

public class SubjectUnderTest
{

    private readonly IFoo dep1;
    private readonly IFoo dep2;

    public void DoWork()
    {
        dep1.DoX();
        dep2.DoY();
    }

    public SubjectUnderTest(IFoo dep1, IFoo dep2)
    {
        this.dep2 = dep2;
        this.dep1 = dep1;            
    }
}

[TestFixture]
public class Tests
{
    [Test]
    public void DoWork_DoesX_And_DoesY()
    {
        var kernel = new Ninject.MockingKernel.RhinoMock.RhinoMocksMockingKernel();
        var dep1 = kernel.Get<IFoo>();
        var dep2 = kernel.Get<IFoo>();

        // tried this binding but it doesnt seem to work
        kernel.Bind<SubjectUnderTest>()
            .ToSelf()
            .WithConstructorArgument("dep1", dep1)
            .WithConstructorArgument("dep2", dep2);

        var sut = kernel.Get<SubjectUnderTest>();

        dep1.Expect(it => it.DoX());
        dep2.Expect(it => it.DoY());

        sut.DoWork();

        dep1.VerifyAllExpectations();
        dep2.VerifyAllExpectations();
    }
}
  • 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-27T05:59:40+00:00Added an answer on May 27, 2026 at 5:59 am

    So I found a way to verify the expections on dep1 and dep2, but I was not able to use the AutoMockingKernel to manage and create dep1 and dep1.

    Here is the code that I came up with.

    It’s pretty lame answer. It seems like I should be able to use the mocking kernel to Get two seperate instances of IFoo…

    Here is my current code… lameo…

    [TestFixture]
    public class Tests
    {
        [Test]
        public void DoWork_DoesX_And_DoesY()
        {
            var kernel = new Ninject.MockingKernel.RhinoMock.RhinoMocksMockingKernel();
            var dep1 = MockRepository.GenerateMock<IFoo>();
            var dep2 = MockRepository.GenerateMock<IFoo>();
    
            kernel.Bind<IFoo>().ToMethod((ctx) => dep1).When((ctx) => ctx.Target.Name.StartsWith("dep1"));
            kernel.Bind<IFoo>().ToMethod((ctx) => dep2).When((ctx) => ctx.Target.Name.StartsWith("dep2"));
    
            var sut = kernel.Get<SubjectUnderTest>();
    
            dep1.Expect(it => it.DoX());
            dep2.Expect(it => it.DoY());
    
            sut.DoWork();
    
            dep1.VerifyAllExpectations();
            dep2.VerifyAllExpectations();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with Drupal's automated testing in PHP. It's a class that has two
I have a class that I am unit testing into with DUnit. It has
I have an abstract class that defines some methods. This class has two subclasses.
I'm testing a C++ class with a number of functions that all have basically
I have a dummy class where I am testing arrays. I've noticed that when
I have two classes that I am testing (let's call them ClassA and ClassB).
Should one create unit tests involving IO? Ie, testing a class method for serializing/deserializing
How to mock object for testing if the class you're testing is abstract? you
I'm writing a network app, where each Client has a Singleton ClientManager. For testing
I have a utility class that has been thoroughly tested, and I do not

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.