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


C# HttpConfiguration.AddFakeODataRoute方法代码示例

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

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

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


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