NSubstitute
NSubstitute copied to clipboard
.When(...).Throws gives a CouldNotSetReturnDueToNoLastCallException
Describe the bug
This is of course a bug in the user code, as we should use Throw instead of Throws. But the exception is at least not clear
And it's confusing, IntelliSense in VS 2022 also suggest throws:
To Reproduce See https://github.com/nsubstitute/NSubstitute/pull/802
Expected behaviour
- Just work
- Or give a clear error
Environment:
- NSubstitute version: 5.1
- NSubstitute.Analyzers version: c# 1.0.17
- Platform: .NET 8
Additional context
The analyzer gives a error, but that one is still a bit confusing
There are multiple options:
- Or give a clear error
- Or also implement Throws on
WhenCalled(not sure if this is a binary breaking change?) - Or delegate Throws to WhenCalled.Throw - this is difficult as Throws returns a ConfiguredCall and Throw is
void