public async Task AsyncPipeline_Execution_Test() { //Arrange PipelineComponentResolver.AddAsync(new FooComponent(), new BarComponent()); var types = new List <Type> { typeof(FooComponent), typeof(BarComponent) }; var config = types.ToDictionary <Type, string, IDictionary <string, string> >( t => t.Name, t => new Dictionary <string, string> { { "test", "value" } }); var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config, null); //Act var result = await target.ExecuteAsync(new TestPayload()); //Assert result.Should().NotBeNull(); result.Count.Should().Be(2); result.FooStatus.Should().Be($"{nameof(FooComponent)} executed!"); result.BarStatus.Should().Be($"{nameof(BarComponent)} executed!"); }
public async Task AsyncPipeline_Dispose_Test() { //Arrange var component1 = Substitute.For <IDisposableAsyncPipelineComponent>(); var component2 = Substitute.For <IAsyncPipelineComponent <TestPayload> >(); var components = new[] { component1, component2 }; var resolver = new DictionaryPipelineComponentResolver(); resolver.AddAsync(components); var payload = new TestPayload(); component1.ExecuteAsync(Arg.Any <TestPayload>(), Arg.Any <CancellationToken>()).Returns(payload); component2.ExecuteAsync(Arg.Any <TestPayload>(), Arg.Any <CancellationToken>()).Returns(payload); TestPayload result; //Act using (var sut = new AsyncPipeline <TestPayload>(resolver, components.Select(c => c.GetType()), null, null)) { result = await sut.ExecuteAsync(payload, CancellationToken.None).ConfigureAwait(false); } //Assert result.Should().NotBeNull(); component1.Received().Dispose(); }
public async Task Pipeline_AsyncFilterExecution_Test() { var types = new List <Type> { typeof(FooComponent), typeof(PipelineExecutionTerminatingComponent), typeof(BarComponent) }; var config = new Dictionary <string, IDictionary <string, string> >(); foreach (var t in types) { config.Add(t.Name, new Dictionary <string, string> { { "test", "value" } }); } var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config); var result = await target.ExecuteAsync(new TestPayload()); result.Should().NotBeNull(); result.Count.Should().Be(2); result.FooStatus.Should().Be($"{nameof(FooComponent)} executed!"); result.BarStatus.Should().BeNull(); }
public async Task AsyncPipeline_DuplicateComponentsConfiguredDifferently_Test() { var settings = new Dictionary <string, IDictionary <string, string> > { { "Component1", new Dictionary <string, string> { { "TestValue", "Component1Value" }, { "UseFoo", "true" } } }, { "Component2", new Dictionary <string, string> { { "TestValue", "Component2Value" }, { "UseFoo", "false" } } } }; var payload = new TestPayload(); var target = new AsyncPipeline <TestPayload>( PipelineComponentResolver, new List <string> { "Component1", "Component2" }, settings); var result = await target.ExecuteAsync(payload); result.Should().NotBeNull(); result.Should().Be(payload); result.FooStatus.Should().Be("Component1Value"); payload.BarStatus.Should().Be("Component2Value"); }
public async Task AsyncPipeline_Execution_NullSettings_Test() { var types = new List <Type> { typeof(FooComponent), typeof(BarComponent) }; var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, null); var result = await target.ExecuteAsync(new TestPayload()); Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); Assert.IsTrue(result.FooStatus == $"{nameof(FooComponent)} executed!"); Assert.IsTrue(result.BarStatus == $"{nameof(BarComponent)} executed!"); }
public void AsyncPipelineComponent_Exception_Test() { var types = new List <Type> { typeof(FooComponent), typeof(BarExceptionComponent) }; var config = types.ToDictionary <Type, string, IDictionary <string, string> >( t => t.Name, t => new Dictionary <string, string> { { "test", "value" } }); var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config); Func <Task <TestPayload> > act = () => target.ExecuteAsync(new TestPayload()); act.Should().ThrowExactly <PipelineExecutionException>() .And.InnerException.Should().BeOfType <NotImplementedException>(); }
public async Task AsyncPipeline_Execution_Test() { var types = new List <Type> { typeof(FooComponent), typeof(BarComponent) }; var config = types.ToDictionary <Type, string, IDictionary <string, string> >( t => t.Name, t => new Dictionary <string, string> { { "test", "value" } }); var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config); var result = await target.ExecuteAsync(new TestPayload()); Assert.IsNotNull(result); Assert.IsTrue(result.Count == 2); Assert.IsTrue(result.FooStatus == $"{nameof(FooComponent)} executed!"); Assert.IsTrue(result.BarStatus == $"{nameof(BarComponent)} executed!"); }
public void AsyncPipelineComponent_SettingNotFoundException_Test() { var types = new List <Type> { typeof(FooSettingNotFoundComponent) }; var config = new Dictionary <string, IDictionary <string, string> >(); foreach (var t in types) { config.Add(t.Name, new Dictionary <string, string> { { "test", "value" } }); } var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config); Func <Task <TestPayload> > act = () => target.ExecuteAsync(new TestPayload()); act.Should().ThrowExactly <PipelineExecutionException>() .And.InnerException.Should().BeOfType <PipelineComponentSettingNotFoundException>(); }
public void AsyncPipeline_Execution_Cancellation_Test() { var types = new List <Type> { typeof(DelayComponent), typeof(BarComponent) }; var config = new Dictionary <string, IDictionary <string, string> >(); foreach (var t in types) { config.Add(t.Name, new Dictionary <string, string> { { "test", "value" } }); } var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)); var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config); Func <Task <TestPayload> > act = () => target.ExecuteAsync(new TestPayload(), cts.Token); act.Should().Throw <OperationCanceledException>(); }
public void AsyncPipeline_ComponentReturnsNull_Test() { //Arrange PipelineComponentResolver.AddAsync(new NullTaskComponent()); var types = new List <Type> { typeof(NullTaskComponent) }; var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, null, null); //Act Func <Task> act = () => target.ExecuteAsync(new TestPayload()); //Assert act.Should() .ThrowExactly <PipelineExecutionException>() .WithInnerExceptionExactly <InvalidOperationException>() .WithMessage($"AsyncPipelineComponent named '{nameof(NullTaskComponent)}' returned a null task."); }
public void AsyncPipelineComponent_SettingNotFoundException_Test() { //Arrange PipelineComponentResolver.AddAsync(new FooSettingNotFoundComponent()); var types = new List <Type> { typeof(FooSettingNotFoundComponent) }; var config = types.ToDictionary <Type, string, IDictionary <string, string> >( t => t.Name, t => new Dictionary <string, string> { { "test", "value" } }); var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config, null); //Act Func <Task <TestPayload> > act = () => target.ExecuteAsync(new TestPayload()); //Assert act.Should().ThrowExactly <PipelineExecutionException>() .And.InnerException.Should().BeOfType <PipelineComponentSettingNotFoundException>(); }
public void AsyncPipeline_Execution_Cancellation_Test() { //Arrange PipelineComponentResolver.AddAsync(new DelayComponent(), new BarComponent()); var types = new List <Type> { typeof(DelayComponent), typeof(BarComponent) }; var config = types.ToDictionary <Type, string, IDictionary <string, string> >( t => t.Name, t => new Dictionary <string, string> { { "test", "value" } }); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)); var target = new AsyncPipeline <TestPayload>(PipelineComponentResolver, types, config, null); //Act Func <Task <TestPayload> > act = () => target.ExecuteAsync(new TestPayload(), cts.Token); //Assert act.Should().Throw <OperationCanceledException>(); }