Skip to content

Commit b72df13

Browse files
authored
Merge pull request #1025 from stakx/defaultvalue-mock-regression
`DefaultValue.Mock` should not add redundant setups for already-matched invocations
2 parents d5552d5 + 63d2a86 commit b72df13

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is loosely based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

77

8+
## Unreleased
9+
10+
#### Fixed
11+
12+
* Regression: `Verify` behavior change using `DefaultValue.Mock` (@DesrosiersC, #1024)
13+
14+
815
## 4.14.1 (2020-04-28)
916

1017
#### Added

src/Moq/Interception/InterceptionAspects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static void Handle(Invocation invocation, Mock mock)
262262
else
263263
{
264264
var returnValue = mock.GetDefaultValue(method, out var innerMock);
265-
if (innerMock != null)
265+
if (innerMock != null && invocation.MatchingSetup == null)
266266
{
267267
mock.AddInnerMockSetup(invocation, returnValue);
268268
}

tests/Moq.Tests/Regressions/IssueReportsFixture.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,28 @@ public interface IX
33133313

33143314
#endregion
33153315

3316+
#region 1024
3317+
3318+
public class Issue1024
3319+
{
3320+
[Fact]
3321+
public void Verify_passes_when_DefaultValue_Mock_and_setup_without_any_Returns()
3322+
{
3323+
var totoMock = new Mock<IToto>() { DefaultValue = DefaultValue.Mock };
3324+
totoMock.Setup(o => o.Do()).Verifiable();
3325+
3326+
totoMock.Object.Do();
3327+
3328+
totoMock.Verify();
3329+
}
3330+
3331+
public interface IToto
3332+
{
3333+
IList<string> Do();
3334+
}
3335+
}
3336+
#endregion
3337+
33163338
// Old @ Google Code
33173339

33183340
#region #47

0 commit comments

Comments
 (0)