Re: [moq4] MockSequence and VerifyAll (#75)

60 views
Skip to first unread message

Daniel Cazzulino

unread,
Dec 18, 2013, 10:40:42 PM12/18/13
to Moq/moq4, Moq/moq4, moqdisc

Good point. What should be the expected behavior?

/kzu from mobile

On Dec 18, 2013 7:33 PM, "Henrique Esteves" <notifi...@github.com> wrote:

When using a "MockSequence" the behavior of the "VerifyAll" method is modified. Is this correct?

public interface IFoo
{
    void Do();
}

/*
 * Throws MockVerificationException
 */
var foo = new Mock<IFoo>(MockBehavior.Strict);

foo.Setup(f => f.Do());
foo.VerifyAll();

/*
 * Does not throw MockVerificationException
 */
var foo = new Mock<IFoo>(MockBehavior.Strict);
var seq = new MockSequence();

foo.InSequence(seq).Setup(f => f.Do());
foo.VerifyAll();


Reply to this email directly or view it on GitHub.

Daniel Cazzulino

unread,
Dec 19, 2013, 1:32:23 PM12/19/13
to Moq/moq4, Moq/moq4, moqdisc
there's a key issue here that I think is missing: a sequence can be used across several mocks. 

So any single mock in that sequence will not be able to verify that it was called before/after any of the calls in the sequence for the other mocks. 

I believe that's a great powerful feature of sequences as implemented currently, and I can't see how we could add this verification behavior without introducing a very confusing behavior for cross-mocks verification.

I think verifying the sequence when you have sequenced calls is the right thing to do.


/kzu

--
Daniel Cazzulino


On Thu, Dec 19, 2013 at 1:40 PM, Henrique Esteves <notifi...@github.com> wrote:

The previous examples were not very good because I've just described the behavior that is already correct.

The following example demonstrates how a "MockSequence" causes the "VerifyAll" method to be less restrictive, while in my opinion, it should be more restrictive.

/*
 * Does not throw MockVerificationException, but in my opinion it should
 */
var foo = new Mock<IFoo>(MockBehavior.Strict);
var seq = new MockSequence();

foo.InSequence(seq).Setup(f => f.DoOne());
foo.InSequence(seq).Setup(f => f.DoTwo());

var obj = foo.Object;

obj.DoOne();

foo.VerifyAll();
Reply all
Reply to author
Forward
0 new messages