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

Returning null #181

Closed
wants to merge 4 commits into from
Closed

Returning null #181

wants to merge 4 commits into from

Conversation

mwereda
Copy link

@mwereda mwereda commented Mar 24, 2015

I added two methods that configure method call to return null:

  1. ReturnNull()
  2. ReturnNullForAnyArgs()

Using one of these methods allows to write more easily code - instead of using
something.SomeAction().Returns(i=> null) it can be written that way: something.SomeAction().ReturnsNull().
With intellisense it's much easier to write call that should return null. In my opinion it's also much more verbose.

I've placed both methods in separate namespace so main namespace doesn't have too much mtehods.

@veihan
Copy link

veihan commented Mar 25, 2015

overkill?

@mwereda
Copy link
Author

mwereda commented Mar 26, 2015

I think it's not overkill.
Sometimes you need/want stub's method to return null and write logic that deal with that null. With my team we've created extension method ReturnsNull and it's much faster for us to use it instead of writing something.SomeAction().Returns(i=> null). Especially when you user R# pressing R and N keys and Enter after that - it speeds code writing a little bit up.

I'm aware that this could be not mostly used method. That's why I've placed it in another namespace.

@veihan
Copy link

veihan commented Mar 26, 2015

Ok.

Btw. R# as R language, ported to C# ex. R.NET?

@mwereda
Copy link
Author

mwereda commented Mar 26, 2015

@veihan - I meant ReSharper

@veihan
Copy link

veihan commented Mar 26, 2015

lol

@veihan
Copy link

veihan commented Mar 26, 2015

I'm a nice guy mostly, so don't get me wrong here. This has already been discussed and it was answered by @dtchepak in late 2012 (read it #87) and generally the idea was rejected.
I'm recommending to use function:
OrderBy(x => check all issues of NS).ThenBy(x => collaborate).ThenBy(x => fix, change).

@mwereda
Copy link
Author

mwereda commented May 27, 2015

Hi, any chances to add this CR to NSubstitute codebase?

@dtchepak dtchepak mentioned this pull request May 29, 2015
@dtchepak
Copy link
Member

Hi Michal,
Sorry for the delay in getting back to you. I've included this in release 1.8.2. Thanks for the contribution.

As an aside I'm wary of including many more extensions like this; I want to avoid the situation where people find NSub works differently than they expect because there are fewer imports than a code sample they look at. I've let this one through just because it has kept coming up. :)

Cheers,
David

@dtchepak dtchepak closed this May 29, 2015
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.

None yet

3 participants