From 39743feb525715fa7a896d8ebd29c2b2fe55216c Mon Sep 17 00:00:00 2001 From: stakx Date: Tue, 16 Jun 2020 21:28:18 +0200 Subject: [PATCH 1/3] Regression with `Verify` & `DefaultValue.Mock` --- .../Regressions/IssueReportsFixture.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/Moq.Tests/Regressions/IssueReportsFixture.cs b/tests/Moq.Tests/Regressions/IssueReportsFixture.cs index 4b41ba9bd..57aa4c4e4 100644 --- a/tests/Moq.Tests/Regressions/IssueReportsFixture.cs +++ b/tests/Moq.Tests/Regressions/IssueReportsFixture.cs @@ -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() { DefaultValue = DefaultValue.Mock }; + totoMock.Setup(o => o.Do()).Verifiable(); + + totoMock.Object.Do(); + + totoMock.Verify(); + } + + public interface IToto + { + IList Do(); + } + } + #endregion + // Old @ Google Code #region #47 From 2b1b13903e9dbb1a077723c41a6c91bcb5bf490d Mon Sep 17 00:00:00 2001 From: stakx Date: Tue, 16 Jun 2020 21:31:10 +0200 Subject: [PATCH 2/3] Skip `DefaultValue.Mock` behavior for matched invocations --- src/Moq/Interception/InterceptionAspects.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Moq/Interception/InterceptionAspects.cs b/src/Moq/Interception/InterceptionAspects.cs index f2b63f8c9..0bd196c2e 100644 --- a/src/Moq/Interception/InterceptionAspects.cs +++ b/src/Moq/Interception/InterceptionAspects.cs @@ -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); } From 63d2a866b0475d90f7d698c647d7d7fc4eb311a0 Mon Sep 17 00:00:00 2001 From: stakx Date: Tue, 16 Jun 2020 21:34:43 +0200 Subject: [PATCH 3/3] Update the changelog --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e727c71..6bda32a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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