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); }
public void ExecuteAsync_ThrowsExceptionOnNullContextParameter() { // ARRANGE var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations); // ACTION / ASSERT Assert.Throws <ArgumentException>(() => opManager.ExecuteAsync <TestOperationAsync>(null)); }
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>()); }
public void ExecuteAsync_DoesNothingWhenEndProcessingInContextIsTrue() { // ARRANGE var opManager = new TestBasePipelineCoordinator(_operations, _asyncOperations); opManager.Context.EndProcessing = true; // ACTION opManager.ExecuteAsync <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]); }
public void ExecuteAsync_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.ExecuteAsync <TestOperationAsync>(); // ASSERT Assert.True(opManager.Context.EndProcessing); Assert.Single(opManager.Context.Exceptions); }
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); }