Beispiel #1
0
        public void SingleTaskWithActionsShouldWorksWell()
        {
            // GIVEN
            mLogs.Logs.Clear();
            var injectionProvider = new IoCContainer();

            injectionProvider.Register <TestMultiplicatorStep>();
            Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false);
            PipelineBlueprint blueprint      = PipelineBlueprint.CreateBlueprint(typeof(int), "SingleApply");
            PipelineBlueprint blueprintOther = PipelineBlueprint.CreateBlueprint(typeof(int), "DoubleApply");

            // WHEN
            TransferingContext tctx = new TransferingContext(new Headers {
                { "factor", 10 }
            }.Dict);

            new Pipeline(blueprint
                         .Apply <TestMultiplicatorStep>("multiplyby2")
                         .Apply <TestMultiplicatorStep>("sync_mbf"))
            .Process(tctx, 1).Wait();

            TransferingContext otherTctx = new TransferingContext(new Headers {
                { "factor", 10 }
            }.Dict);

            new Pipeline(blueprintOther
                         .Apply <TestMultiplicatorStep>("sync_mbf")
                         .Apply <TestMultiplicatorStep>("multiplyby2")
                         .Apply <TestMultiplicatorStep>("sync_mbf"))
            .Process(otherTctx, 1).Wait();

            // THAN
            tctx.GetResult <int>().Should().Be(20);
            otherTctx.GetResult <int>().Should().Be(200);
        }
Beispiel #2
0
        public void SplitShouldWorksWell()
        {
            // GIVEN
            mLogs.Logs.Clear();
            var intSource = new List <int> {
                2, 4, 6
            };

            var injectionProvider = new IoCContainer();

            injectionProvider.RegisterSingle(intSource);
            JustConveyor.Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider);

            var blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "IntMultiplicatorBlueprint")
                            .Split <TestIntSource>()
                            .Apply <TestMultiplicatorStep>("multiplybyfactor")
                            .Collect()
                            .Apply((List <UnitContext> unit) => unit.Select(el => el.GetUnit <int>()).ToList());

            // WHEN
            Pipeline           pipeline = new Pipeline(blueprint);
            TransferingContext tctx     = new TransferingContext(new Headers {
                { "factor", 10 }
            }.Dict);

            pipeline.Process(tctx, 1).Wait();
            List <int> result = tctx.GetResult <List <int> >();

            // THAN
            result.ShouldBeEquivalentTo(new List <int> {
                20, 40, 60
            });
        }
Beispiel #3
0
        public void SingleTaskShouldWorksWell()
        {
            // GIVEN
            mLogs.Logs.Clear();
            var injectionProvider = new IoCContainer();

            injectionProvider.Register <TestMultiplicatorStep>();
            Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false);
            PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "SingleApply");

            // WHEN
            TransferingContext tctx = new TransferingContext();

            new Pipeline(blueprint.Apply <TestMultiplicatorStep>("multiplyby2"))
            .Process(tctx, 1).Wait();

            // THAN
            tctx.GetResult <int>().Should().Be(2);
        }
Beispiel #4
0
        public void SyncSpitCollectShouldWorksWell()
        {
            // GIVEN
            mLogs.Logs.Clear();

            var ints = new List <int> {
                1, 2, 3
            };

            var injectionProvider = new IoCContainer();

            injectionProvider.RegisterSingle(ints);
            injectionProvider.Register <TestIntSource>();
            injectionProvider.Register <TestMultiplicatorStep>();
            Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false);

            PipelineBlueprint blueprint = PipelineBlueprint.CreateBlueprint(typeof(int), "SyncSplitCollect");

            // WHEN
            var result = blueprint
                         .Split <TestIntSource>()
                         .Apply((int el) => el * 10)
                         .Collect()
                         .Apply((IList <UnitContext> octx) => octx.Select(el => el.GetUnit <int>()));

            TransferingContext tctx = new TransferingContext();

            new Pipeline(result)
            .Process(tctx, 1)
            .Wait();

            // THAN
            tctx.Exception.Should().BeNull();
            tctx.GetResult <IEnumerable <int> >().ShouldBeEquivalentTo(new List <int> {
                10, 20, 30
            });
        }
Beispiel #5
0
        public void AsyncSpitCollectShouldWorksWell()
        {
            // GIVEN
            mLogs.Logs.Clear();

            var ints = new List <int> {
                1, 2, 3
            };

            var injectionProvider = new IoCContainer();

            injectionProvider.RegisterSingle(ints);
            injectionProvider.Register <TestIntSource>();
            injectionProvider.Register <TestMultiplicatorStep>();
            Contracts.Dependencies.Injection.RegisterInjectionProvider(injectionProvider, false);

            PipelineBlueprint blueprint         = PipelineBlueprint.CreateBlueprint(typeof(int), "AsyncSplitCollect");
            PipelineBlueprint blueprintOther    = PipelineBlueprint.CreateBlueprint(typeof(int), "OtherAsyncSplitCollect");
            PipelineBlueprint blueprintOneOther = PipelineBlueprint.CreateBlueprint(typeof(int),
                                                                                    "OneOtherAsyncSplitCollect");

            // WHEN
            TransferingContext tctx = new TransferingContext(new Headers {
                { "factor", 10 }
            }.Dict);

            new Pipeline(blueprint
                         .Split <TestIntSource>()
                         .Apply <TestMultiplicatorStep>("multiplybyfactor")
                         .Collect()
                         .Apply((IList <UnitContext> octx) => octx.Select(el => el.GetUnit <int>()).ToList()))
            .Process(tctx, 1)
            .Wait();

            TransferingContext otherTctx = new TransferingContext(new Headers {
                { "factor", 10 }
            }.Dict);

            new Pipeline(blueprintOther
                         .Split <TestIntSource>()
                         .Apply <TestMultiplicatorStep>("multiplybyfactor")
                         .Collect()
                         .Apply <TestMultiplicatorStep>("strip"))
            .Process(otherTctx, 1)
            .Wait();

            TransferingContext oneAnotherTctx = new TransferingContext(new Headers {
                { "factor", 10 }
            }.Dict);

            new Pipeline(blueprintOneOther
                         .Apply <TestMultiplicatorStep>("multiplybyfactor")
                         .Split <TestIntSource>()
                         .Apply <TestMultiplicatorStep>("multiplybyfactor")
                         .Collect()
                         .Apply <TestMultiplicatorStep>("strip"))
            .Process(oneAnotherTctx, 1)
            .Wait();

            // THAN
            tctx.Exception?.InnerException.Should().BeNull();
            tctx.GetResult <List <int> >().ShouldBeEquivalentTo(new List <int> {
                10, 20, 30
            });

            otherTctx.Exception?.InnerException.Should().BeNull();
            otherTctx.GetResult <List <int> >().ShouldBeEquivalentTo(new List <int> {
                10, 20, 30
            });

            oneAnotherTctx.Exception?.InnerException.Should().BeNull();
            oneAnotherTctx.GetResult <List <int> >().ShouldBeEquivalentTo(new List <int> {
                10, 20, 30
            });
        }