Skip to content

Commit 94bc61c

Browse files
committed
Add test for HttpPolicyResultException.InnerException with one failed pipeline handler and external handler that throws.
1 parent cf4f0b6 commit 94bc61c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/PipelineTests.For.InnerException.Of.HttpPolicyResultException.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.DependencyInjection;
22
using NUnit.Framework;
3+
using System;
34
using System.Net.Http;
45

56
namespace PoliNorError.Extensions.Http.Tests
@@ -61,5 +62,36 @@ public void Should_InnerException_Be_HttpRequestException_For_Out_Of_Pipeline_So
6162
Assert.That(exception?.InnerException?.GetType(), Is.EqualTo(typeof(HttpRequestException)));
6263
}
6364
}
65+
66+
[Test]
67+
public void Should_Have_FinalHandler_Exception_As_InnerException_With_One_PipelineHandler_And_ExternalHandler_That_Throws()
68+
{
69+
var testPolicy = new PolicyWithNotFilterableError(() => throw new ArgumentException("Test"), typeof(ArgumentException));
70+
71+
HttpErrorFilterCriteria criteria = HttpErrorFilter.None();
72+
73+
var services = new ServiceCollection();
74+
75+
services.AddFakeHttpClient()
76+
.WithResiliencePipeline((empyConfig) => empyConfig
77+
.AddPolicyHandler(testPolicy)
78+
.AsFinalHandler(criteria)
79+
);
80+
81+
var serviceProvider = services.BuildServiceProvider();
82+
83+
using (var scope = serviceProvider.CreateScope())
84+
{
85+
var sut = scope.ServiceProvider.GetRequiredService<IHttpClientFactory>().CreateClient("my-httpclient");
86+
var request = new HttpRequestMessage(HttpMethod.Get, "/any");
87+
88+
var exception = Assert.ThrowsAsync<HttpPolicyResultException>(async () => await sut.SendAsync(request));
89+
90+
Assert.That(exception?.HasFailedResponse == true, Is.False);
91+
92+
Assert.That(exception?.ThrownByFinalHandler == true, Is.True);
93+
Assert.That(exception?.InnerException?.GetType(), Is.EqualTo(typeof(ArgumentException)));
94+
}
95+
}
6496
}
6597
}

0 commit comments

Comments
 (0)