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
}
}