public void GetHttpResponseMessageCallsPipelineInfo()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            HttpResponseMessage response = new HttpResponseMessage() { RequestMessage = request };
            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) => { };
            molePipelineInfo.GetHttpResponseMessageObjectArray = (values) => response;
            OperationHandlerPipelineContext context = new OperationHandlerPipelineContext(pipelineInfo, request);

            HttpResponseMessage responseReturned = context.GetHttpResponseMessage();

            Assert.IsNotNull(responseReturned, "HttpResponseMessage was not returned.");
            HttpAssert.AreEqual(response, responseReturned);
        }
        public void Constructor()
        {
            HttpOperationHandler[] handlers = new HttpOperationHandler[0];
            SHttpOperationDescription operation = new SHttpOperationDescription() { ReturnValue = HttpParameter.ResponseMessage };
            OperationHandlerPipelineInfo pipelineInfo = new OperationHandlerPipelineInfo(handlers, handlers, operation);
            MOperationHandlerPipelineInfo molePipelineInfo = new MOperationHandlerPipelineInfo(pipelineInfo);
            HttpRequestMessage requestAtCall = null;
            object[] valuesAtCall = null;

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

            OperationHandlerPipelineContext context = new OperationHandlerPipelineContext(pipelineInfo, request);

            Assert.IsNotNull(requestAtCall, "HttpRequestMessage was not set in pipeline info.");
            Assert.IsNotNull(valuesAtCall, "Values were not set in pipeline info.");
            HttpAssert.AreEqual(request, requestAtCall);
        }
            internal OperationHandlerInfo(int offset, HttpOperationHandler handler)
            {
                Fx.Assert(handler != null, "The 'handler' parameter should not be null.");

                this.PipelineValuesOffset = offset;
                this.HandlerInputCount = handler.InputParameters.Count;
                this.OutputParameterInfo = new OutputParameterInfo[handler.OutputParameters.Count];
            }
        private static void ThrowForUnboundResponseHandler(HttpOperationHandler handler, HttpParameter parameter, string operationName)
        {
            Fx.Assert(handler != null, "The 'handler' parameter should not be null.");
            Fx.Assert(parameter != null, "The 'parameter' parameter should not be null.");
            Fx.Assert(operationName != null, "The 'operationName' parameter should not be null.");

            string exceptionMessage = null;

            if (parameter.ValueConverter.CanConvertFromString)
            {
                exceptionMessage = SR.ResponseHandlerWithNoPossibleBindingForStringConvertableType(
                    HttpOperationHandler.HttpOperationHandlerType.Name,
                    handler.ToString(),
                    operationName,
                    parameter.Name,
                    parameter.Type.Name,
                    handler.GetType().Name);
            }
            else
            {
                exceptionMessage = SR.ResponseHandlerWithNoPossibleBindingForNonStringConvertableType(
                    HttpOperationHandler.HttpOperationHandlerType.Name,
                    handler.ToString(),
                    operationName,
                    parameter.Name,
                    parameter.Type.Name,
                    handler.GetType().Name);
            }

            Fx.Assert(exceptionMessage != null, "The 'exceptionMessage' variable should have been set.");
            throw Fx.Exception.AsError(new InvalidOperationException(exceptionMessage));
        }
        private static void ThrowForUnboundParameter(HttpOperationHandler handler, HttpParameter parameter, HandlerType handlerType, string operationName)
        {
            Fx.Assert(handler != null, "The 'handler' parameter should not be null.");
            Fx.Assert(parameter != null, "The 'parameter' parameter should not be null.");
            Fx.Assert(operationName != null, "The 'operationName' parameter should not be null.");

            if (handler == responseMessageSinkHandler)
            {
                throw Fx.Exception.AsError(
                    new InvalidOperationException(
                        SR.ResponseSinkHandlerWithNoHttpResponseMessageSource(
                            HttpOperationHandler.HttpOperationHandlerType.Name,
                            HttpTypeHelper.HttpResponseMessageType.Name,
                            operationName)));
            }

            switch (handlerType)
            {
                case HandlerType.Request:
                    ThrowForUnboundRequestHandler(handler, parameter, operationName);
                    break;
                case HandlerType.ServiceOperation:
                    ThrowForUnboundServiceOperation(parameter, operationName);
                    break;
                case HandlerType.Response:
                    ThrowForUnboundResponseHandler(handler, parameter, operationName);
                    break;
                default:
                    Fx.Assert("The handlerType should have been one of the above cases.");
                    break;
            }
        }
Exemplo n.º 6
0
 public OperRuleTemplate(RuleResult r, HttpOperationHandler p)
 {
     //ValidateHandler(p);
     _p = p;
     _r = r;
 }
Exemplo n.º 7
0
 public OperPredAndRuleBuilder DefinePredicate(HttpOperationHandler p)
 {
     _orb.Add(new OperRuleTemplate(_r, p));
     return _orb;
 }
        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.");
        }
        public void SetOutputValuesAndAdvanceCallsPipelineInfo()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            HttpResponseMessage response = new HttpResponseMessage() { RequestMessage = request };
            HttpOperationHandler[] handlers = new HttpOperationHandler[0];
            SHttpOperationDescription operation = new SHttpOperationDescription() { ReturnValue = HttpParameter.ResponseMessage };
            OperationHandlerPipelineInfo pipelineInfo = new OperationHandlerPipelineInfo(handlers, handlers, operation);

            int indexAtCall = -1;
            object[] valuesAtCall = null;
            object[] pipelineValuesAtCall = null;

            MOperationHandlerPipelineInfo molePipelineInfo = new MOperationHandlerPipelineInfo(pipelineInfo);
            molePipelineInfo.GetEmptyPipelineValuesArray = () => new object[0];
            molePipelineInfo.SetHttpRequestMessageHttpRequestMessageObjectArray = (req, values) => { };
            molePipelineInfo.SetOutputValuesFromHandlerInt32ObjectArrayObjectArray = (index, values, pipelineValues) =>
                {
                    indexAtCall = index;
                    valuesAtCall = values;
                    pipelineValuesAtCall = pipelineValues;
                };

            OperationHandlerPipelineContext context = new OperationHandlerPipelineContext(pipelineInfo, request);

            context.SetOutputValuesAndAdvance(new object[0]);

            Assert.AreEqual(1, indexAtCall, "Handler index was not set.");
            Assert.IsNotNull(valuesAtCall, "Values were not set.");
            Assert.IsNotNull(pipelineValuesAtCall, "Pipeline values were not set.");
        }