public void SetupResultWithNestedOrdering() { ISongBird maleBird = MockRepository.Mock <ISongBird>(); ISongBird femaleBird = MockRepository.Mock <ISongBird>(); 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(); }
public void ExampleUsingParameterMatchingAndConstraints() { ISongBird bird = MockRepository.Mock <ISongBird>(); bird.Expect(x => x.Eat("seeds", 500)); bird.Expect(x => x.Sing()) .Return("Chirp, Chirp"); bird.Expect(x => x.Sing()) .Throws(new Exception("No food, no song")); bird.Eat("seeds", 500); Assert.Equal("Chirp, Chirp", bird.Sing()); try { bird.Sing(); Assert.False(true, "Exception expected"); } catch (Exception e) { Assert.Equal("No food, no song", e.Message); } bird.VerifyAllExpectations(); }
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(); }
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(); }