本文整理汇总了C#中System.Collections.Generic.MapODataServiceRoute方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.Generic.MapODataServiceRoute方法的具体用法?C# System.Collections.Generic.MapODataServiceRoute怎么用?C# System.Collections.Generic.MapODataServiceRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic
的用法示例。
在下文中一共展示了System.Collections.Generic.MapODataServiceRoute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenComplexType_SimpleDeserialization
public void OpenComplexType_SimpleDeserialization()
{
// Arrange
const string Payload = "{" +
"\"@odata.context\":\"http://localhost/odata/$metadata#OpenCustomers/$entity\"," +
"\"CustomerId\":6,\"Name\":\"FirstName 6\"," +
"\"Address\":{" +
"\"Street\":\"Street 6\",\"City\":\"City 6\",\"Country\":\"Earth\",\"[email protected]\":\"#Guid\"," +
"\"Token\":\"4DB52263-4382-4BCB-A63E-3129C1B5FA0D\"," +
"\"Number\":990" +
"}" +
"}";
const string RequestUri = "http://localhost/odata/OpenCustomers";
HttpConfiguration configuration = new[] { typeof(OpenCustomersController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", GetEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, RequestUri);
request.Content = new StringContent(Payload);
request.Content.Headers.ContentType = MediaTypeWithQualityHeaderValue.Parse("application/json");
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
JObject result = JObject.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal("http://localhost/odata/$metadata#OpenCustomers/$entity", result["@odata.context"]);
Assert.Equal("Earth", result["Address"]["Country"]);
Assert.Equal(990, result["Address"]["Number"]);
Assert.Equal("4DB52263-4382-4BCB-A63E-3129C1B5FA0D".ToLower(), result["Address"]["Token"]);
}
示例2: AttributeRouting_QueryProperty_AfterCallBoundFunction
public async Task AttributeRouting_QueryProperty_AfterCallBoundFunction()
{
// Arrange
const string RequestUri = @"http://localhost/Customers(12)/NS.GetOrder(orderId=4)/Amount";
CustomersModelWithInheritance model = new CustomersModelWithInheritance();
HttpConfiguration config = new[] { typeof(CustomersController) }.GetHttpConfiguration();
config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
config.MapODataServiceRoute("odata", "", model.Model);
HttpServer server = new HttpServer(config);
config.EnsureInitialized();
HttpClient client = new HttpClient(server);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri);
// Act
HttpResponseMessage response = await client.SendAsync(request);
string responseString = await response.Content.ReadAsStringAsync();
// Assert
Assert.True(response.IsSuccessStatusCode);
Assert.Equal("{\r\n \"@odata.context\":\"http://localhost/$metadata#Edm.Int32\",\"value\":56\r\n}",
responseString);
}
示例3: Post_OpenEntityType
public void Post_OpenEntityType()
{
// Arrange
const string Payload = "{" +
"\"@odata.context\":\"http://localhost/odata/$metadata#OpenCustomers/$entity\"," +
"\"CustomerId\":6,\"Name\":\"FirstName 6\"," +
"\"Address\":{" +
"\"Street\":\"Street 6\",\"City\":\"City 6\",\"Country\":\"Earth\",\"[email protected]\":\"#Guid\"," +
"\"Token\":\"4DB52263-4382-4BCB-A63E-3129C1B5FA0D\"," +
"\"Number\":990" +
"}," +
"\"Website\": \"WebSite #6\",\"Country\":\"My Dynamic Country\",\"[email protected]\":\"#Guid\",\"Token\":\"2c1f450a-a2a7-4fe1-a25d-4d9332fc0694\"," +
"\"[email protected]\":\"#Collection(Double)\"," +
"\"DoubleList\":[5.5, 4.4, 3.3]" +
"}";
const string RequestUri = "http://localhost/odata/SimpleOpenCustomers";
var configuration = new[] { typeof(SimpleOpenCustomersController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", GetEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, RequestUri);
request.Content = new StringContent(Payload);
request.Content.Headers.ContentType = MediaTypeWithQualityHeaderValue.Parse("application/json");
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
}
示例4: OpenComplexType_SimpleSerialization
public void OpenComplexType_SimpleSerialization(bool enableNullDynamicProperty)
{
// Arrange
const string RequestUri = "http://localhost/odata/OpenCustomers(2)/Address";
var configuration = new[] { typeof(OpenCustomersController) }.GetHttpConfiguration();
configuration.SetSerializeNullDynamicProperty(enableNullDynamicProperty);
configuration.MapODataServiceRoute("odata", "odata", GetEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri);
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=full"));
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
JObject result = JObject.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal("http://localhost/odata/$metadata#OpenCustomers(2)/Address", result["@odata.context"]);
Assert.Equal("Street 2", result["Street"]);
Assert.Equal("City 2", result["City"]);
Assert.Equal("300", result["IntProp"]);
Assert.Equal("My Dynamic Country", result["Country"]);
Assert.Equal("2c1f450a-a2a7-4fe1-a25d-4d9332fc0694", result["Token"]);
Assert.Equal("2015-03-02", result["Birthday"]);
if (enableNullDynamicProperty)
{
Assert.NotNull(result["Region"]);
Assert.Equal(JValue.CreateNull(), result["Region"]);
}
else
{
Assert.Null(result["Region"]);
}
}
示例5: Get_OpenEntityType
public void Get_OpenEntityType()
{
// Arrange
const string RequestUri = "http://localhost/odata/SimpleOpenCustomers(9)";
var configuration = new[] { typeof(SimpleOpenCustomersController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", GetEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri);
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=full"));
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
JObject result = JObject.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal("http://localhost/odata/$metadata#SimpleOpenCustomers/$entity", result["@odata.context"]);
Assert.Equal("#System.Web.OData.SimpleVipCustomer", result["@odata.type"]);
Assert.Equal(9, result["CustomerId"]);
Assert.Equal("VipCustomer", result["Name"]);
Assert.Equal("#Collection(Int32)", result["[email protected]"]);
Assert.Equal(new JArray(new[] { 200, 100, 300, 0, 400 }), result["ListProp"]);
Assert.Equal("0001-01-01", result["DateList"][0]);
Assert.Equal("9999-12-31", result["DateList"][1]);
}
示例6: ODataCountTest
public ODataCountTest()
{
IEdmModel model = GetEdmModel();
HttpConfiguration configuration = new[] { typeof(DollarCountEntitiesController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", model);
var server = new HttpServer(configuration);
_client = new HttpClient(server);
}
示例7: ODataFunctionTests
public ODataFunctionTests()
{
DefaultODataPathHandler pathHandler = new DefaultODataPathHandler();
HttpConfiguration configuration =
new[] { typeof(MetadataController), typeof(FCustomersController) }.GetHttpConfiguration();
var model = GetUnTypedEdmModel();
// without attribute routing
configuration.MapODataServiceRoute("odata1", "odata", model, pathHandler, ODataRoutingConventions.CreateDefault());
// only with attribute routing
IList<IODataRoutingConvention> routingConventions = new List<IODataRoutingConvention>
{
new AttributeRoutingConvention(model, configuration)
};
configuration.MapODataServiceRoute("odata2", "attribute", model, pathHandler, routingConventions);
_client = new HttpClient(new HttpServer(configuration));
}
示例8: AGet_Minimial
public void AGet_Minimial()
{
// Arrange
var configuration = new[] { typeof(AccountsController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", GetEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpResponseMessage response = client.GetAsync(_requestRooturl + "Accounts?$expand=PayoutPI&$format=application/json;odata.metadata=minimal").Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
}
示例9: Get_OpenEntityTypeWithOrderbyAndFilter
public void Get_OpenEntityTypeWithOrderbyAndFilter(string uri, int[] customerIds)
{
// Arrange
var configuration = new[] { typeof(SimpleOpenCustomersController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", GetEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri);
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=full"));
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
JObject result = JObject.Parse(response.Content.ReadAsStringAsync().Result);
var resultArray = result["value"] as JArray;
Assert.Equal(2, resultArray.Count);
for (var i = 0; i < customerIds.Length; i++)
Assert.Equal(customerIds[i], resultArray[i]["CustomerId"]);
}
示例10: Get_OpenEntityType_Enum_Collection_Property
public void Get_OpenEntityType_Enum_Collection_Property()
{
// Arrange
const string RequestUri = "http://localhost/odata/UntypedSimpleOpenCustomers(1)";
var configuration = new[] { typeof(UntypedSimpleOpenCustomersController) }.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", "odata", GetUntypedEdmModel());
HttpClient client = new HttpClient(new HttpServer(configuration));
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, RequestUri);
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/json;odata.metadata=full"));
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
JObject result = JObject.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal("http://localhost/odata/$metadata#UntypedSimpleOpenCustomers/$entity", result["@odata.context"]);
Assert.Equal("#Collection(NS.Color)", result["[email protected]"]);
Assert.Equal(new JArray(new[] { "Red", "0" , "Red"}), result["Colors"]);
Assert.Equal("Red", result["Color"]);
}
示例11: GetQueryOptionConfiguration
private static HttpConfiguration GetQueryOptionConfiguration(bool caseInsensitive)
{
HttpConfiguration config = new[] { typeof(ParserExtenstionCustomersController) }.GetHttpConfiguration();
config.EnableCaseInsensitive(caseInsensitive);
config.MapODataServiceRoute("query", "query", GetEdmModel());
return config;
}
示例12: Queryable_UsesRouteModel_ForMultipleModels
public void Queryable_UsesRouteModel_ForMultipleModels()
{
// Model 1 only has Name, Model 2 only has Age
ODataModelBuilder builder1 = ODataModelBuilderMocks.GetModelBuilderMock<ODataModelBuilder>();
var personType1 = builder1.EntityType<FormatterPerson>().Property(p => p.Name);
builder1.EntitySet<FormatterPerson>("People").HasIdLink(p => new Uri("http://link/"), false);
var model1 = builder1.GetEdmModel();
ODataModelBuilder builder2 = ODataModelBuilderMocks.GetModelBuilderMock<ODataModelBuilder>();
builder2.EntityType<FormatterPerson>().Property(p => p.Age);
builder2.EntitySet<FormatterPerson>("People").HasIdLink(p => new Uri("http://link/"), false);
var model2 = builder2.GetEdmModel();
var config = new[] { typeof(PeopleController) }.GetHttpConfiguration();
config.MapODataServiceRoute("OData1", "v1", model1);
config.MapODataServiceRoute("OData2", "v2", model2);
using (HttpServer host = new HttpServer(config))
using (HttpClient client = new HttpClient(host))
{
// Model 1 has the Name property but not the Age property
AssertRespondsWithExpectedStatusCode(client, "http://localhost/v1/People?$orderby=Name", HttpStatusCode.OK);
AssertRespondsWithExpectedStatusCode(client, "http://localhost/v1/People?$orderby=Age", HttpStatusCode.BadRequest);
// Model 2 has the Age property but not the Name property
AssertRespondsWithExpectedStatusCode(client, "http://localhost/v2/People?$orderby=Name", HttpStatusCode.BadRequest);
AssertRespondsWithExpectedStatusCode(client, "http://localhost/v2/People?$orderby=Age", HttpStatusCode.OK);
}
}
示例13: DollarMetadata_Works_WithDerivedOpenComplexType
public void DollarMetadata_Works_WithDerivedOpenComplexType()
{
// Arrange
const string expectMetadata =
@"<?xml version='1.0' encoding='utf-8'?>
<edmx:Edmx Version='4.0' xmlns:edmx='http://docs.oasis-open.org/odata/ns/edmx'>
<edmx:DataServices>
<Schema Namespace='System.Web.OData.Formatter' xmlns='http://docs.oasis-open.org/odata/ns/edm'>
<ComplexType Name='ComplexBaseType'>
<Property Name='BaseProperty' Type='Edm.String' />
</ComplexType>
<ComplexType Name='ComplexDerivedOpenType' BaseType='System.Web.OData.Formatter.ComplexBaseType' OpenType='true'>
<Property Name='DerivedProperty' Type='Edm.String' />
</ComplexType>
</Schema>
<Schema Namespace='Default' xmlns='http://docs.oasis-open.org/odata/ns/edm'>
<EntityContainer Name='Container' />
</Schema>
</edmx:DataServices>
</edmx:Edmx>";
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.ComplexType<ComplexBaseType>();
IEdmModel model = builder.GetEdmModel();
var config = new[] { typeof(MetadataController) }.GetHttpConfiguration();
config.MapODataServiceRoute(model);
HttpServer server = new HttpServer(config);
HttpClient client = new HttpClient(server);
// Act
var response = client.GetAsync("http://localhost/$metadata").Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
Assert.Equal("application/xml", response.Content.Headers.ContentType.MediaType);
Assert.Equal(expectMetadata.Replace("'", "\""), response.Content.ReadAsStringAsync().Result);
}
示例14: DollarMetadata_Works_WithEntityTypeWithEnumKeys
public void DollarMetadata_Works_WithEntityTypeWithEnumKeys()
{
// Arrange
const string expectMetadata =
" <EntityType Name=\"EnumModel\">\r\n" +
" <Key>\r\n" +
" <PropertyRef Name=\"Simple\" />\r\n" +
" </Key>\r\n" +
" <Property Name=\"Simple\" Type=\"NS.SimpleEnum\" Nullable=\"false\" />\r\n" +
" </EntityType>\r\n" +
" <EnumType Name=\"SimpleEnum\" />";
ODataModelBuilder builder = new ODataModelBuilder();
builder.EntityType<EnumModel>().HasKey(e => e.Simple).Namespace = "NS";
builder.EnumType<SimpleEnum>().Namespace = "NS";
IEdmModel model = builder.GetEdmModel();
var config = new[] { typeof(MetadataController) }.GetHttpConfiguration();
config.MapODataServiceRoute(model);
HttpServer server = new HttpServer(config);
HttpClient client = new HttpClient(server);
// Act
var response = client.GetAsync("http://localhost/$metadata").Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
Assert.Equal("application/xml", response.Content.Headers.ContentType.MediaType);
string payload = response.Content.ReadAsStringAsync().Result;
Assert.Contains(expectMetadata, payload);
}
示例15: GetConfiguration
private static HttpConfiguration GetConfiguration(bool caseInsensitive, bool unqualifiedNameCall)
{
IEdmModel model = ODataRoutingModel.GetModel();
HttpConfiguration config = new[]
{
typeof(MetadataController),
typeof(ProductsController),
typeof(RoutingCustomersController),
}.GetHttpConfiguration();
config.EnableCaseInsensitive(caseInsensitive);
config.EnableUnqualifiedNameCall(unqualifiedNameCall);
config.MapODataServiceRoute("odata", "odata", model);
return config;
}