-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from doomchild/partition
Added TaskExtras.Partition
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
using RLC.TaskChaining; | ||
using Xunit; | ||
|
||
namespace RLC.TaskChainingTests; | ||
|
||
public class PartitionTests | ||
{ | ||
[Fact] | ||
public async Task ItShouldPartition() | ||
{ | ||
int expectedFulfills = 4; | ||
int expectedFaults = 1; | ||
List<Task<string>> tasks = new() | ||
{ | ||
Task.FromResult("abc"), | ||
Task.FromResult("def"), | ||
Task.FromException<string>(new InvalidOperationException()), | ||
Task.FromResult("ghi"), | ||
TaskExtras.Defer(() => Task.FromResult("jkl"), TimeSpan.FromSeconds(1)) | ||
}; | ||
|
||
(IEnumerable<Task<string>> Faulted, IEnumerable<Task<string>> Fulfilled) partition = await TaskExtras.Partition(tasks); | ||
|
||
Assert.Equal(expectedFaults, partition.Faulted.Count()); | ||
Assert.Equal(expectedFulfills, partition.Fulfilled.Count()); | ||
} | ||
} |