public void Constructor()
 {
     SHttpOperationDescription operation = new SHttpOperationDescription() { CallBase = true, ReturnValue = HttpParameter.ResponseMessage };
     IEnumerable<HttpOperationHandler> emptyHandlers = Enumerable.Empty<HttpOperationHandler>();
     OperationHandlerPipeline pipeline = new OperationHandlerPipeline(emptyHandlers, emptyHandlers, operation);
     OperationHandlerFormatter formatter = new OperationHandlerFormatter(pipeline);
 }
Exemple #2
0
 public void Constructor()
 {
     HttpOperationHandler[]    handlers  = new HttpOperationHandler[0];
     SHttpOperationDescription operation = new SHttpOperationDescription()
     {
         ReturnValue = HttpParameter.ResponseMessage
     };
     OperationHandlerPipeline pipeline = new OperationHandlerPipeline(handlers, handlers, operation);
 }
Exemple #3
0
 public void Constructor()
 {
     SHttpOperationDescription operation = new SHttpOperationDescription()
     {
         CallBase = true, ReturnValue = HttpParameter.ResponseMessage
     };
     IEnumerable <HttpOperationHandler> emptyHandlers = Enumerable.Empty <HttpOperationHandler>();
     OperationHandlerPipeline           pipeline      = new OperationHandlerPipeline(emptyHandlers, emptyHandlers, operation);
     OperationHandlerFormatter          formatter     = new OperationHandlerFormatter(pipeline);
 }
Exemple #4
0
        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.");
        }
Exemple #5
0
        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.");
        }
Exemple #6
0
        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.");
        }
Exemple #7
0
        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.");
        }
        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.");
        }
Exemple #9
0
        internal OperationHandlerFormatter(OperationHandlerPipeline pipeline)
        {
            Fx.Assert(pipeline != null, "The 'pipeline' parameter should not be null.");

            this.pipeline = pipeline;
        }
Exemple #10
0
        /// <summary>
        /// Gets the <see cref="HttpMessageFormatter"/> to use for the given 
        /// <paramref name="operations"/> for the specified <paramref name="endpoint"/>.
        /// </summary>
        /// <remarks>
        /// The base implementation returns an <see cref="HttpMessageFormatter"/> with the
        /// <see cref="HttpOperationHandler"/> insances applied to the given operation.
        /// </remarks>
        /// <param name="endpoint">The endpoint exposing the operations.</param>
        /// <param name="operation">The <see cref="HttpOperationDescription"/>.</param>
        /// <returns>The <see cref="HttpMessageFormatter"/> to use for the <paramref name="operation"/>.</returns>
        protected virtual HttpMessageFormatter OnGetMessageFormatter(ServiceEndpoint endpoint, HttpOperationDescription operation)
        {
            Fx.Assert(endpoint != null, "The 'endpoint' parameter should not be null.");
            Fx.Assert(operation != null, "The 'operation' parameter should not be null.");

            OperationHandlerPipeline pipeline = null;
            if (this.OperationHandlerFactory == null)
            {
                Collection<HttpOperationHandler> handlers = new Collection<HttpOperationHandler>();
                pipeline = new OperationHandlerPipeline(handlers, handlers, operation);
            }
            else
            {
                Collection<HttpOperationHandler> requestHandlers = this.OperationHandlerFactory.CreateRequestHandlers(endpoint, operation);
                Collection<HttpOperationHandler> responseHandlers = this.OperationHandlerFactory.CreateResponseHandlers(endpoint, operation);

                pipeline = new OperationHandlerPipeline(requestHandlers, responseHandlers, operation);
            }

            OperationHandlerFormatter formatter = new OperationHandlerFormatter(pipeline);
            return formatter;
        }
        internal OperationHandlerFormatter(OperationHandlerPipeline pipeline)
        {
            Fx.Assert(pipeline != null, "The 'pipeline' parameter should not be null.");

            this.pipeline = pipeline;
        }
        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.");
        }