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

Add a .SetupThrowsDefault<T>() to configure a mock to throw w/o specifying a method #281

Closed
sbrockway opened this issue Aug 16, 2016 · 4 comments

Comments

@sbrockway
Copy link

It would be useful if I could configure a mock to throw an exception when any member is accessed, without having to first declare a specific member via .Setup() in order to configure .Throws()

Similar to the feature Mock.SetupReturnsDefault() provides for specifying a return value without first specifying a member via .Setup()

For example:
mockDependency.SetupThrowsDefault<Exception>();
or
mockDependency.SetupThrowsDefault(new Exception());

If this sounds like a good idea, I'd be willing to fork and try it.

@kzu
Copy link
Member

kzu commented Aug 25, 2016

Wouldn't that be the same as creating a strict mock?

@sbrockway
Copy link
Author

Yes. That does the trick. I forgot about Strict. Thanks @kzu !
Is it possible to change the mock's behavior after instantiation? I see the property is read-only.

@kzu
Copy link
Member

kzu commented Aug 25, 2016

Nope, you can't :(

On Thu, Aug 25, 2016 at 1:09 PM sbrockway notifications@github.com wrote:

Yes. That does the trick. I forgot about Strict. Thanks @kzu
https://github.com/kzu !
Is it possible to change the mock's behavior after instantiation? I see
the property is read-only.


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#281 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAKW68QEuPmvjYgB_oFvIImKAzw1EQThks5qjb43gaJpZM4Jlvru
.

/kzu from mobile

@sbrockway
Copy link
Author

Thanks for the info @kzu !
Closing the issue as the requested functionality is available via: new Mock<>(MockBehavior.Strict);

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

No branches or pull requests

2 participants