예제 #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);
        }
예제 #2
0
        /// <summary>
        /// Add calling another pipeline.
        /// </summary>
        /// <param name="blueprint"></param>
        /// <param name="pipelineName"></param>
        /// <returns></returns>
        public static PipelineBlueprint CallPipeline(this PipelineBlueprint blueprint, string pipelineName)
        {
            var convey = Injection.InjectionProvider.Get <ConveyorContract>();

            blueprint.Apply(async(octx, tctx) =>
            {
                var package = await convey.Process(new Package
                {
                    Label = pipelineName,
                    Load  = octx.Unit,
                    Id    = octx.UnitId
                });

                return(package.Load);
            });
            return(blueprint);
        }
예제 #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);
        }
예제 #4
0
        public void OnIncorrectParameterTypeExceptionShouldReturns()
        {
            // 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((string str) => str))
            .Process(tctx, 1).Wait();

            // THAN
            tctx.Exception.Should().NotBeNull();
            tctx.Exception.InnerException.Should().NotBeNull();
            tctx.Exception.InnerException.GetType().Should().Be(typeof(ParameterTypeMissmatchException));
        }
예제 #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
            });
        }
예제 #6
0
 /// <summary>
 /// Add elements casting step.
 /// </summary>
 /// <typeparam name="TType"></typeparam>
 /// <param name="blueprint"></param>
 /// <returns></returns>
 public static PipelineBlueprint CastCollection <TType>(this PipelineBlueprint blueprint)
 {
     return
         (blueprint.Apply(
              (List <UnitContext> unit) => unit.Where(el => el.Unit != null).Select(el => el.GetUnit <TType>())));
 }