|
1 | 1 | using Microsoft.Extensions.DependencyInjection; |
2 | 2 | using NUnit.Framework; |
| 3 | +using System; |
3 | 4 | using System.Net.Http; |
4 | 5 |
|
5 | 6 | namespace PoliNorError.Extensions.Http.Tests |
@@ -61,5 +62,36 @@ public void Should_InnerException_Be_HttpRequestException_For_Out_Of_Pipeline_So |
61 | 62 | Assert.That(exception?.InnerException?.GetType(), Is.EqualTo(typeof(HttpRequestException))); |
62 | 63 | } |
63 | 64 | } |
| 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 | + } |
64 | 96 | } |
65 | 97 | } |
0 commit comments