Ejemplo n.º 1
0
        public void OrderedExecutionOfUnorderedSequence()
        {
            MockRepository mocks      = new MockRepository();
            ISongBird      maleBird   = (ISongBird)mocks.StrictMock(typeof(ISongBird)),
                           femaleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird));

            using (mocks.Ordered())
            {
                using (mocks.Unordered())
                {
                    maleBird.Eat("seeds", 250);
                    femaleBird.Eat("seeds", 250);
                }

                using (mocks.Unordered())
                {
                    maleBird.Mate(femaleBird);
                    femaleBird.Mate(maleBird);
                }
            }
            mocks.ReplayAll();

            femaleBird.Eat("seeds", 250);
            maleBird.Eat("seeds", 250);

            femaleBird.Mate(maleBird);
            maleBird.Mate(femaleBird);

            mocks.VerifyAll();
        }
Ejemplo n.º 2
0
        public void SetupResultWithNestedOrdering()
        {
            MockRepository mocks      = new MockRepository();
            ISongBird      maleBird   = (ISongBird)mocks.StrictMock(typeof(ISongBird)),
                           femaleBird = (ISongBird)mocks.StrictMock(typeof(ISongBird));

            SetupResult.On(maleBird).Call(maleBird.Sing()).Return("");
            using (mocks.Ordered())
            {
                using (mocks.Unordered())
                {
                    maleBird.Eat("seeds", 250);
                    femaleBird.Eat("seeds", 250);
                }

                using (mocks.Unordered())
                {
                    maleBird.Mate(femaleBird);
                    femaleBird.Mate(maleBird);
                }
            }
            mocks.ReplayAll();

            maleBird.Sing();
            femaleBird.Eat("seeds", 250);
            maleBird.Sing();
            maleBird.Eat("seeds", 250);

            maleBird.Sing();
            femaleBird.Mate(maleBird);
            maleBird.Sing();
            maleBird.Mate(femaleBird);
            maleBird.Sing();
            mocks.VerifyAll();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 4
0
        public void SetupResultWithNestedOrdering()
        {
            ISongBird maleBird = MockRepository.Mock <ISongBird>();

            maleBird.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
            ISongBird femaleBird = MockRepository.Mock <ISongBird>();

            femaleBird.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            maleBird.Stub(x => x.Sing())
            .Return("");

            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));

            maleBird.Sing();
            femaleBird.Eat("seeds", 250);
            maleBird.Sing();
            maleBird.Eat("seeds", 250);

            maleBird.Sing();
            femaleBird.Mate(maleBird);
            maleBird.Sing();
            maleBird.Mate(femaleBird);
            maleBird.Sing();

            maleBird.VerifyAllExpectations();
            femaleBird.VerifyAllExpectations();
        }
Ejemplo n.º 5
0
 public void Mate(ISongBird male, ISongBird female)
 {
     female.MoveToCage(cage);
     male.MoveToCage(cage);
     male.Eat("seeds", 250);
     female.Eat("seeds", 250);
     male.Mate(female);
     female.Mate(male);
 }
Ejemplo n.º 6
0
 public void Mate(ISongBird male, ISongBird female)
 {
     female.MoveToCage(cage);
     male.MoveToCage(cage);
     male.Eat("seeds", 250);
     female.Eat("seeds", 250);
     male.Mate(female);
     female.Mate(male);
 }
Ejemplo n.º 7
0
        public void OrderedExecutionOfUnorderedSequence()
        {
            ISongBird maleBird   = MockRepository.Mock <ISongBird>();
            ISongBird femaleBird = MockRepository.Mock <ISongBird>();

            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));

            femaleBird.Eat("seeds", 250);
            maleBird.Eat("seeds", 250);

            femaleBird.Mate(maleBird);
            maleBird.Mate(femaleBird);

            maleBird.VerifyAllExpectations();
            femaleBird.VerifyAllExpectations();
        }
Ejemplo n.º 8
0
        public void OrderedExecutionOfUnorderedSequence()
        {
            ISongBird maleBird = MockRepository.Mock <ISongBird>();

            maleBird.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);
            ISongBird femaleBird = MockRepository.Mock <ISongBird>();

            femaleBird.SetUnexpectedBehavior(UnexpectedCallBehaviors.BaseOrDefault);

            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));

            femaleBird.Eat("seeds", 250);
            maleBird.Eat("seeds", 250);

            femaleBird.Mate(maleBird);
            maleBird.Mate(femaleBird);

            maleBird.VerifyAllExpectations();
            femaleBird.VerifyAllExpectations();
        }