I've posted this to the Moq discussion forum but I think it warrants its own post here too.

One of the (very minor) limitations we struck with Moq if that if you expect to call the same method more than once and get a different result each time, there's no straight forward way to set that up. If you try this:

mockCommand.Expect(c => c.CreateParameter()).Returns(mockParam1.Object);
mockCommand.Expect(c => c.CreateParameter()).Returns(mockParam2.Object);

... then when your code calls CreateParameter() it'll just get the "mockParam2" object back twice, because the second expectation has "overwritten" the first.

We stumbled upon a nice workaround for this particular problem using an overload of IExpect.Returns which takes an expression rather than a value. Basically, every time the expected method is called, the expression is evaluated and its result is returned. So we use an expression to return a series of values, one after the other. Even nicer, we do so using the generic Queue object. Here's the code:

var pq = new Queue<IDbDataParameter>(new[]
    { 
        mockParam1.Object, 
        mockParam2.Object 
    });
mockCommand.Expect(c => c.CreateParameter()).Returns(() => pq.Dequeue());

See what's happening? We "queue up" two parameters, and then "dequeue" them as the CreateParameter is called each time.

I know that the Moq guys are considering some sort of "sequence" feature to overcome the "successive expectations overwrite the previous ones" problem, but this queuing method works a treat for us.