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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:47+00:00 2026-06-17T23:27:47+00:00

I just started using Rhino mock to set up test cases for my project.

  • 0

I just started using Rhino mock to set up test cases for my project. What exactly does the .Return(objToReturn:list) do ?

Its only seems to work if I initialize and populate the list then pass it to the mock stub method. I was a assuming I could used the Mock Stub method to populate a list then return that populated list.

....
    private ProductRepository _productRepository;
    private IProductRepository _productRepositoryStub;

    [SetUp]
    public void SetUp()
    {
        _productRepository = new ProductRepository();


        //Testing using Rhino Mocks
        //Generate stub
         _productRepositoryStub = MockRepository.GenerateMock<IProductRepository>();
    }

    [Test]
    public void Canquerydb()
    {
        IList list = _productRepository.GetAllProducts();
        _productRepository.Stub(x=> x.GetAllProducts()).Return(list);
        _productRepositoryStub.AssertWasCalled(x => x.GetAllProducts());
    }


    /// <summary>
    /// Refaactor and use MockRhino here
    /// </summary>
    [Test]
    public void can_insert_product()
    {
        IProduct product = new Grains("Cheese Bread", "Dairy grain", 0);
        _productRepository.SaveProduct(product);
        _productRepositoryStub.Stub(x=>x.SaveProduct(product));
        _productRepositoryStub.AssertWasCalled(x => x.SaveProduct(product));

    }
  • 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-17T23:27:48+00:00Added an answer on June 17, 2026 at 11:27 pm

    To answer the title of your question: Rhino mocks makes a distinction between Mocks and Stubs. A Mock is the only thing that can make a test fail because it is a wrapped instance of the thing you are testing – your System Under Test (SUT). You “stub” something in Rhino mocks so that you can satisfy the dependencies of your mocked object. The stub gives you visibility of the arguments you pass to it, and gives you control of the return result so that you can make assertions about the behaviour of your Mock in complete isolation.

    This site has further explanation of Mocks and Stubs.

    To add, Libraries like Moq do not make the distinction between Mocks and Stubs. Through the use of generics you don’t have to Mock your SUT. I personally prefer this simplicity of Moq.

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

Sidebar

Related Questions

I just started using the MVCContrib grid in a test project. I'm having a
I just started using the new project type SQL Server 2008 Database. I can
I just started using LISP, coming from a background in C. So far its
I just started using mock objects (using Java's mockito) in my tests recently. Needless
I just started using the Eclipse IDE and for a first test I created
Just started using fadein/fadeout - it's functioning but with problems. I have a set
I just started using project for showing multiple tags from a select box and
I just started using Yii, coming from Codeigniter (CI). I'm trying to set up
I have just started using Rhino mocks and I am having difficulty doing that.
I just started using Instruments and its Leak detection feature. I was monitoring my

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.