Example #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();
        }
Example #2
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();
        }
Example #3
0
        public void GetInstance()
        {
            //Arrange
            const string name = nameof(FooComponent);

            _sut.AddAsync(new FooComponent());

            //Act
            var result = _sut.GetInstance <IAsyncPipelineComponent <TestPayload> >(name);

            //Assert
            result.Should().NotBeNull();
            result.Should().BeAssignableTo <FooComponent>();
        }