From 8297c6a55cf1fed098fc50ce58559a2100e857a8 Mon Sep 17 00:00:00 2001 From: Petr Onderka Date: Wed, 18 Sep 2013 20:01:07 +0200 Subject: [PATCH] Matcher should always work with the whole expression, including Convert Without this change, the following code doesn't work correctly, because the passed in long is compared against int. interface IFoo { string M(long l); } var mock = new Mock(MockBehavior.Strict); mock.Setup(x => x.M(int.Parse("2"))).Returns("OK"); var result = mock.Object.M(2L); --- Source/MatcherFactory.cs | 6 +++--- UnitTests/Regressions/IssueReportsFixture.cs | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Source/MatcherFactory.cs b/Source/MatcherFactory.cs index db8463458..2ae048921 100644 --- a/Source/MatcherFactory.cs +++ b/Source/MatcherFactory.cs @@ -99,19 +99,19 @@ public static IMatcher CreateMatcher(Expression expression, bool isParams) if (attr != null) { var matcher = attr.CreateMatcher(); - matcher.Initialize(expression); + matcher.Initialize(originalExpression); return matcher; } else if (staticMatcherMethodAttr != null) { var matcher = new MatcherAttributeMatcher(); - matcher.Initialize(expression); + matcher.Initialize(originalExpression); return matcher; } else { var matcher = new LazyEvalMatcher(); - matcher.Initialize(expression); + matcher.Initialize(originalExpression); return matcher; } } diff --git a/UnitTests/Regressions/IssueReportsFixture.cs b/UnitTests/Regressions/IssueReportsFixture.cs index f237ceb21..676a36860 100644 --- a/UnitTests/Regressions/IssueReportsFixture.cs +++ b/UnitTests/Regressions/IssueReportsFixture.cs @@ -1889,5 +1889,25 @@ public interface IServiceContract #endif #endregion + + #region Matcher should work with Convert + + public class MatcherConvertFixture + { + public interface IFoo + { + string M(long l); + } + + [Fact] + public void MatcherDoesNotIgnoreConvert() + { + var mock = new Mock(MockBehavior.Strict); + mock.Setup(x => x.M(int.Parse("2"))).Returns("OK"); + Assert.Equal("OK", mock.Object.M(2L)); + } + } + + #endregion } }