Example #1
0
        public async Task TestParallelGroupCommandUndo()
        {
            // 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.UndoAsync(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.UndoAsync(cts.Token), Times.Once());
            commands[1].Verify(m => m.UndoAsync(cts.Token), Times.Once());
            commands[2].Verify(m => m.UndoAsync(cts.Token), Times.Once());
        }
Example #2
0
        public async Task <Plan> CreateShutdownPlanAsync(ModuleSet current)
        {
            IEnumerable <Task <ICommand> > stopTasks = current.Modules.Values
                                                       .Where(c => !c.Name.Equals(Constants.EdgeAgentModuleName, StringComparison.OrdinalIgnoreCase))
                                                       .Select(m => this.commandFactory.StopAsync(m));

            ICommand[] stopCommands = await Task.WhenAll(stopTasks);

            ICommand parallelCommand = new ParallelGroupCommand(stopCommands);

            Events.ShutdownPlanCreated(stopCommands);
            return(new Plan(new[] { parallelCommand }));
        }
Example #3
0
        public async Task TestUndoAsync(
            Option <TestPlanRecorder> recorder,
            List <TestRecordType> moduleExecutionList,
            List <ICommand> commandList)
        {
            ICommand g = new ParallelGroupCommand(commandList.ToArray());

            var token = default(CancellationToken);

            await g.UndoAsync(token);

            this.AssertUndo(recorder, commandList, moduleExecutionList);
        }
        public async Task TestCreate(
            Option <TestPlanRecorder> recorder,
            List <TestRecordType> moduleExecutionList,
            List <ICommand> commandList)
        {
            var g = new ParallelGroupCommand(commandList.ToArray());

            var token = new CancellationToken();

            await g.ExecuteAsync(token);

            this.AssertCommands(recorder, commandList, moduleExecutionList);
        }
Example #5
0
        public void TestShow(
            Option <TestPlanRecorder> recorder,
            List <TestRecordType> moduleExecutionList,
            List <ICommand> commandList)
        {
            ICommand g = new ParallelGroupCommand(commandList.ToArray());

            string showString = g.Show();

            foreach (ICommand command in commandList)
            {
                Assert.Contains(command.Show(), showString);
            }
        }
Example #6
0
        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());
        }