-
-
Notifications
You must be signed in to change notification settings - Fork 798
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
Method without setup not return null #897
Comments
This comment has been minimized.
This comment has been minimized.
Apologies, I misread your above post. This doesn't look like a duplicate. |
Setups with no .Returns(…) nor .CallBase() no longer return default(T) for loose mocks, but a value that is consistent with the mock's CallBase and DefaultValue[Provider] settings. #877 |
As per my last post, please ignore my initial statement, I was mistaken. As to your unit tests, your tests fail due to two basic misunderstandings on your part:
|
This unit test fail but in the setup I put DateTime and also during the invocation but it's fail? |
Like I already explained above: I suggest you read up on user-defined conversion operators and perhaps open up your code in a tool like ILDASM or ILSpy to see for yourself how |
Why not raise an exception in this case instead of just return null? |
That is a very valid question, and a good idea! Ideally, such situations would be flagged by a Roslyn analyzer, but since we haven't (yet?) got one for Moq, we could try to produce a runtime error. |
Hi,
I make a MockTestCase project : https://github.com/michelcedric/MockTestCase/blob/master/MockTest/UnitTest1.cs
When a method without setup is defined normaly he returns null.
But If the return it's a IEnumerable, it's return an empty list.
I think it's a strange behavior and I don't understand why not return null?
Best regards
Cédric Michel
The text was updated successfully, but these errors were encountered: