public async Task GivenEchoCallback_WhenItIsCalledWithInput_ItShouldReturnTheInput()
        {
            PipeCallback      processCallbackFunc = (input, broker) => Task.FromResult(input);
            PipeOutputPackage pipePackageOption   = PipeOutputPackage.Direct(typeof(string), typeof(string),
                                                                             processCallbackFunc);

            object output = await pipePackageOption.ProcessInput("abc", null);

            Assert.AreEqual("abc", output);
        }
        public void GivenCallbackWhichReturnsNull_WhenLegallyCalled_ItShouldThrowUnexpectedPipePackageOperationException
            ()
        {
            PipeCallback      processCallbackFunc = (input, broker) => null;
            PipeOutputPackage pipePackageOption   = PipeOutputPackage.Direct(typeof(string), typeof(string),
                                                                             processCallbackFunc);

            Assert.Throws <UnexpectedPipePackageOperationException>(
                async() => await pipePackageOption.ProcessInput("abc", null));
        }
        GivenProcessorWhichReturnsString_WhenProcesCallbackReturnsInteger_ItShouldThrowUnexpectedPipePackageOperationException
            ()
        {
            PipeCallback      processCallbackFunc = (input, broker) => Task.FromResult((object)2);
            PipeOutputPackage pipePackageOption   = PipeOutputPackage.Direct(typeof(string), typeof(string),
                                                                             processCallbackFunc);

            Assert.Throws <UnexpectedPipePackageOperationException>(
                async() => await pipePackageOption.ProcessInput("abc", null));
        }
        public void GivenPackageWhichProcessesIntegers_WhenInputParameterIsStringType_ItShouldThrowNotArgumentException()
        {
            PipeCallback      processCallbackFunc = (input, broker) => Task.FromResult((object)"abc");
            PipeOutputPackage pipePackageOption   = PipeOutputPackage.Direct(typeof(int), typeof(string),
                                                                             processCallbackFunc);

            var argumentException =
                Assert.Throws <ArgumentException>(async() => await pipePackageOption.ProcessInput("abc", null));

            Assert.AreEqual("input", argumentException.ParamName);
        }
        public void GivenPackageInstance_WhenNullPassedIntoInputParameter_ItShouldThrowArgumentNullException()
        {
            PipeCallback      processCallbackFunc = (input, broker) => null;
            PipeOutputPackage pipePackageOption   = PipeOutputPackage.Direct(typeof(string), typeof(string),
                                                                             processCallbackFunc);

            var argumentNullException =
                Assert.Throws <ArgumentNullException>(async() => await pipePackageOption.ProcessInput(null, null));

            Assert.AreEqual("input", argumentNullException.ParamName);
        }
示例#6
0
            public Task <TDestination> Output <TDestination>()
            {
                PipeOutputPackage     solvedPipePackage = _solver.SolveAsPipePackage(typeof(TSource), typeof(TDestination));
                Func <object, object> transformInput    =
                    TransformerFactory.ConvertFor(typeof(TSource), solvedPipePackage.InputType);
                Func <object, object> transformOutput =
                    TransformerFactory.ConvertFor(solvedPipePackage.OutputType, typeof(TDestination));

                var input = transformInput(_source);

                return
                    (solvedPipePackage.ProcessInput(input, _broker)
                     .ContinueWith(task => (TDestination)transformOutput(task.Result)));
            }
        public static PipeOutputPackage Bridge(PipeOutputPackage startPackage, PipeOutputPackage endPackage)
        {
            if (startPackage.OutputType != endPackage.InputType)
            {
                throw new NotSupportedException();
            }

            Type sourceType = startPackage.InputType;
            Type destinationType = endPackage.OutputType;
            int weight = startPackage.Weight + endPackage.Weight;

            PipeCallback processCallbackFunc =
                (input, broker) =>
                    startPackage.ProcessInput(input, broker)
                        .ContinueWith(startTask =>
                        {
                            object intermediate = startTask.Result;
                            return endPackage.ProcessInput(intermediate, broker);
                        }).Unwrap();

            return new PipeOutputPackage(weight, sourceType, destinationType, processCallbackFunc);
        }
示例#8
0
        public static PipeOutputPackage Bridge(PipeOutputPackage startPackage, PipeOutputPackage endPackage)
        {
            if (startPackage.OutputType != endPackage.InputType)
            {
                throw new NotSupportedException();
            }

            Type sourceType      = startPackage.InputType;
            Type destinationType = endPackage.OutputType;
            int  weight          = startPackage.Weight + endPackage.Weight;

            PipeCallback processCallbackFunc =
                (input, broker) =>
                startPackage.ProcessInput(input, broker)
                .ContinueWith(startTask =>
            {
                object intermediate = startTask.Result;
                return(endPackage.ProcessInput(intermediate, broker));
            }).Unwrap();

            return(new PipeOutputPackage(weight, sourceType, destinationType, processCallbackFunc));
        }