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));
        }
        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 Ctor_WhenNullToProcessCallbackFuncParameter_ItShouldThrowArgumentNullExcpetion()
        {
            var argumentNullException = Assert.Throws <ArgumentNullException>(() =>
            {
                PipeOutputPackage pipePackageOption = PipeOutputPackage.Direct(typeof(string), typeof(string), null);
                Assert.Fail();
            });

            Assert.AreEqual("processCallbackFunc", argumentNullException.ParamName);
        }
        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);
        }
        private static PipeOutputPackage CreatePipeOutputPackage <TSource, TDestination>(
            Func <TSource, ISemanticBroker, TDestination> processCallback)
        {
            PipeCallback wrappedProcessCallback = (input, broker) =>
            {
                var    castedInput = (TSource)input;
                object result      = processCallback(castedInput, broker);
                return(result.IntoTaskResult());
            };

            return(PipeOutputPackage.Direct(typeof(TSource), typeof(TDestination), wrappedProcessCallback));
        }
        public void Ctor_WhenNullToOutputTypeParameter_ItShouldThrowArgumentNullExcpetion()
        {
            var argumentNullException = Assert.Throws <ArgumentNullException>(() =>
            {
                PipeCallback processCallbackFunc    = (input, broker) => null;
                PipeOutputPackage pipePackageOption = PipeOutputPackage.Direct(typeof(string), null,
                                                                               processCallbackFunc);

                Assert.Fail();
            });

            Assert.AreEqual("outputType", argumentNullException.ParamName);
        }
        private static PipeOutputPackage CreateAsyncPipeOutputPackage <TSource, TDestination>(
            Func <TSource, ISemanticBroker, Task <TDestination> > processCallback)
        {
            PipeCallback wrappedProcessCallback = (input, broker) =>
            {
                var castedInput = (TSource)input;

                return
                    (processCallback(castedInput, broker)
                     .ContinueWith(task => (object)task.Result));
            };

            return(PipeOutputPackage.Direct(typeof(TSource), typeof(TDestination), wrappedProcessCallback));
        }