本文整理匯總了C#中System.Net.Http.HttpRequestMessage.SetFakeODataRouteName方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpRequestMessage.SetFakeODataRouteName方法的具體用法?C# HttpRequestMessage.SetFakeODataRouteName怎麽用?C# HttpRequestMessage.SetFakeODataRouteName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Net.Http.HttpRequestMessage
的用法示例。
在下文中一共展示了HttpRequestMessage.SetFakeODataRouteName方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetSampleRequest
private static HttpRequestMessage GetSampleRequest()
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/property");
request.SetEdmModel(GetSampleModel());
HttpConfiguration configuration = new HttpConfiguration();
configuration.Routes.MapFakeODataRoute();
request.SetConfiguration(configuration);
request.SetFakeODataRouteName();
return request;
}
示例2: PrimitiveTypesSerializeAsOData
public void PrimitiveTypesSerializeAsOData(Type valueType, object value, MediaTypeHeaderValue mediaType,
string resourceName)
{
string expectedEntity = Resources.GetString(resourceName);
Assert.NotNull(expectedEntity);
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<WorkItem>("WorkItems");
IEdmModel model = modelBuilder.GetEdmModel();
string actualEntity;
using (HttpConfiguration configuration = CreateConfiguration())
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
"http://localhost/WorkItems(10)/ID"))
{
request.SetConfiguration(configuration);
IEdmProperty property =
model.EntityContainer.EntitySets().Single().EntityType().Properties().First();
request.ODataProperties().Model = model;
request.ODataProperties().Path = new ODataPath(new PropertyAccessPathSegment(property));
request.SetFakeODataRouteName();
ODataMediaTypeFormatter formatter = CreateFormatter(request);
formatter.SupportedMediaTypes.Add(mediaType);
Type type = (value != null) ? value.GetType() : typeof(Nullable<int>);
using (ObjectContent content = new ObjectContent(type, value, formatter))
{
actualEntity = content.ReadAsStringAsync().Result;
}
}
bool isJson = resourceName.EndsWith(".json");
if (isJson)
{
JsonAssert.Equal(expectedEntity, actualEntity);
}
else
{
Assert.Xml.Equal(expectedEntity, actualEntity);
}
}
示例3: CreateMetadataLinkFactory
private static UrlHelper CreateMetadataLinkFactory(string metadataPath)
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, metadataPath);
HttpConfiguration configuration = new HttpConfiguration();
configuration.Routes.MapFakeODataRoute();
request.SetConfiguration(configuration);
request.SetFakeODataRouteName();
return new UrlHelper(request);
}
示例4: AddRequestInfo
private void AddRequestInfo(HttpRequestMessage request)
{
request.ODataProperties().Path = new DefaultODataPathHandler()
.Parse(_model, GetODataPath(request.RequestUri.AbsoluteUri));
request.ODataProperties().Model = _model;
request.SetFakeODataRouteName();
}
示例5: AddRequestInfo
private void AddRequestInfo(HttpRequestMessage request)
{
request.SetODataPath(new DefaultODataPathHandler().Parse(_model, GetODataPath(
request.RequestUri.AbsoluteUri)));
request.SetEdmModel(_model);
request.SetFakeODataRouteName();
}