From 54d9af8ea8b667029b5e30a7582ce6868f1a976f Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Tue, 30 Apr 2024 22:53:40 +0200 Subject: [PATCH] Add testcase When Throws --- .../NSubstitute.Acceptance.Specs/WhenCalledDo.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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() {