Skip to content

Commit

Permalink
Matcher should always work with the whole expression, including Convert
Browse files Browse the repository at this point in the history
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<IFoo>(MockBehavior.Strict);
mock.Setup(x => x.M(int.Parse("2"))).Returns("OK");
var result = mock.Object.M(2L);
  • Loading branch information
svick committed Sep 26, 2013
1 parent 453f479 commit 8297c6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Source/MatcherFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
20 changes: 20 additions & 0 deletions UnitTests/Regressions/IssueReportsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFoo>(MockBehavior.Strict);
mock.Setup(x => x.M(int.Parse("2"))).Returns("OK");
Assert.Equal("OK", mock.Object.M(2L));
}
}

#endregion
}
}

0 comments on commit 8297c6a

Please sign in to comment.