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); }
/// <summary> /// Serializes the given <paramref name="parameters"/> values into the outgoing <see cref="HttpResponseMessage"/>. /// </summary> /// <param name="parameters">The array of values that need to be serialialized.</param> /// <param name="result">The return value of the operation that needs to be serialized.</param> /// <returns>The <see cref="HttpResponseMessage"/> to return. It cannot be <c>null</c>.</returns> protected override HttpResponseMessage OnSerializeReply(object[] parameters, object result) { OperationHandlerPipelineContext pipelineContext = this.CachedPipelineContext; Fx.Assert(pipelineContext != null, "The pipelineContext should always be available."); return(this.pipeline.ExecuteResponsePipeline(pipelineContext, parameters, result)); }
public void ExecuteRequestPipeline() { HttpOperationHandler[] handlers = new HttpOperationHandler[0]; SHttpOperationDescription operation = new SHttpOperationDescription() { ReturnValue = HttpParameter.ResponseMessage }; OperationHandlerPipeline pipeline = new OperationHandlerPipeline(handlers, handlers, operation); HttpRequestMessage request = new HttpRequestMessage(); OperationHandlerPipelineContext context = pipeline.ExecuteRequestPipeline(request, new object[0]); Assert.IsNotNull(context, "Execute returned null context."); }
public void OnDeserializeRequestExecutesRequestPipeline() { SHttpOperationDescription operation = new SHttpOperationDescription() { CallBase = true, ReturnValue = HttpParameter.ResponseMessage }; IEnumerable <HttpOperationHandler> emptyHandlers = Enumerable.Empty <HttpOperationHandler>(); OperationHandlerPipeline pipeline = new OperationHandlerPipeline(emptyHandlers, emptyHandlers, operation); MOperationHandlerPipeline molePipeline = new MOperationHandlerPipeline(pipeline); molePipeline.BehaveAsDefaultValue(); MOperationHandlerPipelineContext moleContext = new MOperationHandlerPipelineContext(); HttpRequestMessage setRequest = null; object[] setValues = null; OperationHandlerPipelineContext setContext = null; molePipeline.ExecuteRequestPipelineHttpRequestMessageObjectArray = (request, values) => { setRequest = request; setValues = values; return(setContext = moleContext); }; OperationHandlerFormatter formatter = new OperationHandlerFormatter(molePipeline); IDispatchMessageFormatter dispatchMessageFormatter = (IDispatchMessageFormatter)formatter; Uri uri = new Uri("http://somehost/Fred"); HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, uri); httpRequest.Content = new StringContent(""); Message message = httpRequest.ToMessage(); object[] parameters = new object[0]; dispatchMessageFormatter.DeserializeRequest(message, parameters); HttpAssert.AreEqual(httpRequest, setRequest); Assert.IsNotNull(setValues, "Input values were not passed to the pipeline."); Assert.AreEqual(0, ((object[])setValues).Length, "Incorrect number of values."); Assert.IsNotNull(setContext, "Context was not set."); }
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 OnSerializeReplyExecutesResponsePipeline() { SHttpOperationDescription operation = new SHttpOperationDescription() { CallBase = true, ReturnValue = HttpParameter.ResponseMessage }; IEnumerable <HttpOperationHandler> emptyHandlers = Enumerable.Empty <HttpOperationHandler>(); OperationHandlerPipeline pipeline = new OperationHandlerPipeline(emptyHandlers, emptyHandlers, operation); MOperationHandlerPipeline molePipeline = new MOperationHandlerPipeline(pipeline); molePipeline.BehaveAsDefaultValue(); MOperationHandlerPipelineContext moleContext = new MOperationHandlerPipelineContext(); HttpResponseMessage response = new HttpResponseMessage(); OperationHandlerPipelineContext setContext = null; object[] setValues = null; object setResult = null; molePipeline.ExecuteResponsePipelineOperationHandlerPipelineContextObjectArrayObject = (context, values, result) => { setContext = context; setValues = values; setResult = result; return(response); }; OperationHandlerFormatter formatter = new OperationHandlerFormatter(molePipeline); IDispatchMessageFormatter dispatchMessageFormatter = (IDispatchMessageFormatter)formatter; object[] parameters = new object[] { 1, "text" }; Message message = dispatchMessageFormatter.SerializeReply(MessageVersion.None, parameters, "theResult"); Assert.IsNotNull(setValues, "Input values were not passed to the pipeline."); CollectionAssert.AreEqual(new List <object>(parameters), new List <object>(setValues), "Parameters were not passed correctly."); Assert.AreEqual("theResult", setResult, "Result was not passed correctly."); Assert.IsNotNull(setContext, "Context was not set."); }
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; }
public void ExecuteResponsePipeline() { HttpOperationHandler[] handlers = new HttpOperationHandler[0]; SHttpOperationDescription operation = new SHttpOperationDescription() { ReturnValue = HttpParameter.ResponseMessage }; OperationHandlerPipeline pipeline = new OperationHandlerPipeline(handlers, handlers, operation); HttpRequestMessage request = new HttpRequestMessage(); HttpResponseMessage response = new HttpResponseMessage() { RequestMessage = request }; OperationHandlerPipelineContext context = pipeline.ExecuteRequestPipeline(request, new object[0]); //// TODO: what is the convention for returning an HttpResponse from the operation? HttpResponseMessage actualResponse = pipeline.ExecuteResponsePipeline(context, new object[0], response); Assert.IsNotNull(actualResponse, "Execute returned null response."); }
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); }
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."); }
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 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."); }
/// <summary> /// Deserializes the incoming <see cref="HttpRequestMessage"/> into the given <paramref name="parameters"/>. /// </summary> /// <param name="request">The incoming <see cref="HttpRequestMessage"/> containing the content /// that requires deserialization</param> /// <param name="parameters">The array of objects into which this method should deserialize.</param> protected override void OnDeserializeRequest(HttpRequestMessage request, object[] parameters) { OperationHandlerPipelineContext pipelineContext = this.pipeline.ExecuteRequestPipeline(request, parameters); this.CachedPipelineContext = pipelineContext; }
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(); }