当前位置: 首页>>代码示例>>C#>>正文


C# System.Collections.GetHttpConfiguration方法代码示例

本文整理汇总了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();
                    }
                }
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataFormatterTests.cs

示例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);
                    }
                }
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:34,代码来源:ODataFormatterTests.cs

示例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"));
                }
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:24,代码来源:ODataFormatterTests.cs

示例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);
                    }
                }
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:37,代码来源:ODataFormatterTests.cs

示例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());
                }
            }
        }
开发者ID:xuanvufs,项目名称:WebApi,代码行数:33,代码来源:ODataFormatterTests.cs

示例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);
        }
开发者ID:xuanvufs,项目名称:WebApi,代码行数:29,代码来源:ODataFormatterTests.cs

示例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"]);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:26,代码来源:ODataFormatterTests.cs

示例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"]);
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:22,代码来源:ODataFormatterTests.cs


注:本文中的System.Collections.GetHttpConfiguration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。