public async Task TestParallelGroupCommandExecution() { // Arrange TimeSpan delay = TimeSpan.FromSeconds(5); var cts = new CancellationTokenSource(); Mock <ICommand>[] commands = { this.MakeDelayingCommand("c1", delay), this.MakeDelayingCommand("c2", delay), this.MakeDelayingCommand("c3", delay), }; ICommand groupCommand = new ParallelGroupCommand( commands.Select(m => m.Object).ToArray()); // Act Task executeTask = groupCommand.ExecuteAsync(cts.Token); Task waitTask = Task.Delay(delay.Add(TimeSpan.FromSeconds(1))); Task completedTask = await Task.WhenAny(executeTask, waitTask); // Assert Assert.Equal(completedTask, executeTask); commands[0].Verify(m => m.ExecuteAsync(cts.Token), Times.Once()); commands[1].Verify(m => m.ExecuteAsync(cts.Token), Times.Once()); commands[2].Verify(m => m.ExecuteAsync(cts.Token), Times.Once()); }
public async Task TestCreate( Option <TestPlanRecorder> recorder, List <TestRecordType> moduleExecutionList, List <ICommand> commandList) { var g = new ParallelGroupCommand(commandList.ToArray()); var token = default(CancellationToken); await g.ExecuteAsync(token); this.AssertCommands(recorder, commandList, moduleExecutionList); }
public async Task TestParallelGroupCommandCancellation() { // Arrange var cts = new CancellationTokenSource(); Mock <ICommand>[] commands = { this.MakeMockCommand("c1"), this.MakeMockCommand("c2", () => cts.Cancel()), this.MakeMockCommand("c3"), }; ICommand groupCommand = new ParallelGroupCommand( commands.Select(m => m.Object).ToArray()); // Act await groupCommand.ExecuteAsync(cts.Token); // Assert commands[0].Verify(m => m.ExecuteAsync(cts.Token), Times.Once()); commands[1].Verify(m => m.ExecuteAsync(cts.Token), Times.Once()); commands[2].Verify(m => m.ExecuteAsync(cts.Token), Times.Once()); }