Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Revive call to FormattingUtilities in XmlDataContractSerializerOutputFormatter #6511

Merged
merged 1 commit into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ protected virtual DataContractSerializer CreateSerializer(Type type)

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.
return new DataContractSerializer(type, _serializerSettings);
}
Expand Down
13 changes: 6 additions & 7 deletions test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApiExplorerTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// 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.

using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Testing.xunit;
using Newtonsoft.Json;
using Xunit;
using Microsoft.AspNetCore.Http;
using System.Net;

namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{
Expand Down Expand Up @@ -571,7 +570,7 @@ public async Task ExplicitResponseTypeDecoration_SuppressesDefaultStatus()
{
// Arrange
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" };

// Act
Expand Down Expand Up @@ -603,7 +602,7 @@ public async Task ExplicitResponseTypeDecoration_SuppressesDefaultStatus_AlsoHon
{
// Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName;
var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "text/xml" };

// Act
Expand Down Expand Up @@ -635,7 +634,7 @@ public async Task ExplicitResponseTypeDecoration_WithExplicitDefaultStatus()
{
// Arrange
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" };

// Act
Expand Down Expand Up @@ -667,7 +666,7 @@ public async Task ExplicitResponseTypeDecoration_WithExplicitDefaultStatus_Speci
{
// Arrange
var type1 = typeof(ApiExplorerWebSite.Product).FullName;
var type2 = typeof(ModelStateDictionary).FullName;
var type2 = typeof(SerializableError).FullName;
var expectedMediaTypes = new[] { "text/xml" };

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace ApiExplorerWebSite
{
Expand Down Expand Up @@ -58,29 +57,29 @@ public Product GetProduct()
}

[ProducesResponseType(typeof(Product), 201)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product CreateProductWithDefaultResponseContentTypes(Product product)
{
return null;
}

[Produces("text/xml")] // Has status code as 200 but is not applied as it does not set 'Type'
[ProducesResponseType(typeof(Product), 201)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product CreateProductWithLimitedResponseContentTypes(Product product)
{
return null;
}

[ProducesResponseType(typeof(Product), 200)]
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product UpdateProductWithDefaultResponseContentTypes(Product product)
{
return null;
}

[Produces("text/xml", Type = typeof(Product))] // Has status code as 200
[ProducesResponseType(typeof(ModelStateDictionary), 400)]
[ProducesResponseType(typeof(SerializableError), 400)]
public Product UpdateProductWithLimitedResponseContentTypes(Product product)
{
return null;
Expand Down