You will only notice a difference between MockRepository.GenerateStub and MockRepository.GenerateMock when you call VerifyAllExpectations(). The only purpose of stubs is to feed indirect input into the system under test. Stubs will never throw exceptions to fail the test. Mocks can also feed indirect input into the system under test, but they check that their own methods where called and throw exceptions otherwise. Here are two additional tests illustrating the difference:
[Test]
public void PilotSearch_SearchCriteriaSpecified_SearchNotCalled_WithStub()
{
// Setup
IPilotManager pilotMngrStub = MockRepository.GenerateStub<IPilotManager>();
pilotMngrStub.Expect(p => p.Search(null)).Return(new List<Pilot>() { testPilot });
// Execute -> We do not call the Search() method, although it is expected
// Verify -> stubs will never throw exceptions
pilotMngrStub.VerifyAllExpectations();
}
[Test]
[ExpectedException(typeof(ExpectationViolationException))]
public void PilotSearch_SearchCriteriaSpecified_SearchNotCalled_WithMock()
{
// Setup
IPilotManager pilotMngrMock = MockRepository.GenerateMock<IPilotManager>();
pilotMngrMock.Expect(p => p.Search(null)).Return(new List<Pilot>() { testPilot });
// Execute -> We do not call the Search() method, although it is expected
// Verify- > will throw ExpectationViolationException
pilotMngrMock.VerifyAllExpectations();