From 508e998ff6d9d4ad59f35f7357060c9567879650 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <5808377+304NotModified@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:04:53 +0200 Subject: [PATCH 01/11] Add Throws for exceptions to the docs --- .../2010-05-02-throwing-exceptions.markdown | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown index ade4d02b..0b500895 100644 --- a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown +++ b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown @@ -3,7 +3,34 @@ title: Throwing exceptions layout: post --- -[Callbacks](/help/callbacks) can be used to throw exceptions when a member is called. +The `Throws` and `ThrowsAsync` helpers in the namespace NSubstitute.ExceptionExtensions could be use d + + + + +```csharp +//For non-voids: +calculator.Add(-1, -1).Throws(new Exception()); // Or .Throws(); + +//For voids and non-voids: +calculator + .When(x => x.Add(-2, -2)) + .Throw(x => new Exception()); // Or .Throws(); + +//Both calls will now throw. +Assert.Throws(() => calculator.Add(-1, -1)); +Assert.Throws(() => calculator.Add(-2, -2)); +``` + + +### Returns +Another way is to use the underlyning method, .Returns. See also [Callbacks](/help/callbacks) +The `Throws` and `ThrowsAsync` helpers in the namespace NSubstitute.ExceptionExtensions could be use d ```csharp //For non-voids: @@ -31,14 +30,6 @@ Assert.Throws(() => calculator.Add(-2, -2)); ### Returns Another way is to use the underlying method, `.Returns`. See also [Callbacks](/help/callbacks) - - ```csharp //For non-voids: calculator.Add(-1, -1).Returns(x => { throw new Exception(); }); From b72e497ca561f44926d02f9f0cc9e2cecd45685c Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <5808377+304NotModified@users.noreply.github.com> Date: Wed, 24 Apr 2024 13:13:47 +0200 Subject: [PATCH 04/11] Using in requiredcode --- docs/help/_posts/2010-05-02-throwing-exceptions.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown index a911d957..213aa4d6 100644 --- a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown +++ b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown @@ -5,6 +5,7 @@ layout: post -The `Throws` and `ThrowsAsync` helpers in the namespace NSubstitute.ExceptionExtensions could be use d +The `Throws` and `ThrowsAsync` helpers in the `NSubstitute.ExceptionExtensions` namespace can be used to throw exceptions when a member is called. ```csharp //For non-voids: From bcd13b8d3ff9b12e2e292de7e240138f1a6117dd Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <5808377+304NotModified@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:13:02 +0200 Subject: [PATCH 09/11] Fix comment about throw*s* --- docs/help/_posts/2010-05-02-throwing-exceptions.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown index c25a0f09..5257ebf2 100644 --- a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown +++ b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown @@ -15,12 +15,12 @@ The `Throws` and `ThrowsAsync` helpers in the `NSubstitute.ExceptionExtensions` ```csharp //For non-voids: -calculator.Add(-1, -1).Throws(new Exception()); // Or .Throw() - don't use Throw*s* +calculator.Add(-1, -1).Throws(new Exception()); // Or .Throw() //For voids and non-voids: calculator .When(x => x.Add(-2, -2)) - .Throw(x => new Exception()); // Or .Throw(); + .Throw(x => new Exception()); // Or .Throw() - - don't use .Throw*s* in this case //Both calls will now throw. Assert.Throws(() => calculator.Add(-1, -1)); From d947986b034b5a7c1deca7469884170335b8b406 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <5808377+304NotModified@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:14:41 +0200 Subject: [PATCH 10/11] Added . --- docs/help/_posts/2010-05-02-throwing-exceptions.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown index 5257ebf2..7c29d801 100644 --- a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown +++ b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown @@ -28,7 +28,7 @@ Assert.Throws(() => calculator.Add(-2, -2)); ``` ### Returns -Another way is to use the underlying method, `.Returns`. See also [Callbacks](/help/callbacks) +Another way is to use the underlying method, `.Returns`. See also [Callbacks](/help/callbacks). ```csharp //For non-voids: From 184d0b4b77f950187e84a67d2a9cdd5997968b1d Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <5808377+304NotModified@users.noreply.github.com> Date: Sun, 28 Apr 2024 23:16:03 +0200 Subject: [PATCH 11/11] Fix comment --- docs/help/_posts/2010-05-02-throwing-exceptions.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown index 7c29d801..b7ef3adc 100644 --- a/docs/help/_posts/2010-05-02-throwing-exceptions.markdown +++ b/docs/help/_posts/2010-05-02-throwing-exceptions.markdown @@ -15,7 +15,7 @@ The `Throws` and `ThrowsAsync` helpers in the `NSubstitute.ExceptionExtensions` ```csharp //For non-voids: -calculator.Add(-1, -1).Throws(new Exception()); // Or .Throw() +calculator.Add(-1, -1).Throws(new Exception()); // Or .Throws() //For voids and non-voids: calculator