本文整理汇总了C#中System.Collections.GetHttpConfiguration方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.GetHttpConfiguration方法的具体用法?C# System.Collections.GetHttpConfiguration怎么用?C# System.Collections.GetHttpConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections
的用法示例。
在下文中一共展示了System.Collections.GetHttpConfiguration方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ODataCollectionSerializer_SerializeIQueryableOfIEdmEntityObject
public void ODataCollectionSerializer_SerializeIQueryableOfIEdmEntityObject()
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<CollectionSerializerCustomer>("CollectionSerializerCustomers");
IEdmModel model = builder.GetEdmModel();
var controllers = new[] { typeof(CollectionSerializerCustomersController) };
using (HttpConfiguration configuration = controllers.GetHttpConfiguration())
{
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
using (HttpServer host = new HttpServer(configuration))
using (HttpClient client = new HttpClient(host))
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/CollectionSerializerCustomers?$select=ID"))
{
// Act
using (HttpResponseMessage response = client.SendAsync(request).Result)
{
// Assert
response.EnsureSuccessStatusCode();
}
}
}
}
示例2: EnumSerializer_HasMetadataType
public void EnumSerializer_HasMetadataType()
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EnumCustomer>("EnumCustomers");
IEdmModel model = builder.GetEdmModel();
var controllers = new[] { typeof(EnumCustomersController) };
using (HttpConfiguration configuration = controllers.GetHttpConfiguration())
{
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
using (HttpServer host = new HttpServer(configuration))
using (HttpClient client = new HttpClient(host))
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/EnumCustomers"))
{
request.Content = new StringContent(
string.Format(@"{{'@odata.type':'#System.Web.OData.Formatter.EnumCustomer',
'ID':0,'Color':'Green, Blue','Colors':['Red','Red, Blue']}}"));
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
request.Headers.Accept.ParseAdd("application/json;odata.metadata=full");
// Act
using (HttpResponseMessage response = client.SendAsync(request).Result)
{
// Assert
response.EnsureSuccessStatusCode();
dynamic payload = JToken.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal("#System.Web.OData.Formatter.EnumCustomer", payload["@odata.type"].Value);
Assert.Equal("#System.Web.OData.Builder.TestModels.Color", payload["[email protected]"].Value);
Assert.Equal("#Collection(System.Web.OData.Builder.TestModels.Color)", payload["[email protected]"].Value);
}
}
}
}
示例3: RequestProperty_HasCorrectContextUrl
public void RequestProperty_HasCorrectContextUrl()
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EnumCustomer>("EnumCustomers");
IEdmModel model = builder.GetEdmModel();
var controllers = new[] { typeof(EnumCustomersController) };
using (HttpConfiguration configuration = controllers.GetHttpConfiguration())
{
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
using (HttpServer host = new HttpServer(configuration))
using (HttpClient client = new HttpClient(host))
// Act
using (HttpResponseMessage response = client.GetAsync("http://localhost/EnumCustomers(5)/Color").Result)
{
// Assert
response.EnsureSuccessStatusCode();
JObject payload = JObject.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal("http://localhost/$metadata#EnumCustomers(5)/Color", payload.GetValue("@odata.context"));
}
}
}
示例4: EnumTypeRoundTripTest
public void EnumTypeRoundTripTest()
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EnumCustomer>("EnumCustomers");
IEdmModel model = builder.GetEdmModel();
var controllers = new[] { typeof(EnumCustomersController) };
using (HttpConfiguration configuration = controllers.GetHttpConfiguration())
{
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
using (HttpServer host = new HttpServer(configuration))
using (HttpClient client = new HttpClient(host))
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/EnumCustomers"))
{
request.Content = new StringContent(
string.Format(@"{{'@odata.type':'#System.Web.OData.Formatter.EnumCustomer',
'ID':0,'Color':'Green, Blue','Colors':['Red','Red, Blue']}}"));
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
request.Headers.Accept.ParseAdd("application/json");
// Act
using (HttpResponseMessage response = client.SendAsync(request).Result)
{
// Assert
response.EnsureSuccessStatusCode();
var customer = response.Content.ReadAsAsync<JObject>().Result;
Assert.Equal(0, customer["ID"]);
Assert.Equal(Color.Green | Color.Blue, Enum.Parse(typeof(Color), customer["Color"].ToString()));
var colors = customer["Colors"].Select(c => Enum.Parse(typeof(Color), c.ToString()));
Assert.Equal(2, colors.Count());
Assert.Contains(Color.Red, colors);
Assert.Contains(Color.Red | Color.Blue, colors);
}
}
}
}
示例5: RequestCollectionProperty_HasNextPageLine_Count
public void RequestCollectionProperty_HasNextPageLine_Count()
{
// Arrange
const string expect = @"{
""@odata.context"": ""http://localhost/$metadata#Collection(System.Web.OData.Builder.TestModels.Color)"",
""@odata.count"": 3,
""@odata.nextLink"": ""http://localhost/EnumCustomers(5)/Colors?$count=true&$skip=2"",
""value"": [
""Blue"",
""Green""
]
}";
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EnumCustomer>("EnumCustomers");
IEdmModel model = builder.GetEdmModel();
var controllers = new[] { typeof(EnumCustomersController) };
using (HttpConfiguration configuration = controllers.GetHttpConfiguration())
{
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
using (HttpServer host = new HttpServer(configuration))
using (HttpClient client = new HttpClient(host))
// Act
using (HttpResponseMessage response = client.GetAsync("http://localhost/EnumCustomers(5)/Colors?$count=true").Result)
{
// Assert
response.EnsureSuccessStatusCode();
JObject payload = JObject.Parse(response.Content.ReadAsStringAsync().Result);
Assert.Equal(expect, payload.ToString());
}
}
}
示例6: EnumKeySimpleSerializerTest
public void EnumKeySimpleSerializerTest()
{
// Arrange
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.EntitySet<EnumCustomer>("EnumKeyCustomers");
builder.EntityType<EnumCustomer>().HasKey(c => c.Color);
IEdmModel model = builder.GetEdmModel();
var controllers = new[] { typeof(EnumKeyCustomersController) };
HttpConfiguration configuration = controllers.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
HttpServer host = new HttpServer(configuration);
HttpClient client = new HttpClient(host);
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
"http://localhost/EnumKeyCustomers(System.Web.OData.Builder.TestModels.Color'Red')");
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
var customer = response.Content.ReadAsAsync<JObject>().Result;
Assert.Equal(9, customer["ID"]);
Assert.Equal(Color.Red, Enum.Parse(typeof(Color), customer["Color"].ToString()));
var colors = customer["Colors"].Select(c => Enum.Parse(typeof(Color), c.ToString()));
Assert.Equal(2, colors.Count());
Assert.Contains(Color.Blue, colors);
Assert.Contains(Color.Red, colors);
}
示例7: RelatedKeySimpleSerializerTest
[InlineData("KeyCustomers4")] // with [FromODataUriAttribute] int attribute routing
public void RelatedKeySimpleSerializerTest(string entitySet)
{
// Arrange
IEdmModel model = GetKeyCustomerOrderModel();
var controllers = new[]
{
typeof(KeyCustomers1Controller), typeof(KeyCustomers2Controller),
typeof(KeyCustomerOrderController)
};
HttpConfiguration configuration = controllers.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
HttpServer host = new HttpServer(configuration);
HttpClient client = new HttpClient(host);
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete,
"http://localhost/" + entitySet + "(6)/Orders(StringKey='my',DateKey=2016-05-11,GuidKey=46538EC2-E497-4DFE-A039-1C22F0999D6C)/$ref");
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
var customer = response.Content.ReadAsAsync<JObject>().Result;
Assert.Equal("6+my", customer["value"]);
}
示例8: SingleKeySimpleSerializerTest
[InlineData("KeyCustomers4")] // with [FromODataUriAttribute] int attribute routing
public void SingleKeySimpleSerializerTest(string entitySet)
{
// Arrange
IEdmModel model = GetKeyCustomerOrderModel();
var controllers = new[] { typeof(KeyCustomers1Controller), typeof(KeyCustomers2Controller), typeof(KeyCustomerOrderController) };
HttpConfiguration configuration = controllers.GetHttpConfiguration();
configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
HttpServer host = new HttpServer(configuration);
HttpClient client = new HttpClient(host);
// Act
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get,
"http://localhost/" + entitySet + "(5)");
HttpResponseMessage response = client.SendAsync(request).Result;
// Assert
Assert.True(response.IsSuccessStatusCode);
var customer = response.Content.ReadAsAsync<JObject>().Result;
Assert.Equal(5, customer["value"]);
}