public void PipelineBuilder_Defaults()
        {
            var builder = new ActivityProcessorPipelineBuilder();

            Assert.Null(builder.Exporter);
            Assert.Null(builder.Processors);

            var processor = builder.Build();

            Assert.Null(builder.Exporter);
            Assert.Single(builder.Processors);
            Assert.IsType <NoopActivityProcessor>(builder.Processors[0]);
            Assert.Same(processor, builder.Processors[0]);
        }
        public void PipelineBuilder_AddExporter()
        {
            var builder = new ActivityProcessorPipelineBuilder();

            var exporter = new TestActivityExporter(null);

            builder.SetExporter(exporter);

            Assert.Same(exporter, builder.Exporter);

            var processor = builder.Build();

            Assert.Single(builder.Processors);
            Assert.IsType <SimpleActivityProcessor>(builder.Processors.Single());
            Assert.Same(processor, builder.Processors[0]);
        }
        public void PipelineBuilder_AddProcessorChainWithExporter()
        {
            var builder = new ActivityProcessorPipelineBuilder();

            bool processorFactory1Called = false;
            bool processorFactory2Called = false;
            bool exportingFactory3Called = false;

            builder
            .AddProcessor(next =>
            {
                processorFactory1Called = true;
                Assert.NotNull(next);
                return(new TestProcessor(next, "1"));
            })
            .AddProcessor(next =>
            {
                processorFactory2Called = true;
                Assert.NotNull(next);
                return(new TestProcessor(next, "2"));
            })
            .SetExportingProcessor(exporter =>
            {
                exportingFactory3Called = true;
                Assert.NotNull(exporter);
                return(new SimpleActivityProcessor(exporter));
            })
            .SetExporter(new TestActivityExporter(null));

            var firstProcessor = (TestProcessor)builder.Build();

            Assert.Equal(3, builder.Processors.Count);
            Assert.True(processorFactory1Called);
            Assert.True(processorFactory2Called);
            Assert.True(exportingFactory3Called);

            Assert.Equal("1", firstProcessor.Name);

            var secondProcessor = (TestProcessor)firstProcessor.Next;

            Assert.Equal("2", secondProcessor.Name);
            var thirdProcessor = secondProcessor.Next;

            Assert.IsType <SimpleActivityProcessor>(thirdProcessor);
        }
        public void PipelineBuilder_AddProcessorChain()
        {
            var builder = new ActivityProcessorPipelineBuilder();

            bool processorFactory1Called = false;
            bool processorFactory2Called = false;
            bool processorFactory3Called = false;

            builder
            .AddProcessor(next =>
            {
                processorFactory1Called = true;
                Assert.NotNull(next);
                return(new TestProcessor(next, "1"));
            })
            .AddProcessor(next =>
            {
                processorFactory2Called = true;
                Assert.NotNull(next);
                return(new TestProcessor(next, "2"));
            })
            .AddProcessor(next =>
            {
                processorFactory3Called = true;
                Assert.Null(next);
                return(new TestProcessor(next, "3"));
            });

            var firstProcessor = (TestProcessor)builder.Build();

            Assert.Equal(3, builder.Processors.Count);
            Assert.True(processorFactory1Called);
            Assert.True(processorFactory2Called);
            Assert.True(processorFactory3Called);

            Assert.Equal("1", firstProcessor.Name);

            var secondProcessor = (TestProcessor)firstProcessor.Next;

            Assert.Equal("2", secondProcessor.Name);
            var thirdProcessor = (TestProcessor)secondProcessor.Next;

            Assert.Equal("3", thirdProcessor.Name);
        }
        public void PipelineBuilder_AddProcessor()
        {
            var builder = new ActivityProcessorPipelineBuilder();

            bool processorFactoryCalled = false;
            var  processor = new TestProcessor();

            builder.AddProcessor(e =>
            {
                processorFactoryCalled = true;
                return(processor);
            });

            Assert.Same(processor, builder.Build());

            Assert.Single(builder.Processors);
            Assert.True(processorFactoryCalled);
            Assert.Same(processor, builder.Processors.Single());
        }
        public void PipelineBuilder_AddExporterAndExportingProcessor()
        {
            var builder = new ActivityProcessorPipelineBuilder();

            var exporter = new TestActivityExporter(null);

            builder.SetExporter(exporter);

            bool processorFactoryCalled = false;

            builder.SetExportingProcessor(e =>
            {
                processorFactoryCalled = true;
                return(new SimpleActivityProcessor(e));
            });

            var processor = builder.Build();

            Assert.Single(builder.Processors);
            Assert.True(processorFactoryCalled);
            Assert.IsType <SimpleActivityProcessor>(builder.Processors.Single());
            Assert.Same(processor, builder.Processors[0]);
        }