public void Stub_as_a_noun_is_just_scaffolding() { var stub = MockRepository.GenerateStub<IGameResultsService>(); var game = new Game(); stub.Stub(s => s.GetMagicNumber(Arg<string>.Is.Anything)).Return(3); var result = game.CalculateMagicNumber(stub); result.ShouldEqual(3 + 7); }
public void Stub_as_a_verb_sets_up_behavior_on_mocks_and_stubs() { var mock = MockRepository.GenerateMock<IGameResultsService>(); var stub = MockRepository.GenerateStub<IGameResultsService>(); var game = new Game(); mock.Stub(m => m.GetMagicNumber(Arg<string>.Is.Anything)).Return(2); stub.Stub(m => m.GetMagicNumber(Arg<string>.Is.Anything)).Return(5); var result = game.CalculateMagicNumber(mock); result.ShouldEqual(2 + 7); }
public void Stubs_are_supporting_players() { var service = MockRepository.GenerateStub<IGameResultsService>(); const string magicWord = "something extra"; const int magicNumberSeed = 9; var game = new Game(); service.Stub(s => s.GetMagicNumber(magicWord)) .Return(magicNumberSeed); var result = game.CalculateMagicNumber(service, magicWord); Assert.That(result, Is.EqualTo(magicNumberSeed + 7)); }
public void You_can_stub_behavior_for_mocks_too() { var service = MockRepository.GenerateMock<IGameResultsService>(); const int magicNumberSeed = 9; const string magicWord = "something extra"; var game = new Game(); service.Stub(s => s.GetMagicNumber(Arg<string>.Is.Anything)) .Return(magicNumberSeed); var result = game.CalculateMagicNumber(service, magicWord); service.AssertWasCalled(s => s.GetMagicNumber(magicWord)); Assert.That(result, Is.EqualTo(magicNumberSeed + 7)); }
public void Stubs_now_apply_AssertWasNotCalled() { //In prior versions of Rhino Mocks, AssertWasCalled and //AssertWasNotCalled on stubs would silently pass. var game = new Game(); var service = MockRepository.GenerateStub<IGameResultsService>(); game.CalculateMagicNumber(service); //This should (and does) throw an expectation violation in 3.6. //Correctly failing test. service.AssertWasNotCalled(s => s.GetMagicNumber(Arg<string>.Is.Anything)); }