public void Mocks_are_semantically_important_to_the_test()
        {
            var service = MockRepository.GenerateMock<IGameResultsService>();
            var game = new Game();

            game.StartGame(service);

            service.AssertWasCalled(s => s.DoSomething());
        }
            public void Mock_as_a_noun_is_part_of_the_test_assertions()
            {
                var mock = MockRepository.GenerateMock<IGameResultsService>();
                var game = new Game();

                game.StartGame(mock);

                mock.AssertWasCalled(m => m.DoSomething());
            }
            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 Use_AssertWasCalled_for_interaction_tests_on_a_mock()
        {
            const string expectedBand = "The Blues Brothers";
            var game = new Game();

            game.UpdateFavoriteBand(_mock, expectedBand);

            //Interaction-based test:
            _mock.AssertWasCalled(m => m.FavoriteBand = expectedBand);
        }
        public void AssertWasCalled_will_not_work_for_properties_on_a_stub()
        {
            const string expectedBand = "Rick Astley";
            var interactor = new Game();

            interactor.UpdateFavoriteBand(_stub, expectedBand);

            //Incorrectly failing test:
            _stub.AssertWasCalled(m => m.FavoriteBand = expectedBand);
        }
        public void Use_GetArgumentsForCallsMadeOn_to_inspect_arguments()
        {
            var game = new Game();

            game.GetMagicNumberTwice(_mock);

            IList<object[]> argsPerCall =
                _mock.GetArgumentsForCallsMadeOn(m => m.GetMagicNumber(null));
            argsPerCall[0][0].ShouldEqual("foo");
            argsPerCall[1][0].ShouldEqual("bar");
        }
            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 Use_PropertyBehavior_for_state_based_tests_on_a_mock()
        {
            const string expectedBand = "Philip Glass";
            var game = new Game();
            //This is not typical, but it is available:
            _mock.Stub(m => m.FavoriteBand).PropertyBehavior();

            game.UpdateFavoriteBand(_mock, expectedBand);

            //State-based test:
            _mock.FavoriteBand.ShouldEqual(expectedBand);
        }
        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 Stubs_do_not_verify_their_expectations()
        {
            //This is a legacy point.
            //I recommend the AssertWasCalled syntax over the VerifyAll.
            var service = MockRepository.GenerateStub<IGameResultsService>();
            var game = new Game();
            service.Expect(s => s.GetMagicNumber(Arg<string>.Is.Anything)).Return(4);

            game.IgnoreTheService(service);

            //This will silently pass, as if Game were meeting your expectations.
            //Falsely passing test.
            service.VerifyAllExpectations();
        }
        public void Only_mocks_verify_their_expectations()
        {
            //This is a legacy point.
            //I recommend the AssertWasCalled syntax over the VerifyAll.
            var service = MockRepository.GenerateMock<IGameResultsService>();
            var game = new Game();
            service.Expect(m => m.GetMagicNumber(Arg<string>.Is.Anything)).Return(4);

            game.IgnoreTheService(service);

            //This should (and does) throw an expectation violation.
            //Correctly failing test.
            service.VerifyAllExpectations();
        }
        public void Stubs_now_apply_AssertWasCalled()
        {
            //In prior versions of Rhino Mocks, AssertWasCalled and
            //AssertWasNotCalled on stubs would silently pass.
            var game = new Game();
            var service = MockRepository.GenerateStub<IGameResultsService>();

            game.IgnoreTheService(service);

            //This should (and does) throw an expectation violation in 3.5+.
            //Correctly failing test.
            service.AssertWasCalled(s => s.GetMagicNumber(Arg<string>.Is.Anything));
        }
        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 SetUp()
 {
     _mock = MockRepository.GenerateMock<IGameResultsService>();
     _game = new Game();
 }
 public void Setup()
 {
     _game = new Game();
     _service = new MockGameResultsService();
 }