public void RunAsync_NoProcessesToRun_NoExceptions() { // arrange var sut = new ParallelProcess(); // act + assert sut.Invoking(async process => await process.RunAsync(CancellationToken.None)) .Should().NotThrow(); }
public void RunAsync_ManyProcessesThrows_ThrowsAggregateExceptionForProcesses(int processCount) { // arrange var counter = 0; _fixture.Register(() => { var processId = Interlocked.Increment(ref counter); var expectedException = new Exception($"I'm failing You, I'm so sorry. Process id: {processId}."); var process = A.Fake <IProcess>(); A.CallTo(() => process.RunAsync(CancellationToken.None)).Returns(Task.FromException(expectedException)); return(process); }); var processes = _fixture.CreateMany <IProcess>(processCount); var sut = new ParallelProcess(processes); // act + assert sut.Invoking(async x => await x.RunAsync(CancellationToken.None)) .Should().Throw <AggregateException>().Where(ex => ex.InnerExceptions.Count == processCount); }