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

Fail when implicit conversion operator renders argument matcher unmatchable #900

Merged
merged 3 commits into from Aug 23, 2019

Conversation

stakx
Copy link
Member

@stakx stakx commented Aug 17, 2019

Closes #897, #898.

@stakx stakx added this to the 4.13.0 milestone Aug 17, 2019
@stakx
Copy link
Member Author

stakx commented Aug 17, 2019

@michelcedric: With this proposed change, your DateTimeNotWorking test from #897 would fail here:

serviceMock.Setup(s => s.GetDataList(It.IsAny<DateTime>())).Returns(_data);

with the following message:

System.ArgumentException: Matcher It.IsAny<DateTime>() is unmatchable: An implicit conversion operator will convert arguments of type DateTime to the parameter's type DateTimeOffset, which is assignment-incompatible.

Do you think this would be a helpful error message?

@stakx stakx force-pushed the unmatchable-matchers-recognition branch from 9d8e2c5 to 71ef9e7 Compare Aug 17, 2019
@michelcedric
Copy link

michelcedric commented Aug 19, 2019

Yes thanks

if (argument.NodeType == ExpressionType.Convert)
{
var convertExpression = (UnaryExpression)argument;
if (convertExpression.Method?.Name == "op_Implicit")
Copy link
Member Author

@stakx stakx Aug 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could take op_Implicit handling even further and evaluate it if it isn't applied to an argument matcher.

@stakx stakx force-pushed the unmatchable-matchers-recognition branch 2 times, most recently from b88e7b3 to a011ed4 Compare Aug 23, 2019
@stakx stakx force-pushed the unmatchable-matchers-recognition branch from a011ed4 to 52eaecd Compare Aug 23, 2019
@stakx stakx merged commit 433c3ed into moq:master Aug 23, 2019
1 of 2 checks passed
@stakx stakx deleted the unmatchable-matchers-recognition branch Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants