Exemple #1
0
        public async Task Run_executes_tasks_in_the_expected_order_if_there_are_multiple_tasks_of_the_same_type()
        {
            // ARRANGE
            var task1 = new TestTask15("task1");
            var task2 = new TestTask14("task2");
            var task3 = new TestTask15("task3");
            var task4 = new TestTask14("task4");

            var sut = new ChangeLogPipeline(m_Logger, new IChangeLogTask[] { task1, task2, task3, task4 });

            // ACT
            var result = await sut.RunAsync();

            // ASSERT
            Assert.True(result.Success);

            Assert.Collection(
                result.ExecutedTasks,
                executedTask => Assert.Same(task2, executedTask.Task),
                executedTask => Assert.Same(task4, executedTask.Task),
                executedTask => Assert.Same(task1, executedTask.Task),
                executedTask => Assert.Same(task3, executedTask.Task)
                );

            Assert.Empty(result.PendingTasks);
        }
Exemple #2
0
        public async Task Run_executes_all_tasks_in_the_insertion_order(int numberOfTasks)
        {
            // ARRANGE
            var tasks = Enumerable.Range(0, numberOfTasks)
                        .Select(_ =>
            {
                var mock = new Mock <IChangeLogTask>(MockBehavior.Strict);
                mock.Setup(x => x.RunAsync(It.IsAny <ApplicationChangeLog>())).Returns(Task.FromResult(ChangeLogTaskResult.Success));
                return(mock);
            })
                        .ToArray();

            var sut = new ChangeLogPipeline(m_Logger, tasks.Select(x => x.Object));

            // ACT
            var result = await sut.RunAsync();

            // ASSERT
            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.NotNull(result.Value);
            Assert.All(tasks, task => task.Verify(x => x.RunAsync(It.IsAny <ApplicationChangeLog>()), Times.Once));
            Assert.Collection(
                result.ExecutedTasks,
                tasks.Select <Mock <IChangeLogTask>, Action <ChangeLogTaskExecutionResult> >(taskMock => r =>
            {
                Assert.Same(taskMock.Object, r.Task);
                Assert.Equal(ChangeLogTaskResult.Success, r.Result);
            }).ToArray()
                );
            Assert.Empty(result.PendingTasks);
        }
Exemple #3
0
        public async Task Run_executes_a_tasks_dependencies_before_running_the_task()
        {
            // ARRANGE
            var task1 = new TestTask1();
            var task2 = new TestTask2();
            var task3 = new TestTask3();
            var task4 = new TestTask4();
            var sut   = new ChangeLogPipeline(m_Logger, new IChangeLogTask[] { task1, task2, task3, task4 });

            // ACT
            var result = await sut.RunAsync();

            // ASSERT
            Assert.True(result.Success);

            Assert.Collection(
                result.ExecutedTasks,
                executedTask => Assert.Same(task2, executedTask.Task),
                executedTask => Assert.Same(task1, executedTask.Task),
                executedTask => Assert.Same(task3, executedTask.Task),
                executedTask => Assert.Same(task4, executedTask.Task)
                );

            Assert.Empty(result.PendingTasks);
        }
        public async Task Run_continues_execution_if_a_task_is_skipped()
        {
            // ARRANGE
            var tasks = Enumerable.Range(0, 3)
                        .Select(_ =>
            {
                var mock = new Mock <IChangeLogTask>(MockBehavior.Strict);
                mock.Setup(x => x.RunAsync(It.IsAny <ApplicationChangeLog>())).Returns(Task.FromResult(ChangeLogTaskResult.Success));
                return(mock);
            })
                        .ToArray();

            tasks[1].Setup(x => x.RunAsync(It.IsAny <ApplicationChangeLog>())).Returns(Task.FromResult(ChangeLogTaskResult.Skipped));

            var sut = new ChangeLogPipeline(m_Logger, tasks.Select(x => x.Object));

            // ACT
            var result = await sut.RunAsync();

            // ASSERT
            Assert.NotNull(result);
            Assert.True(result.Success);
            Assert.NotNull(result.Value);
            Assert.All(tasks, task => task.Verify(x => x.RunAsync(It.IsAny <ApplicationChangeLog>()), Times.Once));
        }
        public async Task Run_aborts_execution_if_a_task_fails()
        {
            // ARRANGE
            var tasks = Enumerable.Range(0, 3)
                        .Select(_ =>
            {
                var mock = new Mock <IChangeLogTask>(MockBehavior.Strict);
                mock.Setup(x => x.RunAsync(It.IsAny <ApplicationChangeLog>())).Returns(Task.FromResult(ChangeLogTaskResult.Success));
                return(mock);
            })
                        .ToArray();

            tasks[1].Setup(x => x.RunAsync(It.IsAny <ApplicationChangeLog>())).Returns(Task.FromResult(ChangeLogTaskResult.Error));

            var sut = new ChangeLogPipeline(m_Logger, tasks.Select(x => x.Object));

            // ACT
            var result = await sut.RunAsync();

            // ASSERT
            Assert.NotNull(result);
            Assert.False(result.Success);
            tasks[0].Verify(x => x.RunAsync(It.IsAny <ApplicationChangeLog>()), Times.Once);
            tasks[1].Verify(x => x.RunAsync(It.IsAny <ApplicationChangeLog>()), Times.Once);
            tasks[2].Verify(x => x.RunAsync(It.IsAny <ApplicationChangeLog>()), Times.Never);
        }
Exemple #6
0
        public async Task Run_throws_InvalidPipelineConfigurationException_if_there_is_a_dependency_to_task_not_added_to_the_pipeline_02()
        {
            // ARRANGE
            var tasks = new IChangeLogTask[]
            {
                new TestTask12(),
            };
            var sut = new ChangeLogPipeline(m_Logger, tasks);

            // ACT
            var ex = await Record.ExceptionAsync(async() => await sut.RunAsync());

            // ASSERT
            Assert.IsType <InvalidPipelineConfigurationException>(ex);
            Assert.Equal("Dependent task 'TestTask13' of task 'TestTask12' was not found", ex.Message);
        }
Exemple #7
0
        public async Task Run_throws_InvalidPipelineConfigurationException_if_there_are_cyclic_dependencies_between_tasks_01()
        {
            // ARRANGE
            var tasks = new IChangeLogTask[]
            {
                new TestTask5()
            };
            var sut = new ChangeLogPipeline(m_Logger, tasks);

            // ACT
            var ex = await Record.ExceptionAsync(async() => await sut.RunAsync());

            // ASSERT
            Assert.IsType <InvalidPipelineConfigurationException>(ex);
            Assert.Equal("Detected circular dependency between tasks: 'TestTask5' -> 'TestTask5'", ex.Message);
        }