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
Contributor

@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
Contributor 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 August 17, 2019 18:49
@michelcedric
Copy link

Yes thanks

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

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 August 23, 2019 11:37
@stakx stakx force-pushed the unmatchable-matchers-recognition branch from a011ed4 to 52eaecd Compare August 23, 2019 12:17
@stakx stakx merged commit 433c3ed into devlooped:master Aug 23, 2019
@stakx stakx deleted the unmatchable-matchers-recognition branch August 23, 2019 12:20
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.

Method without setup not return null
2 participants