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


C# HttpConfiguration.SetODataFormatter方法代码示例

本文整理汇总了C#中HttpConfiguration.SetODataFormatter方法的典型用法代码示例。如果您正苦于以下问题:C# HttpConfiguration.SetODataFormatter方法的具体用法?C# HttpConfiguration.SetODataFormatter怎么用?C# HttpConfiguration.SetODataFormatter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpConfiguration的用法示例。


在下文中一共展示了HttpConfiguration.SetODataFormatter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetODataFormatter_AddsFormatterToTheFormatterCollection

        public void SetODataFormatter_AddsFormatterToTheFormatterCollection()
        {
            // Arrange
            HttpConfiguration configuration = new HttpConfiguration();
            ODataMediaTypeFormatter formatter = new Mock<ODataMediaTypeFormatter>().Object;

            // Act
            configuration.SetODataFormatter(formatter);

            // Assert
            Assert.Contains(formatter, configuration.Formatters);
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:12,代码来源:HttpConfigurationExtensionTests.cs

示例2: SetEdmModel_WithADifferentModel_AfterSettingFormatter_Throws

        public void SetEdmModel_WithADifferentModel_AfterSettingFormatter_Throws()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();
            IEdmModel model = new Mock<IEdmModel>().Object;
            config.SetODataFormatter(new ODataMediaTypeFormatter());

            // Act
            Assert.Throws<NotSupportedException>(
                () => config.SetEdmModel(model),
                "The given 'IEdmModel' does not match the 'IEdmModel' in the formatter on the configuration. Setting 'ODataMediaTypeFormatter' using the method 'SetODataFormatter' also sets the corresponding 'IEdmModel'.");
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:12,代码来源:HttpConfigurationExtensionTests.cs

示例3: SetODataFormatter_Throws_FormatterAlreadyInTheCollection

        public void SetODataFormatter_Throws_FormatterAlreadyInTheCollection()
        {
            // Arrange
            HttpConfiguration configuration = new HttpConfiguration();
            ODataMediaTypeFormatter formatter = new Mock<ODataMediaTypeFormatter>().Object;
            configuration.Formatters.Add(formatter);

            // Act & Assert
            Assert.Throws<NotSupportedException>(
                () => configuration.SetODataFormatter(formatter),
                "You already have a ODataMediaTypeFormatter on your HttpConfiguration. Set your ODataMediaTypeFormatter once using the 'SetODataFormatter' method on 'HttpConfiguration' only.");

        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:13,代码来源:HttpConfigurationExtensionTests.cs

示例4: GetMetadata_Returns_EdmModelFromSetODataFormatter

        public void GetMetadata_Returns_EdmModelFromSetODataFormatter()
        {
            IEdmModel model = new EdmModel();
            ODataMediaTypeFormatter oDataFormatter = new ODataMediaTypeFormatter(model);
            HttpConfiguration configuration = new HttpConfiguration();
            configuration.SetODataFormatter(oDataFormatter);

            ODataMetadataController controller = new ODataMetadataController();
            controller.Request = new HttpRequestMessage();
            controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;

            Assert.Equal(
                model,
                controller.GetMetadata());
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:15,代码来源:ODataMetaDataControllerTests.cs

示例5: PostEntry_InODataAtomFormat

        public void PostEntry_InODataAtomFormat()
        {
            var _config = new HttpConfiguration();
            _config.Routes.MapHttpRoute(ODataRouteNames.GetById, "{controller}({id})");
            _config.Routes.MapHttpRoute(ODataRouteNames.Default, "{controller}");
            _config.SetODataFormatter(new ODataMediaTypeFormatter(ODataTestUtil.GetEdmModel()));

            using (HttpServer host = new HttpServer(_config))
            {
                var _client = new HttpClient(host);
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(baseAddress + "People"));
                requestMessage.Content = new StringContent(BaselineResource.EntryTypePersonAtom, Encoding.UTF8, "application/atom+xml");
                using (HttpResponseMessage response = _client.SendAsync(requestMessage).Result)
                {
                    Assert.NotNull(response);
                    Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                    Assert.Equal("application/atom+xml", response.Content.Headers.ContentType.MediaType);

                    ODataTestUtil.VerifyResponse(response.Content, BaselineResource.EntryTypePersonAtom);
                }
            }
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:22,代码来源:PartialTrustTest.cs

示例6: GetODataFormatter_Returns_SetODataFormatter

        public void GetODataFormatter_Returns_SetODataFormatter()
        {
            // Arrange
            HttpConfiguration configuration = new HttpConfiguration();
            ODataMediaTypeFormatter formatter = new Mock<ODataMediaTypeFormatter>().Object;
            configuration.SetODataFormatter(formatter);

            // Act
            ODataMediaTypeFormatter result = configuration.GetODataFormatter();

            // Assert
            Assert.Equal(formatter, result);
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:13,代码来源:HttpConfigurationExtensionTests.cs


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