Esempio n. 1
0
        public void AddAsyncOperation_ThrowsArgExceptionOnNullContextParameter()
        {
            // ARRANGE
            var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations);

            // ACTION / ASSERT
            Assert.Throws <ArgumentException>(() => opManager.AddAsyncOperation <TestOperationAsync>(null));
        }
Esempio n. 2
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. 3
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. 4
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. 5
0
        public void AddAsyncOperation_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
            .AddAsyncOperation <TestOperationAsync>()
            .WhenAll();

            // ASSERT
            Assert.False(opManager.Context.Successful);
            Assert.NotEmpty(opManager.Context.Exceptions);
            Assert.IsType <OperationExecutionException>(opManager.Context.Exceptions[0]);
            Assert.Contains(typeof(TestOperationAsync), opManager.OperationsExecuted);
        }