Revive call to FormattingUtilities in XmlDataContractSerializerOutputFormatter

Fixes #6235
This commit is contained in:
Pranav K 2017-07-06 17:50:02 -07:00
parent 05f5d59e44
commit fc106ab793
3 changed files with 13 additions and 13 deletions

View File

@ -132,7 +132,9 @@ namespace Microsoft.AspNetCore.Mvc.Formatters
try try
{ {
// Use FormattingUtilities here when https://github.com/aspnet/Mvc/issues/6235 is resolved. // Verify that type is a valid data contract by forcing the serializer to try to create a data contract
FormattingUtilities.XsdDataContractExporter.GetRootElementName(type);
// If the serializer does not support this type it will throw an exception. // If the serializer does not support this type it will throw an exception.
return new DataContractSerializer(type, _serializerSettings); return new DataContractSerializer(type, _serializerSettings);
} }

View File

@ -1,8 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Formatters;
@ -10,8 +11,6 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Testing.xunit; using Microsoft.AspNetCore.Testing.xunit;
using Newtonsoft.Json; using Newtonsoft.Json;
using Xunit; using Xunit;
using Microsoft.AspNetCore.Http;
using System.Net;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
@ -571,7 +570,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
// Arrange // Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName; var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName; var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" }; var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" };
// Act // Act
@ -603,7 +602,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
// Arrange // Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName; var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName; var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "text/xml" }; var expectedMediaTypes = new[] { "text/xml" };
// Act // Act
@ -635,7 +634,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
// Arrange // Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName; var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName; var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" }; var expectedMediaTypes = new[] { "application/json", "text/json", "application/xml", "text/xml" };
// Act // Act
@ -667,7 +666,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
// Arrange // Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName; var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName; var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "text/xml" }; var expectedMediaTypes = new[] { "text/xml" };
// Act // Act

View File

@ -3,7 +3,6 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
namespace ApiExplorerWebSite namespace ApiExplorerWebSite
{ {
@ -58,7 +57,7 @@ namespace ApiExplorerWebSite
} }
[ProducesResponseType(typeof(Product), 201)] [ProducesResponseType(typeof(Product), 201)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)] [ProducesResponseType(typeof(SerializableError), 400)]
public Product CreateProductWithDefaultResponseContentTypes(Product product) public Product CreateProductWithDefaultResponseContentTypes(Product product)
{ {
return null; return null;
@ -66,21 +65,21 @@ namespace ApiExplorerWebSite
[Produces("text/xml")] // Has status code as 200 but is not applied as it does not set 'Type' [Produces("text/xml")] // Has status code as 200 but is not applied as it does not set 'Type'
[ProducesResponseType(typeof(Product), 201)] [ProducesResponseType(typeof(Product), 201)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)] [ProducesResponseType(typeof(SerializableError), 400)]
public Product CreateProductWithLimitedResponseContentTypes(Product product) public Product CreateProductWithLimitedResponseContentTypes(Product product)
{ {
return null; return null;
} }
[ProducesResponseType(typeof(Product), 200)] [ProducesResponseType(typeof(Product), 200)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)] [ProducesResponseType(typeof(SerializableError), 400)]
public Product UpdateProductWithDefaultResponseContentTypes(Product product) public Product UpdateProductWithDefaultResponseContentTypes(Product product)
{ {
return null; return null;
} }
[Produces("text/xml", Type = typeof(Product))] // Has status code as 200 [Produces("text/xml", Type = typeof(Product))] // Has status code as 200
[ProducesResponseType(typeof(ModelStateDictionary), 400)] [ProducesResponseType(typeof(SerializableError), 400)]
public Product UpdateProductWithLimitedResponseContentTypes(Product product) public Product UpdateProductWithLimitedResponseContentTypes(Product product)
{ {
return null; return null;