Skip to content

Commit

Permalink
Merge pull request #1025 from stakx/defaultvalue-mock-regression
Browse files Browse the repository at this point in the history
`DefaultValue.Mock` should not add redundant setups for already-matched invocations
  • Loading branch information
stakx committed Jun 16, 2020
2 parents d5552d5 + 63d2a86 commit b72df13
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).


## Unreleased

#### Fixed

* Regression: `Verify` behavior change using `DefaultValue.Mock` (@DesrosiersC, #1024)


## 4.14.1 (2020-04-28)

#### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Moq/Interception/InterceptionAspects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static void Handle(Invocation invocation, Mock mock)
else
{
var returnValue = mock.GetDefaultValue(method, out var innerMock);
if (innerMock != null)
if (innerMock != null && invocation.MatchingSetup == null)
{
mock.AddInnerMockSetup(invocation, returnValue);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Moq.Tests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3313,6 +3313,28 @@ public interface IX

#endregion

#region 1024

public class Issue1024
{
[Fact]
public void Verify_passes_when_DefaultValue_Mock_and_setup_without_any_Returns()
{
var totoMock = new Mock<IToto>() { DefaultValue = DefaultValue.Mock };
totoMock.Setup(o => o.Do()).Verifiable();

totoMock.Object.Do();

totoMock.Verify();
}

public interface IToto
{
IList<string> Do();
}
}
#endregion

// Old @ Google Code

#region #47
Expand Down

0 comments on commit b72df13

Please sign in to comment.