Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Fix VerifyAll + VerifyNoOtherCalls for sequence setups (devlooped…
Browse files Browse the repository at this point in the history
…#672)

* `VerifyAll` no longer marks sequence setups as invoked

This is a regression caused by the introduction of the new `Setup`
base class. `MethodCall.Execute` contains logic that marks invocations
as matched by a setup, which is required for `VerifyNoOtherCalls` to
work well together with `Verify[All]`.

Move this logic out of `MethodCall`.
  • Loading branch information
stakx committed Sep 1, 2018
1 parent f07b59b commit e074bfe
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/Moq/Interception/InterceptionAspects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ public override InterceptionAction Handle(Invocation invocation, Mock mock)
if (matchedSetup != null)
{
matchedSetup.Condition?.EvaluatedSuccessfully();

if (matchedSetup.IsVerifiable)
{
invocation.MarkAsMatchedByVerifiableSetup();
}
else
{
invocation.MarkAsMatchedBySetup();
}

matchedSetup.SetOutParameters(invocation);

// We first execute, as there may be a Throws
Expand Down
11 changes: 1 addition & 10 deletions src/Moq/MethodCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public string FailMessage

public override Condition Condition => this.condition;

protected override bool IsVerifiable => this.verifiable;
public override bool IsVerifiable => this.verifiable;

[Conditional("DESKTOP")]
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
Expand Down Expand Up @@ -131,15 +131,6 @@ public override void Execute(Invocation invocation)
{
++this.callCount;

if (this.verifiable)
{
invocation.MarkAsMatchedByVerifiableSetup();
}
else
{
invocation.MarkAsMatchedBySetup();
}

if (expectedMaxCallCount.HasValue && this.callCount > expectedMaxCallCount)
{
if (expectedMaxCallCount == 1)
Expand Down
4 changes: 2 additions & 2 deletions src/Moq/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ protected Setup(InvocationShape expectation, LambdaExpression expression)

public LambdaExpression Expression => this.expression;

public MethodInfo Method => this.expectation.Method;
public virtual bool IsVerifiable => false;

protected virtual bool IsVerifiable => false;
public MethodInfo Method => this.expectation.Method;

public abstract void Execute(Invocation invocation);

Expand Down
12 changes: 12 additions & 0 deletions tests/Moq.Tests/VerifyFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,18 @@ public void VerifyNoOtherCalls_works_with_a_combination_of_parameterised_Verify_
cat.VerifyNoOtherCalls();
}

[Fact]
public void VerifyNoOtherCalls_works_together_with_parameterless_VerifyAll_for_sequence_setups()
{
var mock = new Mock<ICat>();
mock.SetupSequence(x => x.Hiss());

mock.Object.Hiss();

mock.VerifyAll();
mock.VerifyNoOtherCalls();
}

public interface IBar
{
int? Value { get; set; }
Expand Down

0 comments on commit e074bfe

Please sign in to comment.