本文整理汇总了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());
}