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

Fluent API allows setting up a second callback that won't get involved if .Throws() is specified too #667

Closed
stakx opened this issue Aug 28, 2018 · 1 comment
Labels

Comments

@stakx
Copy link
Contributor

stakx commented Aug 28, 2018

This is currently (as of version 4.9.0) possible:

bool (firstCallbackInvoked, secondCallbackInvoked) = (false, false);

var mock = new Mock<object>();
mock.Setup(m => m.ToString())
    .Callback(() => firstCallbackInvoked = true)
    .Returns(() => default(string))
    .Callback(() => secondCallbackInvoked = true)
    .Throws<Exception>();

Assert.Throws<Exception>(() => mock.Object.ToString());
Assert.True(firstCallbackInvoked);
Assert.True(secondCallbackInvoked);

This fails because the second callback never gets invoked.

(This test doesn't make sense because it returns and throws simultaneously; see #665 concerning that. If the pattern of returning-then-throwing is forbidden, then we won't have to fix anything here.)

@stakx stakx added the bug label Aug 28, 2018
@stakx stakx added this to the 4.10.0 milestone Aug 28, 2018
@stakx stakx changed the title Fluent API allows setting up a second API that won't get involved if .Throws() is specified too Fluent API allows setting up a second callback that won't get involved if .Throws() is specified too Aug 28, 2018
@stakx
Copy link
Contributor Author

stakx commented Aug 28, 2018

This will be tracked in #668 along with some other closely related issues.

@stakx stakx closed this as completed Aug 28, 2018
@stakx stakx removed this from the 4.10.0 milestone Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant