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

DefaultValue.Mock should not add redundant setups for already-matched invocations #1025

Merged
merged 3 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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