Skip to content

Commit

Permalink
Verify[All] should mark invocations of conditional setups
Browse files Browse the repository at this point in the history
While this is a step away from being able to expose a generic
`Verify(setupPredicate)` method, we need to do this for back-compat.

A future `Verify(setupPredicate)` method will simply have to have
slightly different behavior where the same predicate applies on both
the setup & invocation sides.

(This commit also removes a superfluous double predicate check.)
  • Loading branch information
stakx committed Dec 28, 2020
1 parent f4ab8b5 commit 6307c0b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1

* Performance regression: Adding setups to a mock becomes slower with each setup (@CeesKaas, #1110)

* Regression: `mock.Verify[All]` no longer marks invocations as verified if they were matched by conditional setups. (@Lyra2108, #1114)


## 4.15.2 (2020-11-26)

#### Changed
Expand Down
8 changes: 4 additions & 4 deletions src/Moq/Mock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public DefaultValue DefaultValue
/// </example>
public void Verify()
{
this.Verify(setup => !setup.IsOverridden && !setup.IsConditional && setup.IsVerifiable);
this.Verify(setup => setup.IsVerifiable);
}

/// <summary>
Expand All @@ -283,7 +283,7 @@ public void Verify()
/// </example>
public void VerifyAll()
{
this.Verify(setup => !setup.IsOverridden && !setup.IsConditional);
this.Verify(setup => true);
}

private void Verify(Func<ISetup, bool> predicate)
Expand Down Expand Up @@ -313,9 +313,9 @@ internal bool TryVerify(Func<ISetup, bool> predicate, HashSet<Mock> verifiedMock

var errors = new List<MockException>();

foreach (var setup in this.MutableSetups.ToArray(predicate))
foreach (var setup in this.MutableSetups.ToArray(setup => !setup.IsOverridden && !setup.IsConditional && predicate(setup)))
{
if (predicate(setup) && !setup.TryVerify(recursive: true, predicate, verifiedMocks, out var e) && e.IsVerificationError)
if (!setup.TryVerify(recursive: true, predicate, verifiedMocks, out var e) && e.IsVerificationError)
{
errors.Add(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Moq/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ protected virtual void ResetCore()

public void Verify(bool recursive = true)
{
this.Verify(recursive, setup => !setup.IsOverridden && !setup.IsConditional && setup.IsVerifiable);
this.Verify(recursive, setup => setup.IsVerifiable);
}

public void VerifyAll()
{
this.Verify(recursive: true, setup => !setup.IsOverridden && !setup.IsConditional);
this.Verify(recursive: true, setup => true);
}

private void Verify(bool recursive, Func<ISetup, bool> predicate)
Expand Down

0 comments on commit 6307c0b

Please sign in to comment.