当前位置: 首页>>代码示例>>C#>>正文


C# HttpRequestMessage.SetUrlHelper方法代码示例

本文整理汇总了C#中System.Net.Http.HttpRequestMessage.SetUrlHelper方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestMessage.SetUrlHelper方法的具体用法?C# HttpRequestMessage.SetUrlHelper怎么用?C# HttpRequestMessage.SetUrlHelper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpRequestMessage的用法示例。


在下文中一共展示了HttpRequestMessage.SetUrlHelper方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUrlHelper_AndThen_GetUrlHelper_Returns_SameInstance

        public void SetUrlHelper_AndThen_GetUrlHelper_Returns_SameInstance()
        {
            HttpRequestMessage request = new HttpRequestMessage();
            UrlHelper urlHelper = new UrlHelper();

            request.SetUrlHelper(urlHelper);
            var retrievedUrlHelper = request.GetUrlHelper();

            Assert.Same(urlHelper, retrievedUrlHelper);
        }
开发者ID:balajivasudevan,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpRequestMessageExtensionsTest.cs

示例2: ExecuteOperationAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties

        public void ExecuteOperationAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties()
        {
            MockHttpServer server = new MockHttpServer(request =>
            {
                return new HttpResponseMessage
                {
                    RequestMessage = request
                };
            });
            UnbufferedODataBatchHandler batchHandler = new UnbufferedODataBatchHandler(server);
            HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, "http://example.com/$batch")
            {
                Content = new MultipartContent("mixed")
                {
                    ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Get, "http://example.com/")),
                }
            };
            batchRequest.Properties.Add("foo", "bar");
            batchRequest.SetRouteData(new HttpRouteData(new HttpRoute()));
            batchRequest.RegisterForDispose(new StringContent(String.Empty));
            batchRequest.SetUrlHelper(new UrlHelper());
            ODataMessageReader reader = batchRequest.Content.GetODataMessageReaderAsync(new ODataMessageReaderSettings { BaseUri = new Uri("http://example.com") }).Result;
            ODataBatchReader batchReader = reader.CreateODataBatchReader();
            List<ODataBatchResponseItem> responses = new List<ODataBatchResponseItem>();
            Guid batchId = Guid.NewGuid();
            batchReader.Read();

            var response = batchHandler.ExecuteOperationAsync(batchReader, Guid.NewGuid(), batchRequest, CancellationToken.None).Result;

            var operationResponse = ((OperationResponseItem)response).Response;
            var operationRequest = operationResponse.RequestMessage;
            Assert.Equal("bar", operationRequest.Properties["foo"]);
            Assert.Null(operationRequest.GetRouteData());
            Assert.Same(operationRequest, operationRequest.GetUrlHelper().Request);
            Assert.Empty(operationRequest.GetResourcesForDisposal());
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:36,代码来源:UnbufferedODataBatchHandlerTest.cs

示例3: ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties

        public void ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties()
        {
            DefaultODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer());
            HttpRequestMessage batchRequest = new HttpRequestMessage(HttpMethod.Post, "http://example.com/$batch")
            {
                Content = new MultipartContent("mixed")
                {
                    ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Get, "http://example.com/")),
                    new MultipartContent("mixed") // ChangeSet
                    {
                        ODataBatchRequestHelper.CreateODataRequestContent(new HttpRequestMessage(HttpMethod.Post, "http://example.com/values"))
                    }
                }
            };
            batchRequest.Properties.Add("foo", "bar");
            batchRequest.SetRouteData(new HttpRouteData(new HttpRoute()));
            batchRequest.RegisterForDispose(new StringContent(String.Empty));
            batchRequest.SetUrlHelper(new UrlHelper());

            IList<ODataBatchRequestItem> requests = batchHandler.ParseBatchRequestsAsync(batchRequest, CancellationToken.None).Result;

            Assert.Equal(2, requests.Count);

            var operationRequest = ((OperationRequestItem)requests[0]).Request;
            Assert.Equal(HttpMethod.Get, operationRequest.Method);
            Assert.Equal("http://example.com/", operationRequest.RequestUri.AbsoluteUri);
            Assert.Equal("bar", operationRequest.Properties["foo"]);
            Assert.Null(operationRequest.GetRouteData());
            Assert.Same(operationRequest, operationRequest.GetUrlHelper().Request);
            Assert.Empty(operationRequest.GetResourcesForDisposal());

            var changeSetRequest = ((ChangeSetRequestItem)requests[1]).Requests.First();
            Assert.Equal(HttpMethod.Post, changeSetRequest.Method);
            Assert.Equal("http://example.com/values", changeSetRequest.RequestUri.AbsoluteUri);
            Assert.Equal("bar", changeSetRequest.Properties["foo"]);
            Assert.Null(changeSetRequest.GetRouteData());
            Assert.Same(operationRequest, operationRequest.GetUrlHelper().Request);
            Assert.Empty(changeSetRequest.GetResourcesForDisposal());
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:39,代码来源:DefaultODataBatchHandlerTest.cs

示例4: ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties

        public void ParseBatchRequestsAsync_CopiesPropertiesFromRequest_WithoutExcludedProperties()
        {
            DefaultHttpBatchHandler batchHandler = new DefaultHttpBatchHandler(new HttpServer());
            HttpRequestMessage request = new HttpRequestMessage
            {
                Content = new MultipartContent("mixed")
                {
                    new HttpMessageContent(new HttpRequestMessage(HttpMethod.Get, "http://example.com/")),
                    new HttpMessageContent(new HttpRequestMessage(HttpMethod.Post, "http://example.com/values"))
                }
            };
            request.Properties.Add("foo", "bar");
            request.SetRouteData(new HttpRouteData(new HttpRoute()));
            request.SetUrlHelper(new UrlHelper());
            request.RegisterForDispose(new StringContent(String.Empty));

            IList<HttpRequestMessage> requests = batchHandler.ParseBatchRequestsAsync(request, CancellationToken.None).Result;

            Assert.Equal(2, requests.Count);
            Assert.Equal(HttpMethod.Get, requests[0].Method);
            Assert.Equal("bar", requests[0].Properties["foo"]);
            Assert.Null(requests[0].GetRouteData());
            Assert.Same(requests[0], requests[0].GetUrlHelper().Request);
            Assert.Empty(requests[0].GetResourcesForDisposal());
            Assert.Equal("http://example.com/", requests[0].RequestUri.AbsoluteUri);

            Assert.Equal(HttpMethod.Post, requests[1].Method);
            Assert.Equal("http://example.com/values", requests[1].RequestUri.AbsoluteUri);
            Assert.Equal("bar", requests[1].Properties["foo"]);
            Assert.Null(requests[1].GetRouteData());
            Assert.Same(requests[1], requests[1].GetUrlHelper().Request);
            Assert.Empty(requests[1].GetResourcesForDisposal());
        }
开发者ID:samgithub-duplicate,项目名称:aspnetwebstack,代码行数:33,代码来源:DefaultHttpBatchHandlerTest.cs


注:本文中的System.Net.Http.HttpRequestMessage.SetUrlHelper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。