Skip to content

Commit

Permalink
Fixed async response interceptors don't get invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-berg committed Dec 2, 2020
1 parent d09abae commit 65e58d0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/Appeaser.Tests/PipelineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ public void TestInterception()
Assert.True(interceptor.ResponseWasIntercepted);
}

[Fact]
public void TestInterceptionAsync()
{
var interceptor = new Interceptor();
var settings = new MediatorSettings().AddInterceptor<Interceptor>();
A.CallTo(() => _handler.GetHandler(A<Type>.That.IsEqualTo(typeof(Interceptor)))).Returns(interceptor);
var mediator = new Mediator(_handler, settings);

mediator.Send(new CommandFeature.AsyncCommand());

Assert.True(interceptor.RequestWasIntercepted);
Assert.True(interceptor.ResponseWasIntercepted);
}

[Fact]
public void TestReponseExceptionInterception()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Appeaser/Appeaser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFrameworks>netstandard2.0;netstandard1.0;net45</TargetFrameworks>
<Authors>Carl Berg</Authors>
<Copyright>Copyright (c) $([System.DateTime]::Now.Year) Carl Berg</Copyright>
<VersionPrefix>2.3.3</VersionPrefix>
<VersionPrefix>2.3.4</VersionPrefix>
<DisableImplicitFrameworkReferences Condition=" '$(TargetFramework)' == 'net45' ">true</DisableImplicitFrameworkReferences>
<Description>Appeaser, the appeasing mediator</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
4 changes: 2 additions & 2 deletions src/Appeaser/Interception/MediatorInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<TResponse> InvokeHandlerAsync<TResponse>(object handler, objec

var result = await invocation(scope);

foreach (var interceptor in ResolveInterceptors<IRequestInterceptor>(x => x.ResponseInterceptors).Reverse())
foreach (var interceptor in ResolveInterceptors<IResponseInterceptor>(x => x.ResponseInterceptors).Reverse())
{
await interceptor.InterceptAsync(scope.CreateResponseInterceptionContext<TResponse>(result));
}
Expand All @@ -70,7 +70,7 @@ public async Task<TResponse> InvokeHandlerAsync<TResponse>(object handler, objec
catch (Exception ex)
{
var exception = ex is TargetInvocationException ? ex.InnerException : ex;
foreach (var interceptor in ResolveInterceptors<IRequestInterceptor>(x => x.ResponseInterceptors).Reverse())
foreach (var interceptor in ResolveInterceptors<IResponseInterceptor>(x => x.ResponseInterceptors).Reverse())
{
await interceptor.InterceptAsync(scope.CreateExceptionInterceptionContext<TResponse>(exception));
}
Expand Down

0 comments on commit 65e58d0

Please sign in to comment.