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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:35:36+00:00 2026-05-16T16:35:36+00:00

I am playing around with MbUnit and Rhino Mocks and made a simple test.

  • 0

I am playing around with MbUnit and Rhino Mocks and made a simple test. It may be poorly designed code, but I am more focused on just seeing if I can get the test to pass. Basically, When the engine light of a car is on, the car should an oil change. Here is code:

public interface ICar
{
    bool EngineLight { get; set; }
    void GetOilChange();
    bool CheckEngineLight(ICar car);
}

public class Car : ICar
{
    public bool EngineLight { get; set; }

    public void GetOilChange()
    {
    }

    public bool CheckEngineLight(ICar car)
    {
        if (car.EngineLight)
            GetOilChange();
            return true;

        return false;
    } 
}

[TestFixture]
public class CarTests
{
[Test]
    public void WhenEngineLightIsOnGetOilChange()
    {
        var carMock = MockRepository.GenerateMock<ICar>();
        carMock.Stub(x => x.EngineLight).Return(true);

        Assert.AreEqual(true, new Car().CheckEngineLight(carMock)); //This passes

        carMock.AssertWasCalled(x => x.GetOilChange()); //This fails
    }
 }
  • 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-16T16:35:36+00:00Added an answer on May 16, 2026 at 4:35 pm

    First off, this code has a bug. Add in the {} around the IF:

    public bool CheckEngineLight(ICar car)
        {
            if (car.EngineLight)
            {
                car.GetOilChange();
                return true;
            }
    
            return false;
        } 
    

    The reason it fails is because you are calling new Car().CheckEngineLight … and the new Car() is calling GetOilChange … the carMock is not calling GetOilChange. Change the code to car.GetOilChange() (see it in the code above).

    The fact that you are passing a Car object into a method on the Car Object is very confusing. Why not change the code to this:

    public class Car : ICar
    {
        public bool EngineLight { get; set; }
    
        public void GetOilChange()
        {
        }
    
        public bool CheckEngineLight()
        {
            if (EngineLight)
            {
                GetOilChange();
                return true;
            }
    
            return false;
        } 
    }
    

    Change your test to:

    [Test]
        public void WhenEngineLightIsOnGetOilChange()
        {
            var carMock = MockRepository.GenerateMock<ICar>();
            carMock.Stub(x => x.EngineLight).Return(true);
    
            Assert.AreEqual(true, carMock.CheckEngineLight()); 
    
            carMock.AssertWasCalled(x => x.GetOilChange()); 
        }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing around with the Windows api for uni, but I cant get
After playing around with links in Rails for a view hours i've managed to
Whilst playing around in an open source project, my attempt to ToString a DateTime
Im playing around with the soundcloud api , in its instructions it says to
Im playing around with web.py as a lightweight web framework. Im having problems when
I have been playing around with the concept of 'module' that some mvc frameworks
I was playing around the new swiftmailer 4.0.4 using my zend studio embbeded apache
I've been playing around with Mongo for about a week now and I still
I've been playing around with faceted search and the available display styles and wanted
I'm playing around with an idea(never played with TypeDescriptors before), and managed to get

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.