diff --git a/tests/NSubstitute.Acceptance.Specs/WhenCalledDo.cs b/tests/NSubstitute.Acceptance.Specs/WhenCalledDo.cs index 8b001a0e..79693524 100644 --- a/tests/NSubstitute.Acceptance.Specs/WhenCalledDo.cs +++ b/tests/NSubstitute.Acceptance.Specs/WhenCalledDo.cs @@ -1,6 +1,7 @@ using NSubstitute.Acceptance.Specs.Infrastructure; using NSubstitute.Core; using NUnit.Framework; +using NSubstitute.ExceptionExtensions; namespace NSubstitute.Acceptance.Specs; @@ -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())).Do(x => called++); + _something.When(x => x.Echo(Arg.Any())).Throws(exception); + + Assert.That(called, Is.EqualTo(0), "Should not have been called yet"); + IndexOutOfRangeException thrownException = Assert.Throws(() => _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() {