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

Throws() bug for a NotImplemented Func<Task> #42

Open
chris-findlay opened this issue Jan 3, 2019 · 1 comment
Open

Throws() bug for a NotImplemented Func<Task> #42

chris-findlay opened this issue Jan 3, 2019 · 1 comment

Comments

@chris-findlay
Copy link
Contributor

PAssert.Throws<TException>(Action a, ...) has the expected try/catch structure, but PAssert.Throws<TException>(Func<Task> a, ...) does not - the latter handles the case of the task faulting, but does not work if the code returning the task fails in any synchronous way, e.g:

public Task DoSomethingAsync() { throw new NotImplementedException(); }
---
[Test]
public void TestIt() {
    PAssert.Throws<NotImplementedException>(() => obj.DoSomethingAsync());
}

This results in the NIE bubbling up out of the Throws call, as it doesn't check that the setup works, only that the resulting task does (or rather doesn't - i.e. that the Task faults).

@chris-findlay
Copy link
Contributor Author

chris-findlay commented Jan 3, 2019

I tried wrapping the content of Throws<>(Func<Task>...) in a try catch like the other one, but the catch needs to return a Task<TException> and not just TException, so I used Task.FromResult(), but get a compile error that says
error CS0117: 'Task' does not contain a definition for 'FromResult'
which I completely don't understand, given what's in scope at the time...

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

1 participant