public async Task TestBuilderWithSettings() { // Arrange PipelineComponentResolver.AddAsync(new ConfigurableComponent()); var pipeline = AsyncPipelineBuilder <TestPayload> .Initialize(null) .WithComponent <ConfigurableComponent>() .WithComponentResolver(PipelineComponentResolver) .WithSettings(new Dictionary <string, IDictionary <string, string> > { { "ConfigurableComponent", new Dictionary <string, string> { { "UseFoo", "true" }, { "TestValue", "MyFooTestValue" } } } }) .Build(); var payload = new TestPayload(); // Act payload.FooStatus.Should().BeNull(); payload.BarStatus.Should().BeNull(); var result = await pipeline.ExecuteAsync(payload); // Assert pipeline.Name.StartsWith("AsyncPipeline").Should().BeTrue(); result.FooStatus.Should().Be("MyFooTestValue"); payload.BarStatus.Should().BeNull(); }
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 TestBuilderByComponentType() { // Arrange const string name = "test-name"; PipelineComponentResolver.AddAsync(new FooComponent()); PipelineComponentResolver.AddAsync(new BarComponent()); var pipeline = AsyncPipelineBuilder <TestPayload> .Initialize(null) .WithComponent <FooComponent>() .WithComponent <BarComponent>() .WithComponentResolver(PipelineComponentResolver) .WithoutSettings() .Build(name); var payload = new TestPayload(); // Act payload.FooWasCalled.Should().BeFalse(); payload.BarWasCalled.Should().BeFalse(); var result = await pipeline.ExecuteAsync(payload); // Assert pipeline.Name.Should().Be(name); result.Count.Should().Be(2); result.Count.Should().Be(2); result.FooWasCalled.Should().BeTrue(); result.BarWasCalled.Should().BeTrue(); }
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 AsyncPipeline_ExecutionStatusNotification_Test() { //Arrange PipelineComponentResolver.AddAsync(new FooComponent(), new BarExceptionComponent()); var receiver = Substitute.For <IAsyncPipelineComponentExecutionStatusReceiver>(); var sut = PipelineBuilder <TestPayload> .InitializeAsyncPipeline(receiver) .WithComponent <FooComponent>() .WithComponent <BarExceptionComponent>() .WithComponentResolver(PipelineComponentResolver) .WithoutSettings() .Build(); //Act Func <Task> act = () => sut.ExecuteAsync(new TestPayload()); //Assert act.Should() .ThrowExactly <PipelineExecutionException>() .WithInnerExceptionExactly <NotImplementedException>(); receiver.Received(2) .ReceiveExecutionStartingAsync(Arg.Is <PipelineComponentExecutionStartingInfo>(info => info.PipelineComponentName == nameof(FooComponent) || info.PipelineComponentName == nameof(BarExceptionComponent))); receiver.Received() .ReceiveExecutionCompletedAsync( Arg.Is <PipelineComponentExecutionCompletedInfo>(info => info.PipelineComponentName == nameof(FooComponent) && info.ExecutionTime != TimeSpan.Zero && info.Exception == null)); receiver.Received() .ReceiveExecutionCompletedAsync( Arg.Is <PipelineComponentExecutionCompletedInfo>(info => info.PipelineComponentName == nameof(BarExceptionComponent) && info.ExecutionTime != TimeSpan.Zero && info.Exception is NotImplementedException)); }
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>(); }