本文整理匯總了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);
}
示例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());
}
示例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());
}
示例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());
}