Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var components = new Dictionary <string, IPipelineComponent>
            {
                { typeof(FooComponent).Name, new FooComponent() },
                { typeof(DelayComponent).Name, new DelayComponent() },
                { typeof(BarComponent).Name, new BarComponent() },
                { typeof(FooComponentNonAsync).Name, new FooComponentNonAsync() },
                { typeof(DelayComponentNonAsync).Name, new DelayComponentNonAsync() },
                { typeof(BarComponentNonAsync).Name, new BarComponentNonAsync() }
            };

            var resolver = new DictionaryPipelineComponentResolver(components);

            var settings = new Dictionary <string, IDictionary <string, string> >
            {
                { typeof(DelayComponent).Name, new Dictionary <string, string>
                  {
                      { "DelayTimeSpan", "00:00:10" }
                  } }
            };

            var t = InvokePipelineAsync(resolver, settings);

            t.Wait();

            Console.WriteLine("Async task completed");

            InvokePipeline(resolver, settings);

            Console.WriteLine("Sync task completed");

            Console.Read();
        }
Exemplo n.º 3
0
        static async Task Main()
        {
            var resolver = new DictionaryPipelineComponentResolver();

            resolver.AddAsync(new FooComponent(), new DelayComponent(), new BarComponent());
            resolver.Add(new FooComponentNonAsync(), new DelayComponentNonAsync(), new BarComponentNonAsync());

            var settings = new Dictionary <string, IDictionary <string, string> >
            {
                { nameof(DelayComponent), new Dictionary <string, string>
                  {
                      { "DelayTimeSpan", "00:00:05" }
                  } }
            };

            Console.WriteLine();

            // ReSharper disable once MethodHasAsyncOverload
            InvokePipeline(resolver, settings);

            await InvokePipelineAsync(resolver, settings);

            await InvokePipelineWithDependencyInjectionAndStatusReceiverAsync(settings);

            await InvokeNamedPipelinesWithDependencyInjectionAndStatusReceiverAsync();

            Console.Write("\nPress any key to exit...");
            Console.Read();
        }
Exemplo n.º 4
0
        static async Task Main()
        {
            var components = new Dictionary <string, IPipelineComponent>
            {
                { nameof(FooComponent), new FooComponent() },
                { nameof(DelayComponent), new DelayComponent() },
                { nameof(BarComponent), new BarComponent() },
                { nameof(FooComponentNonAsync), new FooComponentNonAsync() },
                { nameof(DelayComponentNonAsync), new DelayComponentNonAsync() },
                { nameof(BarComponentNonAsync), new BarComponentNonAsync() }
            };

            var resolver = new DictionaryPipelineComponentResolver(components);

            var settings = new Dictionary <string, IDictionary <string, string> >
            {
                { typeof(DelayComponent).Name, new Dictionary <string, string>
                  {
                      { "DelayTimeSpan", "00:00:05" }
                  } }
            };

            Console.WriteLine();

            await InvokePipelineAsync(resolver, settings);

            InvokePipeline(resolver, settings);

            Console.WriteLine();
            Console.Write("Press any key to exit...");
            Console.Read();
        }
        protected PipelineTestsBase()
        {
            //var components = new Dictionary<string, IPipelineComponent>
            //{
            //    {nameof(FooComponent), new FooComponent()},
            //    {nameof(BarComponent), new BarComponent()},
            //    {nameof(FooSettingNotFoundComponent), new FooSettingNotFoundComponent() },
            //    {nameof(BarExceptionComponent), new BarExceptionComponent() },
            //    {nameof(DelayComponent), new DelayComponent() },
            //    {nameof(ConfigurableComponent), new ConfigurableComponent()},
            //    {nameof(PipelineExecutionTerminatingComponent), new PipelineExecutionTerminatingComponent()}
            //};

            PipelineComponentResolver = new DictionaryPipelineComponentResolver();
        }
Exemplo n.º 6
0
        private static void InvokePipeline(DictionaryPipelineComponentResolver resolver, Dictionary <string, IDictionary <string, string> > settings)
        {
            var pipeline = PipelineBuilder <ExamplePipelinePayload>
                           .NonAsync()
                           .WithComponent <FooComponentNonAsync>()
                           .WithComponent <DelayComponentNonAsync>()
                           .WithComponent <BarComponentNonAsync>()
                           .WithComponentResolver(resolver)
                           .WithSettings(settings)
                           .Build();

            Console.WriteLine("Executing pipeline synchronously.");
            var result = pipeline.Execute(new ExamplePipelinePayload());

            result.Messages.ForEach(Console.WriteLine);
        }
Exemplo n.º 7
0
        private static async Task InvokePipelineAsync(DictionaryPipelineComponentResolver resolver, Dictionary <string, IDictionary <string, string> > settings)
        {
            var pipeline = PipelineBuilder <ExamplePipelinePayload>
                           .Async()
                           .WithComponent <FooComponent>()
                           .WithComponent <DelayComponent>()
                           .WithComponent <BarComponent>()
                           .WithComponentResolver(resolver)
                           .WithSettings(settings)
                           .Build();

            Console.WriteLine("Executing pipeline asynchronously.");
            var result = await pipeline.ExecuteAsync(new ExamplePipelinePayload(), CancellationToken.None);

            result.Messages.ForEach(Console.WriteLine);
        }
        protected PipelineTestsBase()
        {
            var components = new Dictionary <string, IPipelineComponent>
            {
                { typeof(FooComponent).Name, new FooComponent() },
                { typeof(BarComponent).Name, new BarComponent() },
                { typeof(FooSettingNotFoundComponent).Name, new FooSettingNotFoundComponent() },
                { typeof(BarExceptionComponent).Name, new BarExceptionComponent() },
                { typeof(DelayComponent).Name, new DelayComponent() },
                { "Component1", new ConfigurableComponent() },
                { "Component2", new ConfigurableComponent() },
                { typeof(PipelineExecutionTerminatingComponent).Name, new PipelineExecutionTerminatingComponent() }
            };

            PipelineComponentResolver = new DictionaryPipelineComponentResolver(components);
        }
Exemplo n.º 9
0
 public void Init()
 {
     _sut = new DictionaryPipelineComponentResolver();
 }