Skip to content

Commit

Permalink
Add testcase When Throws
Browse files Browse the repository at this point in the history
  • Loading branch information
304NotModified committed Apr 30, 2024
1 parent 1f2fb0f commit 54d9af8
Showing 1 changed file with 16 additions and 0 deletions.
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

0 comments on commit 54d9af8

Please sign in to comment.