Esempio n. 1
0
        public void ExecuteAsync_HandlesExceptionThrownInCompletedTaskCallback()
        {
            // ARRANGE
            var mockOperation = new Mock <IPipelineOperationAsync <TestPipelineContext> >();

            mockOperation
            .Setup(o => o.Dependencies)
            .Returns(new List <Type>());

            mockOperation
            .Setup(o => o.ExecuteAsync())
            .Returns(Task.CompletedTask);

            mockOperation
            .Setup(o => o.CompletedTaskCallback(It.IsAny <Task>()))
            .Throws(new OperationExecutionException("Unit test exception"));

            var asyncOperations = new ReadOnlyDictionary <Type, IPipelineOperationAsync <TestPipelineContext> >(
                new Dictionary <Type, IPipelineOperationAsync <TestPipelineContext> >
            {
                { typeof(TestOperationAsync), mockOperation.Object }
            }
                );

            var opManager = new TestBasePipelineCoordinator(_operations, asyncOperations);

            // ACTION
            opManager.ExecuteAsync <TestOperationAsync>();

            // ASSERT
            Assert.False(opManager.Context.Successful);
            Assert.NotEmpty(opManager.Context.Exceptions);
            Assert.IsType <OperationExecutionException>(opManager.Context.Exceptions[0]);
            Assert.Contains(typeof(TestOperationAsync), opManager.OperationsExecuted);
        }
Esempio n. 2
0
        public void Execute_HandlesExceptionThrownByOperation()
        {
            // ARRANGE
            var mockOperation = new Mock <IPipelineOperation <TestPipelineContext> >();

            mockOperation
            .Setup(o => o.Dependencies)
            .Returns(new List <Type>());

            mockOperation
            .Setup(o => o.Execute(It.IsAny <TestPipelineContext>()))
            .Throws <OperationExecutionException>();

            var operations = new ReadOnlyDictionary <Type, IPipelineOperation <TestPipelineContext> >(
                new Dictionary <Type, IPipelineOperation <TestPipelineContext> >
            {
                { typeof(TestOperation), mockOperation.Object }
            }
                );

            var opManager = new TestBasePipelineCoordinator(operations, _asyncOperations);

            // ACTION
            opManager.Execute <TestOperation>();

            // ASSERT
            Assert.False(opManager.Context.Successful);
            Assert.NotEmpty(opManager.Context.Exceptions);
            Assert.IsType <OperationExecutionException>(opManager.Context.Exceptions[0]);
            Assert.Contains(typeof(TestOperation), opManager.OperationsExecuted);
        }
Esempio n. 3
0
        public void OperationTasks_Property_IsNotNull()
        {
            // ARRANGE / ACTION
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            // ASSERT
            Assert.NotNull(opManager.OperationTasks);
        }
Esempio n. 4
0
        public void AddAsyncOperation_ThrowsArgExceptionOnNullContextParameter()
        {
            // ARRANGE
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            // ACTION / ASSERT
            Assert.Throws <ArgumentException>(() => opManager.AddAsyncOperation <TestOperationAsync>(null));
        }
Esempio n. 5
0
        public void Execute_ThrowsArgExceptionOnNullContextProperty()
        {
            // ARRANGE
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            opManager.Context = null;

            // ACTION / ASSERT
            Assert.Throws <ArgumentException>(() => opManager.Execute <TestOperation>());
        }
Esempio n. 6
0
        public void ExecuteAsync_ThrowsOpExceptionWhenOtherTasksArePending()
        {
            // ARRANGE
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            var task = Task.CompletedTask;

            opManager.OperationTasks.Add(task);

            // ACTION / ASSERT
            Assert.Throws <OperationExecutionException>(() => opManager.ExecuteAsync <TestOperationAsync>());
        }
Esempio n. 7
0
        public void WhenAll_DoesNothingWhenEndProcessingInContextIsTrue()
        {
            // ARRANGE
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            opManager.Context.EndProcessing = true;

            // ACTION
            opManager.WhenAll();

            // ASSERT
            Assert.True(opManager.Context.Successful);
            Assert.Empty(opManager.Context.Exceptions);
            Assert.Empty(opManager.OperationsExecuted);
        }
Esempio n. 8
0
        public void WhenAll_AwaitsPendingTasksInContextParameter()
        {
            // ARRANGE
            var mockOperation1 = new Mock <IPipelineOperationAsync <TestPipelineContext> >();

            mockOperation1
            .Setup(o => o.Dependencies)
            .Returns(new List <Type>());

            mockOperation1
            .Setup(o => o.ExecuteAsync())
            .Returns(() => Task.CompletedTask);

            var mockOperation2 = new Mock <IPipelineOperationAsync <TestPipelineContext> >();

            mockOperation2
            .Setup(o => o.Dependencies)
            .Returns(new List <Type>());

            mockOperation2
            .Setup(o => o.ExecuteAsync())
            .Returns(() => Task.CompletedTask);

            var asyncOperations = new ReadOnlyDictionary <Type, IPipelineOperationAsync <TestPipelineContext> >(
                new Dictionary <Type, IPipelineOperationAsync <TestPipelineContext> >
            {
                { typeof(TestDependencyOperationAsync), mockOperation1.Object },
                { typeof(TestOperationAsync), mockOperation2.Object }
            }
                );

            var context = new TestPipelineContext();

            var opManager = new TestBasePipelineCoordinator(_operations, asyncOperations);

            // ACTION
            opManager
            .AddAsyncOperation <TestDependencyOperationAsync>(context)
            .AddAsyncOperation <TestOperationAsync>(context)
            .WhenAll(context);

            // ASSERT
            Assert.True(context.Successful);
            Assert.Empty(context.Exceptions);
            Assert.Contains(typeof(TestDependencyOperationAsync), opManager.OperationsExecuted);
            Assert.Contains(typeof(TestOperationAsync), opManager.OperationsExecuted);
        }
Esempio n. 9
0
        public void AddAsyncOperation_DoesNothingWhenEndProcessingInContextIsTrue()
        {
            // ARRANGE
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            opManager.Context.EndProcessing = true;

            // ACTION
            opManager.AddAsyncOperation <TestDependencyOperationAsync>();

            // ASSERT
            Assert.True(opManager.Context.Successful);
            Assert.Empty(opManager.Context.Exceptions);
            Assert.Empty(opManager.OperationsExecuted);
            Assert.Single(opManager.Context.ResultMessages);
            Assert.Contains("Not Executed", opManager.Context.ResultMessages[0]);
        }
Esempio n. 10
0
        public void AddAsyncOperation_ThrowsExceptionOnMissingDependency()
        {
            // ARRANGE
            var asyncOperations = new ReadOnlyDictionary <Type, IPipelineOperationAsync <TestPipelineContext> >(
                new Dictionary <Type, IPipelineOperationAsync <TestPipelineContext> >
            {
                { typeof(TestOperationAsync), new TestOperationAsync() }
            }
                );

            var opManager = new TestBasePipelineCoordinator(_operations, asyncOperations);

            // ACTION
            opManager.AddAsyncOperation <TestOperationAsync>();

            // ASSERT
            Assert.True(opManager.Context.EndProcessing);
            Assert.Single(opManager.Context.Exceptions);
        }
Esempio n. 11
0
        public void ExecuteAsync_RunsOperationSuccessfully()
        {
            // ARRANGE
            var asyncOperations = new ReadOnlyDictionary <Type, IPipelineOperationAsync <TestPipelineContext> >(
                new Dictionary <Type, IPipelineOperationAsync <TestPipelineContext> >
            {
                { typeof(TestDependencyOperationAsync), new TestDependencyOperationAsync() }
            }
                );

            var opManager = new TestBasePipelineCoordinator(_operations, asyncOperations);

            // ACTION
            opManager.ExecuteAsync <TestDependencyOperationAsync>();

            // ASSERT
            Assert.True(opManager.Context.Successful);
            Assert.Empty(opManager.Context.Exceptions);
            Assert.Contains(typeof(TestDependencyOperationAsync), opManager.OperationsExecuted);
        }
Esempio n. 12
0
        public void Execute_ThrowsExceptionOnMissingDependency()
        {
            // ARRANGE
            var testOperation = new TestOperation();

            var operations = new ReadOnlyDictionary <Type, IPipelineOperation <TestPipelineContext> >(
                new Dictionary <Type, IPipelineOperation <TestPipelineContext> >
            {
                { typeof(TestOperation), testOperation }
            }
                );

            var opManager = new TestBasePipelineCoordinator(operations, _asyncOperations);

            // ACTION
            opManager.Execute <TestOperation>();

            // ASSERT
            Assert.True(opManager.Context.EndProcessing);
            Assert.Single(opManager.Context.Exceptions);
        }