コード例 #1
0
        public void ExampleUsingCallbacks()
        {
            MockRepository mocks = new MockRepository();

            ISongBird maleBird   = (ISongBird)mocks.StrictMock(typeof(ISongBird)),
                      femaleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird));

            using (mocks.Ordered())
            {
                using (mocks.Unordered())
                {
                    maleBird.MoveToCage(null);
                    LastCall.On(maleBird).Callback(new CageDelegate(IsSameCage));
                    femaleBird.MoveToCage(null);
                    LastCall.On(femaleBird).Callback(new CageDelegate(IsSameCage));
                }
                maleBird.Eat("seeds", 250);
                femaleBird.Eat("seeds", 250);
                using (mocks.Unordered())
                {
                    maleBird.Mate(femaleBird);
                    femaleBird.Mate(maleBird);
                }
            }
            mocks.ReplayAll();

            BirdVeterinary vet = new BirdVeterinary();

            vet.Mate(maleBird, femaleBird);
            mocks.VerifyAll();
        }
コード例 #2
0
        public void ExampleUsingCallbacks()
        {
            ISongBird maleBird = (ISongBird)MockRepository.GenerateStrictMock(typeof(ISongBird), null, null),
                femaleBird = (ISongBird)MockRepository.GenerateStrictMock(typeof(ISongBird), null, null);

            maleBird.Expect(x => x.MoveToCage(null)).Callback(new CageDelegate(IsSameCage));
            femaleBird.Expect(x => x.MoveToCage(null)).Callback(new CageDelegate(IsSameCage));
            maleBird.Expect(x => x.Eat("seeds", 250));
            femaleBird.Expect(x => x.Eat("seeds", 250));
            maleBird.Expect(x => x.Mate(femaleBird));
            femaleBird.Expect(x => x.Mate(maleBird));

            BirdVeterinary vet = new BirdVeterinary();
            vet.Mate(maleBird, femaleBird);

            maleBird.AssertWasCalled(x => x.Eat("seeds", 250)).Before(femaleBird.AssertWasCalled(x => x.Eat("seeds", 250)));
            maleBird.VerifyAllExpectations();
            femaleBird.VerifyAllExpectations();
        }
コード例 #3
0
        public void ExampleUsingCallbacks()
        {
            MockRepository mocks = new MockRepository();

            ISongBird maleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird)),
                femaleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird));

            using (mocks.Ordered())
            {
                using (mocks.Unordered())
                {
                    maleBird.MoveToCage(null);
                    LastCall.On(maleBird).Callback(new CageDelegate(IsSameCage));
                    femaleBird.MoveToCage(null);
                    LastCall.On(femaleBird).Callback(new CageDelegate(IsSameCage));
                }
                maleBird.Eat("seeds", 250);
                femaleBird.Eat("seeds", 250);
                using (mocks.Unordered())
                {
                    maleBird.Mate(femaleBird);
                    femaleBird.Mate(maleBird);
                }
            }
            mocks.ReplayAll();

            BirdVeterinary vet = new BirdVeterinary();
            vet.Mate(maleBird, femaleBird);
            mocks.VerifyAll();
        }