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