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

Demo: When Throws gives CouldNotSetReturnDueToNoLastCallException #802

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/NSubstitute.Acceptance.Specs/WhenCalledDo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NSubstitute.Acceptance.Specs.Infrastructure;
using NSubstitute.Core;
using NUnit.Framework;
using NSubstitute.ExceptionExtensions;

namespace NSubstitute.Acceptance.Specs;

Expand Down Expand Up @@ -94,6 +95,21 @@ public void Throw_exception_when_Throw_with_specific_exception()
Assert.That(called, Is.EqualTo(1));
}


[Test]
public void Throw_exception_when_Throws_with_specific_exception()
{
var exception = new IndexOutOfRangeException("Test");
int called = 0;
_something.When(x => x.Echo(Arg.Any<int>())).Do(x => called++);
_something.When(x => x.Echo(Arg.Any<int>())).Throws(exception);

Assert.That(called, Is.EqualTo(0), "Should not have been called yet");
IndexOutOfRangeException thrownException = Assert.Throws<IndexOutOfRangeException>(() => _something.Echo(1234));
Assert.That(thrownException, Is.EqualTo(exception));
Assert.That(called, Is.EqualTo(1));
}

[Test]
public void Throw_exception_when_Throw_with_exception_generator()
{
Expand Down
Loading