diff --git a/project-metadata.json b/project-metadata.json index 3d49451..eaef9fb 100644 --- a/project-metadata.json +++ b/project-metadata.json @@ -2,7 +2,7 @@ "name": "task-chaining", "description": "Extension methods to System.Threading.Task to allow Promise-like chaining", "title": "TaskChaining", - "version": "2.18.0", + "version": "2.18.1", "ciEnvironment": { "variables": [ { diff --git a/src/TaskExtras.cs b/src/TaskExtras.cs index 4d415ce..c009b3f 100644 --- a/src/TaskExtras.cs +++ b/src/TaskExtras.cs @@ -195,16 +195,16 @@ private static Task DoRetry( /// The underlying type of the tasks in . /// The collection of tasks to partition. /// A tuple of the partitioned tasks. - public static Task<(IReadOnlyList> Faulted, IReadOnlyList> Fulfilled)> Partition( + public static Task<(IReadOnlyList Faulted, IReadOnlyList Fulfilled)> Partition( IEnumerable> tasks ) { - return tasks.Aggregate, Task<(IReadOnlyList> Faulted, IReadOnlyList> Fulfilled)>>( - Task.FromResult(((IReadOnlyList>)new List>(), (IReadOnlyList>)new List>())), - ZipTasksWith> Faulted, IReadOnlyList> Fulfilled), (IReadOnlyList> Faulted, IReadOnlyList> Fulfilled), Exception> + return tasks.Aggregate, Task<(IReadOnlyList Faulted, IReadOnlyList Fulfilled)>>( + Task.FromResult(((IReadOnlyList)new List(), (IReadOnlyList)new List())), + ZipTasksWith Faulted, IReadOnlyList Fulfilled), (IReadOnlyList Faulted, IReadOnlyList Fulfilled), Exception> ( - (values, v) => (values.Faulted, values.Fulfilled.Append(Task.FromResult(v)).ToList()), - (values, v) => (values.Faulted.Append>(Task.FromException(v)).ToList(), values.Fulfilled) + (values, v) => (values.Faulted, values.Fulfilled.Append(v).ToList()), + (values, v) => (values.Faulted.Append(v).ToList(), values.Fulfilled) ) ); } diff --git a/tests/unit/TaskChainingTests.csproj b/tests/unit/TaskChainingTests.csproj index c0c9238..24a64d6 100644 --- a/tests/unit/TaskChainingTests.csproj +++ b/tests/unit/TaskChainingTests.csproj @@ -28,6 +28,7 @@ all + diff --git a/tests/unit/TaskExtrasPartitionTests.cs b/tests/unit/TaskExtrasPartitionTests.cs index 5a60c30..5813707 100644 --- a/tests/unit/TaskExtrasPartitionTests.cs +++ b/tests/unit/TaskExtrasPartitionTests.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading.Tasks; +using FluentAssertions; using RLC.TaskChaining; using Xunit; @@ -13,20 +13,38 @@ public class PartitionTests [Fact] public async Task ItShouldPartition() { - int expectedFulfills = 4; - int expectedFaults = 1; + Func> throwFunc = () => throw new NullReferenceException(); List> tasks = new() { Task.FromResult("abc"), Task.FromResult("def"), Task.FromException(new InvalidOperationException()), Task.FromResult("ghi"), - TaskExtras.Defer(() => Task.FromResult("jkl"), TimeSpan.FromSeconds(1)) + TaskExtras.Defer(() => Task.FromResult("jkl"), TimeSpan.FromSeconds(1)), + TaskExtras.Defer(throwFunc, TimeSpan.FromSeconds(1)) + }; + List expectedFulfillments = new() + { + "abc", + "def", + "ghi", + "jkl" + }; + List expectedFaults = new() + { + new InvalidOperationException(), + new NullReferenceException() }; - (IEnumerable> Faulted, IEnumerable> Fulfilled) partition = await TaskExtras.Partition(tasks); + (IEnumerable Faulted, IEnumerable Fulfilled) partition = await TaskExtras.Partition(tasks); - Assert.Equal(expectedFaults, partition.Faulted.Count()); - Assert.Equal(expectedFulfills, partition.Fulfilled.Count()); + partition.Faulted.Should().BeEquivalentTo( + expectedFaults, + options => options.Excluding(ex => ex.TargetSite) + .Excluding(ex => ex.Source) + .Excluding(ex => ex.StackTrace) + .Excluding(ex => ex.HResult) + ); + partition.Fulfilled.Should().BeEquivalentTo(expectedFulfillments); } }