Beispiel #1
0
        internal OperationHandlerPipelineContext ExecuteRequestPipeline(HttpRequestMessage request, object[] parameters)
        {
            Fx.Assert(request != null, "The 'request' parameter should not be null.");
            Fx.Assert(parameters != null, "The 'parameters' parameter should not be null.");

            OperationHandlerPipelineContext pipelineContext = new OperationHandlerPipelineContext(this.pipelineContextInfo, request);

            for (int handlerIndex = 0; handlerIndex < this.requestHandlersCount; handlerIndex++)
            {
                HttpOperationHandler handler      = this.requestHandlers[handlerIndex];
                object[]             inputValues  = pipelineContext.GetInputValues();
                object[]             outputValues = handler.Handle(inputValues);
                pipelineContext.SetOutputValuesAndAdvance(outputValues);
            }

            object[] pipelineParameters = pipelineContext.GetInputValues();

            Fx.Assert(pipelineParameters.Length == parameters.Length, "The two parameter object arrays should have the same length.");
            Array.Copy(pipelineParameters, parameters, parameters.Length);

            return(pipelineContext);
        }
        internal OperationHandlerPipelineContext ExecuteRequestPipeline(HttpRequestMessage request, object[] parameters)
        {
            Fx.Assert(request != null, "The 'request' parameter should not be null.");
            Fx.Assert(parameters != null, "The 'parameters' parameter should not be null.");

            OperationHandlerPipelineContext pipelineContext = new OperationHandlerPipelineContext(this.pipelineContextInfo, request);

            for (int handlerIndex = 0; handlerIndex < this.requestHandlersCount; handlerIndex++)
            {
                HttpOperationHandler handler = this.requestHandlers[handlerIndex];
                object[] inputValues = pipelineContext.GetInputValues();
                object[] outputValues = handler.Handle(inputValues);
                pipelineContext.SetOutputValuesAndAdvance(outputValues);
            }

            object[] pipelineParameters = pipelineContext.GetInputValues();

            Fx.Assert(pipelineParameters.Length == parameters.Length, "The two parameter object arrays should have the same length.");
            Array.Copy(pipelineParameters, parameters, parameters.Length);

            return pipelineContext;
        }
Beispiel #3
0
        internal HttpResponseMessage ExecuteResponsePipeline(OperationHandlerPipelineContext pipelineContext, object[] parameters, object result)
        {
            Fx.Assert(pipelineContext != null, "The 'pipelineContext' parameter should not be null.");
            Fx.Assert(parameters != null, "The 'parameters' parameter should not be null.");

            object[] pipelineParameters = new object[parameters.Length + 1];
            pipelineParameters[0] = result;
            Array.Copy(parameters, 0, pipelineParameters, 1, parameters.Length);
            pipelineContext.SetOutputValuesAndAdvance(pipelineParameters);

            for (int handlerIndex = 0; handlerIndex < this.responseHandlersCount; handlerIndex++)
            {
                HttpOperationHandler handler      = this.responseHandlers[handlerIndex];
                object[]             inputValues  = pipelineContext.GetInputValues();
                object[]             outputValues = handler.Handle(inputValues);
                pipelineContext.SetOutputValuesAndAdvance(outputValues);
            }

            return(pipelineContext.GetHttpResponseMessage());
        }
        public void GetInputValuesCallsPipelineInfo()
        {
            HttpOperationHandler[]    handlers  = new HttpOperationHandler[0];
            SHttpOperationDescription operation = new SHttpOperationDescription()
            {
                ReturnValue = HttpParameter.ResponseMessage
            };
            OperationHandlerPipelineInfo  pipelineInfo     = new OperationHandlerPipelineInfo(handlers, handlers, operation);
            MOperationHandlerPipelineInfo molePipelineInfo = new MOperationHandlerPipelineInfo(pipelineInfo);

            molePipelineInfo.GetEmptyPipelineValuesArray = () => new object[0];
            molePipelineInfo.SetHttpRequestMessageHttpRequestMessageObjectArray = (req, values) => { };

            bool calledForValues    = false;
            int  handlerIndexAtCall = -1;

            object[] valuesAtCall = null;
            molePipelineInfo.GetInputValuesForHandlerInt32ObjectArray = (index, values) =>
            {
                calledForValues    = true;
                handlerIndexAtCall = index;
                valuesAtCall       = values;
                return(new object[0]);
            };

            HttpRequestMessage request = new HttpRequestMessage();
            OperationHandlerPipelineContext context = new OperationHandlerPipelineContext(pipelineInfo, request);

            object[] returnedValues = context.GetInputValues();

            Assert.IsTrue(calledForValues, "PipelineInfo was not called for its values.");
            Assert.AreEqual(1, handlerIndexAtCall, "Handler index should have been 0.");
            Assert.IsNotNull(valuesAtCall, "Values at call should have not been null.");
            Assert.IsNotNull(returnedValues, "Returned values were null.");
            Assert.AreEqual(0, returnedValues.Length, "Returned values were incorrect length.");
        }
        internal HttpResponseMessage ExecuteResponsePipeline(OperationHandlerPipelineContext pipelineContext, object[] parameters, object result)
        {
            Fx.Assert(pipelineContext != null, "The 'pipelineContext' parameter should not be null.");
            Fx.Assert(parameters != null, "The 'parameters' parameter should not be null.");

            object[] pipelineParameters = new object[parameters.Length + 1];
            pipelineParameters[0] = result;
            Array.Copy(parameters, 0, pipelineParameters, 1, parameters.Length);
            pipelineContext.SetOutputValuesAndAdvance(pipelineParameters);

            for (int handlerIndex = 0; handlerIndex < this.responseHandlersCount; handlerIndex++)
            {
                HttpOperationHandler handler = this.responseHandlers[handlerIndex];
                object[] inputValues = pipelineContext.GetInputValues();
                object[] outputValues = handler.Handle(inputValues);
                pipelineContext.SetOutputValuesAndAdvance(outputValues);
            }

            return pipelineContext.GetHttpResponseMessage();
        }
        public void GetInputValuesCallsPipelineInfo()
        {
            HttpOperationHandler[] handlers = new HttpOperationHandler[0];
            SHttpOperationDescription operation = new SHttpOperationDescription() { ReturnValue = HttpParameter.ResponseMessage };
            OperationHandlerPipelineInfo pipelineInfo = new OperationHandlerPipelineInfo(handlers, handlers, operation);
            MOperationHandlerPipelineInfo molePipelineInfo = new MOperationHandlerPipelineInfo(pipelineInfo);
            molePipelineInfo.GetEmptyPipelineValuesArray = () => new object[0];
            molePipelineInfo.SetHttpRequestMessageHttpRequestMessageObjectArray = (req, values) => { };

            bool calledForValues = false;
            int handlerIndexAtCall = -1;
            object[] valuesAtCall = null;
            molePipelineInfo.GetInputValuesForHandlerInt32ObjectArray = (index, values) =>
            {
                calledForValues = true;
                handlerIndexAtCall = index;
                valuesAtCall = values;
                return new object[0];
            };

            HttpRequestMessage request = new HttpRequestMessage();
            OperationHandlerPipelineContext context = new OperationHandlerPipelineContext(pipelineInfo, request);

            object[] returnedValues = context.GetInputValues();

            Assert.IsTrue(calledForValues, "PipelineInfo was not called for its values.");
            Assert.AreEqual(1, handlerIndexAtCall, "Handler index should have been 0.");
            Assert.IsNotNull(valuesAtCall, "Values at call should have not been null.");
            Assert.IsNotNull(returnedValues, "Returned values were null.");
            Assert.AreEqual(0, returnedValues.Length, "Returned values were incorrect length.");
        }