本文整理汇总了C#中HttpConfiguration.AddFakeODataRoute方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.AddFakeODataRoute方法的具体用法?C# HttpConfiguration.AddFakeODataRoute怎么用?C# HttpConfiguration.AddFakeODataRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpConfiguration
的用法示例。
在下文中一共展示了HttpConfiguration.AddFakeODataRoute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InheritanceTests
public InheritanceTests()
{
_configuration = new HttpConfiguration();
_model = GetEdmModel();
IEnumerable<ODataMediaTypeFormatter> formatters = ODataMediaTypeFormatters.Create(_model);
_configuration.Formatters.Clear();
_configuration.Formatters.AddRange(formatters);
_configuration.AddFakeODataRoute();
_configuration.Routes.MapHttpRoute("default", "{action}", new { Controller = "Inheritance" });
_server = new HttpServer(_configuration);
_client = new HttpClient(_server);
}
示例2: PrimitiveTypesDeserializeAsOData
public void PrimitiveTypesDeserializeAsOData(string typeString, Type type, object value)
{
HttpConfiguration configuration = new HttpConfiguration();
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<WorkItem>("WorkItems");
IEdmModel model = modelBuilder.GetEdmModel();
configuration.AddFakeODataRoute();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/WorkItems(10)/ID");
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
ODataMediaTypeFormatter formatter = CreateFormatter(model, request);
ObjectContent content = new ObjectContent(type, value, formatter, "application/xml");
var stream = content.ReadAsStreamAsync().Result;
Assert.Equal(
value,
formatter.ReadFromStreamAsync(type, stream, content, new Mock<IFormatterLogger>().Object).Result);
}
示例3: PrimitiveTypesSerializeAsOData
public void PrimitiveTypesSerializeAsOData(string typeString, Type valueType, object value)
{
string expected = BaselineResource.ResourceManager.GetString(typeString);
Assert.NotNull(expected);
ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
modelBuilder.EntitySet<WorkItem>("WorkItems");
IEdmModel model = modelBuilder.GetEdmModel();
HttpConfiguration configuration = new HttpConfiguration();
configuration.AddFakeODataRoute();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/WorkItems(10)/ID");
request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
request.Properties["MS_ODataPath"] = new DefaultODataPathHandler(model).Parse("WorkItems(10)/ID");
ODataMediaTypeFormatter formatter = CreateFormatter(model, request);
Type type = (value != null) ? value.GetType() : typeof(Nullable<int>);
ObjectContent content = new ObjectContent(type, value, formatter);
var result = content.ReadAsStringAsync().Result;
Assert.Xml.Equal(result, expected);
}