Skip to content

Commit

Permalink
Adds specific tests for RecipientRunner's exception extraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommasobertoni committed Jan 5, 2021
1 parent 0b242f4 commit dd163da
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/NScatterGather.Tests/Recipients/Run/RecipientRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using NScatterGather.Inspection;
using NScatterGather.Recipients;
using NScatterGather.Recipients.Invokers;
using NScatterGather.Recipients.Run;
using Xunit;
using static NScatterGather.CollisionStrategy;

Expand Down Expand Up @@ -155,5 +158,59 @@ public async Task Reflection_exception_are_decomposed()
Assert.NotNull(runner.Exception);
Assert.Equal("An invocation failure.", runner.Exception!.Message);
}

[Fact]
public async Task Aggregate_exception_without_inner_is_handled()
{
var aggEx = new AggregateException("Empty inner exceptions");
var runner = new RecipientRunner<int>(_recipient, new PreparedInvocation<int>(() => throw aggEx));

await runner.Start();
Assert.Same(aggEx, runner.Exception);
}

[Fact]
public async Task Aggregate_exception_with_inner_is_handled()
{
var ex1 = new Exception();
var ex2 = new Exception();
var aggEx = new AggregateException(ex1, ex2);
var runner = new RecipientRunner<int>(_recipient, new PreparedInvocation<int>(() => throw aggEx));

await runner.Start();
Assert.Same(aggEx, runner.Exception);
}

[Fact]
public async Task Aggregate_exception_with_one_inner_is_handled()
{
var ex = new Exception();
var aggEx = new AggregateException(ex);
var runner = new RecipientRunner<int>(_recipient, new PreparedInvocation<int>(() => throw aggEx));

await runner.Start();
Assert.Same(ex, runner.Exception);
}

[Fact]
public async Task Target_invocation_exception_without_inner_is_handled()
{
var tiEx = new TargetInvocationException("Empty inner exception", null);
var runner = new RecipientRunner<int>(_recipient, new PreparedInvocation<int>(() => throw tiEx));

await runner.Start();
Assert.Same(tiEx, runner.Exception);
}

[Fact]
public async Task Target_invocation_exception_with_inner_is_handled()
{
var ex = new Exception();
var tiEx = new TargetInvocationException(ex);
var runner = new RecipientRunner<int>(_recipient, new PreparedInvocation<int>(() => throw tiEx));

await runner.Start();
Assert.Same(ex, runner.Exception);
}
}
}

0 comments on commit dd163da

Please sign in to comment.