Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VerifyNoOtherCalls take into account previous calls to parameterless Verify() and VerifyAll() #659

Merged
merged 3 commits into from
Aug 27, 2018

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Aug 19, 2018

This closes #607. See commit messages for details.

/cc @uecasm

Invoked = 0,
InvokedAndMatchedBySetup,
InvokedAndMatchedByVerifiableSetup,
Verified,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the logic implemented in the new Invocation methods ensures that we only ever progress from Invoked towards Verified, but it should never be possible to regress back to an earlier flag.

@@ -252,6 +252,11 @@ public void Verify()

private bool TryVerify(out MockException error)
{
foreach (Invocation invocation in this.MutableInvocations)

This comment was marked as resolved.

@@ -282,6 +287,11 @@ public void VerifyAll()

private bool TryVerifyAll(out MockException error)
{
foreach (Invocation invocation in this.MutableInvocations)

This comment was marked as resolved.

}

[Fact]
public void VerifyNoOtherCalls_works_together_with_parameterless_Verify()

This comment was marked as resolved.

@stakx
Copy link
Contributor Author

stakx commented Aug 19, 2018

@uecasm, may I ask you to briefly review this? I'd be glad if you could take a look at the tests I added in the first commit. Do we need to test anything else?

@stakx stakx changed the title Make VerifyNoOtherCalls play along nicely with parameterless Verify() and VerifyAll() Make VerifyNoOtherCalls take into account previous calls to parameterless Verify() and VerifyAll() Aug 19, 2018
@stakx stakx added this to the 4.9.1 milestone Aug 19, 2018
Add two tests that demonstrate how `VerifyNoOtherCalls` ought to
interact with both parameterless and parameterized `Verify` methods.

Currently, `VerifyNoOtherCalls` only works together with parameterized
`Verify`, but not with the parameterless variant (which internally is
actually very different as it targets setups, not invocations).

These tests are taken from:
devlooped#607
In order to get `VerifyNoOtherCalls` to interact properly with param-
eterless `Verify[All]()`, we need to check, at verification time, for
all invocations whether they were matched by a (verifiable) setup. If
we have M setups and N invocations, that would be up to M*N checks.

We can do something more efficient.

Moq already checks upon each invocation whether there is a setup that
matches it. So why not cache the result of that check with the invoc-
ation? That allows us to do a linear (N) scan during verification and
flag all setups as verified that were previously matched.

In order to support both `Verify()` and `VerifyAll()`, we need to
distinguish between verifiable setups and regular setups--that's why
the `verified` flag in `Invocation` becomes an enum with that many
options.
@stakx stakx merged commit a964fa7 into devlooped:master Aug 27, 2018
@stakx stakx deleted the verifynoothercalls branch August 27, 2018 13:23
@stakx
Copy link
Contributor Author

stakx commented Aug 27, 2018

@uecasm, merging for now. If you feel I've missed an important use case, please comment here or on the issue (#607) so we can add further tests, and/or adjust the implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verifiable vs VerifyNoOtherCalls
1 participant