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

Allow setting up null return values using Mock.Of #396

Merged
merged 2 commits into from
Jun 27, 2017

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Jun 27, 2017

This fixes #337.

Moq currently doesn't allow setting up a method to return `null` via
`Mock.Of`. At current, such a setup seems irrelevant as `null` is
often the default value that doesn't have to be set up explicitly.

However, if we want to allow custom default value providers in the
future, meaning that `null` might no longer be the default value in
all cases, it should be possible to set up `null` explicitly.
Setting up an explicit `null` return value in `Mock.Of` does not work
because a `null` constant in an expression tree is by default of type
`object`, which leads to a type mismatch when Moq uses that constant
to build a new binary expression to do a != comparison. Therefore make
sure to assign a compatible type to `null` const exprs.
@stakx stakx merged commit 1c6a1fa into devlooped:develop Jun 27, 2017
@stakx stakx deleted the setup-null-return branch June 27, 2017 22:20
@devlooped devlooped locked and limited conversation to collaborators Sep 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant