本文整理汇总了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);
}
示例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'.");
}
示例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.");
}
示例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());
}
示例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);
}
}
}
示例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);
}