[Fixes#1792]Separate XML serializers to Microsoft.AspNet.Mvc.Xml

This commit is contained in:
Kiran Challa 2015-01-13 17:29:27 -08:00
parent bf00f478e5
commit 5c2dc5db11
52 changed files with 634 additions and 235 deletions

43
Mvc.sln
View File

@ -68,8 +68,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AddServicesWebSite", "test\
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FiltersWebSite", "test\WebSites\FiltersWebSite\FiltersWebSite.kproj", "{1976AC4A-FEA4-4587-A158-D9F79736D2B6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "XmlSerializerWebSite", "test\WebSites\XmlSerializerWebSite\XmlSerializerWebSite.kproj", "{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "UrlHelperWebSite", "test\WebSites\UrlHelperWebSite\UrlHelperWebSite.kproj", "{A192E504-2881-41DC-90D1-B7F1DD1134E8}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ApiExplorerWebSite", "test\WebSites\ApiExplorerWebSite\ApiExplorerWebSite.kproj", "{61061528-071E-424E-965A-07BCC2F02672}"
@ -114,6 +112,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ActionResultsWebSite", "tes
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "LoggingWebSite", "test\WebSites\LoggingWebSite\LoggingWebSite.kproj", "{0AD78AB5-D67C-49BC-81B1-0C51BFA82B5E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Xml", "src\Microsoft.AspNet.Mvc.Xml\Microsoft.AspNet.Mvc.Xml.kproj", "{9C632DF0-DC06-410B-95AE-B5423702E84F}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ErrorPageMiddlewareWebSite", "test\WebSites\ErrorPageMiddlewareWebSite\ErrorPageMiddlewareWebSite.kproj", "{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ActionConstraintsWebSite", "test\WebSites\ActionConstraintsWebSite\ActionConstraintsWebSite.kproj", "{AF210F69-9D31-43AF-AC3A-CD366E252218}"
@ -124,6 +124,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ResponseCacheWebSite", "tes
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Common.Test", "test\Microsoft.AspNet.Mvc.Common.Test\Microsoft.AspNet.Mvc.Common.Test.kproj", "{0449D6D2-BE1B-4E29-8E1B-444420802C03}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "XmlFormattersWebSite", "test\WebSites\XmlFormattersWebSite\XmlFormattersWebSite.kproj", "{C3123A70-41C4-4122-AD1C-D35DF8958DD7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -394,16 +396,6 @@ Global
{1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Release|x86.ActiveCfg = Release|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Debug|x86.ActiveCfg = Debug|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Release|Any CPU.Build.0 = Release|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD}.Release|x86.ActiveCfg = Release|Any CPU
{A192E504-2881-41DC-90D1-B7F1DD1134E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A192E504-2881-41DC-90D1-B7F1DD1134E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A192E504-2881-41DC-90D1-B7F1DD1134E8}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -636,6 +628,18 @@ Global
{0AD78AB5-D67C-49BC-81B1-0C51BFA82B5E}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{0AD78AB5-D67C-49BC-81B1-0C51BFA82B5E}.Release|x86.ActiveCfg = Release|Any CPU
{0AD78AB5-D67C-49BC-81B1-0C51BFA82B5E}.Release|x86.Build.0 = Release|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Debug|x86.ActiveCfg = Debug|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Debug|x86.Build.0 = Debug|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Release|Any CPU.Build.0 = Release|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Release|x86.ActiveCfg = Release|Any CPU
{9C632DF0-DC06-410B-95AE-B5423702E84F}.Release|x86.Build.0 = Release|Any CPU
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -696,6 +700,18 @@ Global
{0449D6D2-BE1B-4E29-8E1B-444420802C03}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{0449D6D2-BE1B-4E29-8E1B-444420802C03}.Release|x86.ActiveCfg = Release|Any CPU
{0449D6D2-BE1B-4E29-8E1B-444420802C03}.Release|x86.Build.0 = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|x86.ActiveCfg = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|x86.Build.0 = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Release|Any CPU.Build.0 = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Release|x86.ActiveCfg = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -728,7 +744,6 @@ Global
{A353B17E-A940-4CE8-8BF9-179E24A9041F} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{6A0B65CE-6B01-40D0-840D-EFF3680D1547} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{1976AC4A-FEA4-4587-A158-D9F79736D2B6} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{96107AC0-18E2-474D-BAB4-2FFF2185FBCD} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{A192E504-2881-41DC-90D1-B7F1DD1134E8} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{61061528-071E-424E-965A-07BCC2F02672} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{C6304029-78C8-4604-99BE-2078DCA1DD36} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
@ -751,10 +766,12 @@ Global
{920F8A0E-6F7D-4BBE-84FF-840B89099BE6} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{0A6BB4C0-48D3-4E7F-952B-B8917345E075} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{0AD78AB5-D67C-49BC-81B1-0C51BFA82B5E} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{9C632DF0-DC06-410B-95AE-B5423702E84F} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{AF210F69-9D31-43AF-AC3A-CD366E252218} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{364EC3C6-C9DB-45E0-A0F2-1EE61E4B429B} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{BDEEBE09-C0C4-433C-B0B8-8478C9776996} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{0449D6D2-BE1B-4E29-8E1B-444420802C03} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{C3123A70-41C4-4122-AD1C-D35DF8958DD7} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
EndGlobalSection
EndGlobal

View File

@ -9,6 +9,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -9,6 +9,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -4,9 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding;
@ -16,8 +13,7 @@ namespace Microsoft.AspNet.Mvc
/// Defines a serializable container for storing ModelState information.
/// This information is stored as key/value pairs.
/// </summary>
[XmlRoot("Error")]
public sealed class SerializableError : Dictionary<string, object>, IXmlSerializable
public sealed class SerializableError : Dictionary<string, object>
{
/// <summary>
/// Initializes a new instance of the <see cref="SerializableError"/> class.
@ -55,50 +51,5 @@ namespace Microsoft.AspNet.Mvc
}
}
}
// <inheritdoc />
public XmlSchema GetSchema()
{
return null;
}
// <inheritdoc />
public void ReadXml(XmlReader reader)
{
if (reader.IsEmptyElement)
{
reader.Read();
return;
}
reader.ReadStartElement();
while (reader.NodeType != XmlNodeType.EndElement)
{
var key = XmlConvert.DecodeName(reader.LocalName);
var value = reader.ReadInnerXml();
Add(key, value);
reader.MoveToContent();
}
reader.ReadEndElement();
}
// <inheritdoc />
public void WriteXml(XmlWriter writer)
{
foreach (var keyValuePair in this)
{
var key = keyValuePair.Key;
var value = keyValuePair.Value;
writer.WriteStartElement(XmlConvert.EncodeLocalName(key));
if (value != null)
{
writer.WriteValue(value);
}
writer.WriteEndElement();
}
}
}
}

View File

@ -16,7 +16,6 @@
"aspnet50": {
"frameworkAssemblies": {
"System.ComponentModel.DataAnnotations": "",
"System.Xml": "",
"System.Runtime.Serialization": ""
}
},
@ -26,9 +25,7 @@
"System.ComponentModel.Annotations": "4.0.10-beta-*",
"System.ComponentModel.TypeConverter": "4.0.0-beta-*",
"System.Reflection.TypeExtensions": "4.0.0-beta-*",
"System.Runtime.Serialization.Primitives": "4.0.0-beta-*",
"System.Runtime.Serialization.Xml": "4.0.10-beta-*",
"System.Xml.XmlSerializer": "4.0.10-beta-*"
"System.Runtime.Serialization.Primitives": "4.0.0-beta-*"
}
}
}

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
@ -14,4 +14,9 @@
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
<ProjectExtensions>
<VisualStudio>
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -13,12 +13,16 @@
"frameworks": {
"aspnet50": {
"frameworkAssemblies": {
"System.Net.Http": "4.0.0.0"
"System.Net.Http": "",
"System.Xml": "",
"System.Runtime.Serialization": ""
}
},
"aspnetcore50": {
"dependencies": {
"System.Net.Http": "4.0.0-beta-*"
"System.Net.Http": "4.0.0-beta-*",
"System.Xml.XmlSerializer": "4.0.0-beta-*",
"System.Runtime.Serialization.Xml": "4.0.10-beta-*"
}
}
}

View File

@ -6,10 +6,10 @@ using System.Runtime.Serialization;
#endif
using System.Xml;
namespace Microsoft.AspNet.Mvc
namespace Microsoft.AspNet.Mvc.Xml
{
/// <summary>
/// Contains methods which are used by input formatters.
/// Contains methods which are used by Xml input formatters.
/// </summary>
public static class FormattingUtilities
{

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
using System.Xml;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
namespace Microsoft.AspNet.Mvc.Xml
{
/// <summary>
/// This class handles deserialization of input XML data
@ -106,7 +106,7 @@ namespace Microsoft.AspNet.Mvc
/// <returns>The <see cref="XmlObjectSerializer"/> used during deserialization.</returns>
protected virtual XmlObjectSerializer CreateDataContractSerializer(Type type)
{
return new DataContractSerializer(type);
return new DataContractSerializer(SerializableErrorWrapper.CreateSerializableType(type));
}
private object GetDefaultValueForType(Type modelType)
@ -127,7 +127,9 @@ namespace Microsoft.AspNet.Mvc
using (var xmlReader = CreateXmlReader(new DelegatingStream(request.Body)))
{
var xmlSerializer = CreateDataContractSerializer(type);
return Task.FromResult(xmlSerializer.ReadObject(xmlReader));
var deserializedObject = xmlSerializer.ReadObject(xmlReader);
deserializedObject = SerializableErrorWrapper.UnwrapSerializableErrorObject(type, deserializedObject);
return Task.FromResult(deserializedObject);
}
}
}

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
using System.Xml;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
namespace Microsoft.AspNet.Mvc.Xml
{
/// <summary>
/// This class handles serialization of objects
@ -53,16 +53,16 @@ namespace Microsoft.AspNet.Mvc
/// <returns>The type of the object to be serialized.</returns>
protected virtual Type GetSerializableType(Type declaredType, Type runtimeType)
{
if (declaredType == null ||
declaredType == typeof(object))
Type type = declaredType;
if (declaredType == null || declaredType == typeof(object))
{
if (runtimeType != null)
{
return runtimeType;
type = runtimeType;
}
}
return declaredType;
return SerializableErrorWrapper.CreateSerializableType(type);
}
/// <inheritdoc />
@ -121,7 +121,8 @@ namespace Microsoft.AspNet.Mvc
var type = GetSerializableType(context.DeclaredType, runtimeType);
var dataContractSerializer = CreateSerializer(type);
dataContractSerializer.WriteObject(xmlWriter, context.Object);
var responseObject = SerializableErrorWrapper.WrapSerializableErrorObject(context.Object);
dataContractSerializer.WriteObject(xmlWriter, responseObject);
}
return Task.FromResult(true);

View File

@ -12,7 +12,7 @@ using System.Xml;
using System.Xml.Serialization;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
namespace Microsoft.AspNet.Mvc.Xml
{
/// <summary>
/// This class handles deserialization of input XML data
@ -106,7 +106,7 @@ namespace Microsoft.AspNet.Mvc
/// <returns>The <see cref="XmlSerializer"/> used during deserialization.</returns>
protected virtual XmlSerializer CreateXmlSerializer(Type type)
{
return new XmlSerializer(type);
return new XmlSerializer(SerializableErrorWrapper.CreateSerializableType(type));
}
private object GetDefaultValueForType(Type modelType)
@ -127,7 +127,9 @@ namespace Microsoft.AspNet.Mvc
using (var xmlReader = CreateXmlReader(new DelegatingStream(request.Body)))
{
var xmlSerializer = CreateXmlSerializer(type);
return Task.FromResult(xmlSerializer.Deserialize(xmlReader));
var deserializedObject = xmlSerializer.Deserialize(xmlReader);
deserializedObject = SerializableErrorWrapper.UnwrapSerializableErrorObject(type, deserializedObject);
return Task.FromResult(deserializedObject);
}
}
}

View File

@ -8,7 +8,7 @@ using System.Xml;
using System.Xml.Serialization;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc
namespace Microsoft.AspNet.Mvc.Xml
{
/// <summary>
/// This class handles serialization of objects
@ -53,16 +53,16 @@ namespace Microsoft.AspNet.Mvc
/// <returns>The type of the object to be serialized.</returns>
protected virtual Type GetSerializableType(Type declaredType, Type runtimeType)
{
if (declaredType == null ||
declaredType == typeof(object))
var type = declaredType;
if (declaredType == null || declaredType == typeof(object))
{
if (runtimeType != null)
{
return runtimeType;
type = runtimeType;
}
}
return declaredType;
return SerializableErrorWrapper.CreateSerializableType(type);
}
/// <inheritdoc />
@ -119,7 +119,8 @@ namespace Microsoft.AspNet.Mvc
var type = GetSerializableType(context.DeclaredType, runtimeType);
var xmlSerializer = CreateSerializer(type);
xmlSerializer.Serialize(xmlWriter, context.Object);
var responseObject = SerializableErrorWrapper.WrapSerializableErrorObject(context.Object);
xmlSerializer.Serialize(xmlWriter, responseObject);
}
return Task.FromResult(true);

View File

@ -1,18 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="__ToolsVersion__" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>96107ac0-18e2-474d-bab4-2fff2185fbcd</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<ProjectGuid>9c632df0-dc06-410b-95ae-b5423702e84f</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>49642</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
<ProjectExtensions>
<VisualStudio>
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -1,6 +1,8 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Xml;
namespace Microsoft.AspNet.Mvc
{
public static class MvcOptionsExtensions

View File

@ -0,0 +1,143 @@
using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace Microsoft.AspNet.Mvc.Xml
{
/// <summary>
/// Wrapper class for <see cref="SerializableError"/> to enable it to be serialized by the xml formatters.
/// </summary>
[XmlRoot("Error")]
public sealed class SerializableErrorWrapper : IXmlSerializable
{
// Note: XmlSerializer requires to have default constructor
public SerializableErrorWrapper()
{
SerializableError = new SerializableError();
}
/// <summary>
/// Initializes a new instance of the <see cref="SerializableErrorWrapper"/> class.
/// </summary>
/// <param name="error">The <see cref="SerializableError"/> object that needs to be wrapped.</param>
public SerializableErrorWrapper([NotNull] SerializableError error)
{
SerializableError = error;
}
/// <summary>
/// Gets the wrapped object which is serialized/deserialized into XML
/// representation.
/// </summary>
public SerializableError SerializableError { get; }
/// <inheritdoc />
public XmlSchema GetSchema()
{
return null;
}
/// <summary>
/// Generates a <see cref="SerializableError"/> object from its XML representation.
/// </summary>
/// <param name="reader">The <see cref="XmlReader"/> stream from which the object is deserialized.</param>
public void ReadXml(XmlReader reader)
{
if (reader.IsEmptyElement)
{
reader.Read();
return;
}
reader.ReadStartElement();
while (reader.NodeType != XmlNodeType.EndElement)
{
var key = XmlConvert.DecodeName(reader.LocalName);
var value = reader.ReadInnerXml();
SerializableError.Add(key, value);
reader.MoveToContent();
}
reader.ReadEndElement();
}
/// <summary>
/// Converts the wrapped <see cref="SerializableError"/> object into its XML representation.
/// </summary>
/// <param name="writer">The <see cref="XmlWriter"/> stream to which the object is serialized.</param>
public void WriteXml(XmlWriter writer)
{
foreach (var keyValuePair in SerializableError)
{
var key = keyValuePair.Key;
var value = keyValuePair.Value;
writer.WriteStartElement(XmlConvert.EncodeLocalName(key));
if (value != null)
{
writer.WriteValue(value);
}
writer.WriteEndElement();
}
}
/// <summary>
/// Gets the
/// </summary>
/// <param name="modelType"></param>
/// <param name="deserializedObject"></param>
/// <returns></returns>
public static object UnwrapSerializableErrorObject([NotNull] Type modelType, object deserializedObject)
{
// Since we expect users to typically bind with SerializableError type,
// we should try to unwrap and get the actual SerializableError.
if (modelType == typeof(SerializableError))
{
var serializableErrorWrapper = deserializedObject as SerializableErrorWrapper;
if (serializableErrorWrapper != null)
{
deserializedObject = serializableErrorWrapper.SerializableError;
}
}
return deserializedObject;
}
/// <summary>
/// Checks if an object is an instance of type <see cref="SerializableError"/> and if yes,
/// gets and returns the wrapped <see cref="SerializableErrorWrapper"/> object in it.
/// </summary>
/// <param name="obj">An </param>
/// <returns></returns>
public static object WrapSerializableErrorObject(object obj)
{
var serializableError = obj as SerializableError;
if (serializableError == null)
{
return obj;
}
return new SerializableErrorWrapper(serializableError);
}
/// <summary>
/// Checks if the given type is of type <see cref="SerializableError"/> and if yes, returns
/// the wrapper type <see cref="SerializableErrorWrapper"/>.
/// </summary>
/// <param name="type">The type to be checked</param>
/// <returns><see cref="SerializableErrorWrapper"/> type, else the original type.</returns>
public static Type CreateSerializableType([NotNull] Type type)
{
// Since the type "SerializableError" is not compatible
// with the xml serializers, we create a compatible wrapper type for serialization.
if (type == typeof(SerializableError))
{
type = typeof(SerializableErrorWrapper);
}
return type;
}
}
}

View File

@ -0,0 +1,25 @@
{
"description": "Contains DataContractSerializer and XmlSerializer based input and output formatters",
"version": "6.0.0-*",
"compilationOptions": {
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.AspNet.Mvc.Common": { "version": "6.0.0-*", "type": "build" },
"Microsoft.AspNet.Mvc.Core": "6.0.0-*"
},
"frameworks": {
"aspnet50": {
"frameworkAssemblies": {
"System.Xml": "",
"System.Runtime.Serialization": ""
}
},
"aspnetcore50": {
"dependencies": {
"System.Runtime.Serialization.Xml": "4.0.10-beta-*",
"System.Xml.XmlSerializer": "4.0.10-beta-*"
}
}
}
}

View File

@ -9,6 +9,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;

View File

@ -7,6 +7,7 @@ using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Xml;
using Xunit;
namespace Microsoft.AspNet.Mvc
@ -87,60 +88,5 @@ namespace Microsoft.AspNet.Mvc
// Assert
Assert.Equal(0, serializableError.Count);
}
[Fact]
public void GetSchema_Returns_Null()
{
// Arrange
var modelState = new ModelStateDictionary();
// To make modelState invalid.
modelState.AddModelError("key1", "Test Error 1");
var serializableError = new SerializableError(modelState);
// Act & Assert
Assert.Null(serializableError.GetSchema());
}
[Fact]
public void WriteXml_WritesValidXml()
{
// Arrange
var modelState = new ModelStateDictionary();
modelState.AddModelError("key1", "Test Error 1");
modelState.AddModelError("key1", "Test Error 2");
modelState.AddModelError("key2", "Test Error 3");
var serializableError = new SerializableError(modelState);
var outputStream = new MemoryStream();
// Act
using (var xmlWriter = XmlWriter.Create(outputStream))
{
var dataContractSerializer = new DataContractSerializer(typeof(SerializableError));
dataContractSerializer.WriteObject(xmlWriter, serializableError);
}
outputStream.Position = 0;
var res = new StreamReader(outputStream, Encoding.UTF8).ReadToEnd();
// Assert
Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Error><key1>Test Error 1 Test Error 2</key1><key2>Test Error 3</key2></Error>", res);
}
[Fact]
public void ReadXml_ReadsSerializableErrorXml()
{
// Arrange
var serializableErrorXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Error><key1>Test Error 1 Test Error 2</key1><key2>Test Error 3</key2></Error>";
var serializer = new DataContractSerializer(typeof(SerializableError));
// Act
var errors = (SerializableError)serializer.ReadObject(
new MemoryStream(Encoding.UTF8.GetBytes(serializableErrorXml)));
// Assert
Assert.Equal("Test Error 1 Test Error 2", errors["key1"]);
Assert.Equal("Test Error 3", errors["key2"]);
}
}
}

View File

@ -11,6 +11,7 @@ using System.Threading.Tasks;
using System.Xml;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Testing;
using Moq;
using Xunit;
@ -338,6 +339,26 @@ namespace Microsoft.AspNet.Mvc
Assert.Equal(expectedString, levelOneModel.sampleString);
}
[Fact]
public async Task ReadsSerializableErrorXml()
{
// Arrange
var serializableErrorXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Error><key1>Test Error 1 Test Error 2</key1><key2>Test Error 3</key2></Error>";
var formatter = new XmlDataContractSerializerInputFormatter();
var contentBytes = Encodings.UTF8EncodingWithoutBOM.GetBytes(serializableErrorXml);
var context = GetInputFormatterContext(contentBytes, typeof(SerializableError));
// Act
var model = await formatter.ReadAsync(context);
// Assert
var serializableError = model as SerializableError;
Assert.NotNull(serializableError);
Assert.Equal("Test Error 1 Test Error 2", serializableError["key1"]);
Assert.Equal("Test Error 3", serializableError["key2"]);
}
private InputFormatterContext GetInputFormatterContext(byte[] contentBytes, Type modelType)
{
var actionContext = GetActionContext(contentBytes);

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.Net.Http.Headers;
using Microsoft.AspNet.Mvc.Xml;
using Moq;
using Xunit;
@ -273,7 +274,6 @@ namespace Microsoft.AspNet.Mvc.Core
// Act & Assert
await formatter.WriteAsync(outputFormatterContext);
}
public static IEnumerable<object[]> TypesForCanWriteResult
{
get

View File

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using System.Xml;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Testing;
using Moq;
using Xunit;
@ -345,6 +346,26 @@ namespace Microsoft.AspNet.Mvc
Assert.Equal(XmlConvert.ToDateTime(expectedDateTime, XmlDateTimeSerializationMode.Utc), levelOneModel.SampleDate);
}
[Fact]
public async Task ReadsSerializableErrorXml()
{
// Arrange
var serializableErrorXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Error><key1>Test Error 1 Test Error 2</key1><key2>Test Error 3</key2></Error>";
var formatter = new XmlSerializerInputFormatter();
var contentBytes = Encodings.UTF8EncodingWithoutBOM.GetBytes(serializableErrorXml);
var context = GetInputFormatterContext(contentBytes, typeof(SerializableError));
// Act
var model = await formatter.ReadAsync(context);
// Assert
var serializableError = model as SerializableError;
Assert.NotNull(serializableError);
Assert.Equal("Test Error 1 Test Error 2", serializableError["key1"]);
Assert.Equal("Test Error 3", serializableError["key2"]);
}
private InputFormatterContext GetInputFormatterContext(byte[] contentBytes, Type modelType)
{
var actionContext = GetActionContext(contentBytes);

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.Net.Http.Headers;
using Microsoft.AspNet.Mvc.Xml;
using Moq;
using Xunit;
@ -242,7 +243,7 @@ namespace Microsoft.AspNet.Mvc.Core
Assert.NotNull(outputFormatterContext.ActionContext.HttpContext.Response.Body);
Assert.True(outputFormatterContext.ActionContext.HttpContext.Response.Body.CanRead);
}
public static IEnumerable<object[]> TypesForCanWriteResult
{
get

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Http.Core;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.OptionsModel;

View File

@ -0,0 +1,99 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Xml;
using Xunit;
namespace Microsoft.AspNet.Mvc
{
public class SerializableErrorWrapperTests
{
[Fact]
public void DefaultConstructor_CreatesSerializableError()
{
// Arrange and Act
var wrapper = new SerializableErrorWrapper();
// Assert
Assert.NotNull(wrapper.SerializableError);
Assert.Empty(wrapper.SerializableError);
}
[Fact]
public void WrappedSerializableErrorInstance_ReturnedFromProperty()
{
// Arrange
var serializableError = new SerializableError();
serializableError.Add("key1", "key1-error");
// Act
var wrapper = new SerializableErrorWrapper(serializableError);
// Assert
Assert.NotNull(wrapper.SerializableError);
Assert.Same(serializableError, wrapper.SerializableError);
Assert.Equal(1, wrapper.SerializableError.Count);
Assert.True(wrapper.SerializableError.ContainsKey("key1"));
Assert.Equal("key1-error", wrapper.SerializableError["key1"]);
}
[Fact]
public void GetSchema_Returns_Null()
{
// Arrange
var serializableError = new SerializableErrorWrapper(new SerializableError(new ModelStateDictionary()));
// Act & Assert
Assert.Null(serializableError.GetSchema());
}
[Fact]
public void ReadXml_ReadsSerializableErrorXml()
{
// Arrange
var serializableErrorXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Error><key1>Test Error 1 Test Error 2</key1><key2>Test Error 3</key2></Error>";
var serializer = new DataContractSerializer(typeof(SerializableErrorWrapper));
// Act
var wrapper = (SerializableErrorWrapper)serializer.ReadObject(
new MemoryStream(Encoding.UTF8.GetBytes(serializableErrorXml)));
var errors = wrapper.SerializableError;
// Assert
Assert.Equal("Test Error 1 Test Error 2", errors["key1"]);
Assert.Equal("Test Error 3", errors["key2"]);
}
[Fact]
public void WriteXml_WritesValidXml()
{
// Arrange
var modelState = new ModelStateDictionary();
modelState.AddModelError("key1", "Test Error 1");
modelState.AddModelError("key1", "Test Error 2");
modelState.AddModelError("key2", "Test Error 3");
var serializableError = new SerializableError(modelState);
var outputStream = new MemoryStream();
// Act
using (var xmlWriter = XmlWriter.Create(outputStream))
{
var dataContractSerializer = new DataContractSerializer(typeof(SerializableErrorWrapper));
dataContractSerializer.WriteObject(xmlWriter, new SerializableErrorWrapper(serializableError));
}
outputStream.Position = 0;
var res = new StreamReader(outputStream, Encoding.UTF8).ReadToEnd();
// Assert
Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<Error><key1>Test Error 1 Test Error 2</key1><key2>Test Error 3</key2></Error>", res);
}
}
}

View File

@ -4,6 +4,7 @@
},
"dependencies": {
"Microsoft.AspNet.Mvc" : "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml" : "6.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"Moq": "4.2.1312.1622",
"xunit.runner.kre": "1.0.0-*"

View File

@ -248,38 +248,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
await response.Content.ReadAsStringAsync());
}
[Fact]
public async Task SerializableError_ReadTheReturnedXml()
{
// Arrange
var server = TestServer.Create(_provider, _app);
var client = server.CreateClient();
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<DummyClass xmlns=\"http://schemas.datacontract.org/2004/07/ActionResultsWebSite\">" +
"<SampleInt>20</SampleInt><SampleString>foo</SampleString></DummyClass>";
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Home/Index");
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
request.Content = new StringContent(input, Encoding.UTF8, "application/xml");
// Act
var response = await client.SendAsync(request);
var responseContent = await response.Content.ReadAsStringAsync();
// Deserializing Xml content
var serializer = new XmlSerializer(typeof(SerializableError));
var errors = (SerializableError)serializer.Deserialize(
new MemoryStream(Encoding.UTF8.GetBytes(responseContent)));
// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
Assert.Equal(
"<Error><test.SampleString>" + sampleStringError + "</test.SampleString></Error>",
responseContent);
Assert.Equal(sampleStringError, errors["test.SampleString"]);
}
[Fact]
public async Task ContentResult_WritesContent_SetsDefaultContentTypeAndEncoding()
{

View File

@ -7,6 +7,7 @@ using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc.Description;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.TestHost;
using Newtonsoft.Json;
using Xunit;
@ -697,7 +698,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
}
[Theory]
[InlineData("Controller", "text/xml", "Microsoft.AspNet.Mvc.XmlDataContractSerializerOutputFormatter")]
[InlineData("Controller", "text/xml", "Microsoft.AspNet.Mvc.Xml.XmlDataContractSerializerOutputFormatter")]
[InlineData("Action", "application/json", "Microsoft.AspNet.Mvc.JsonOutputFormatter")]
public async Task ApiExplorer_ResponseContentType_OverrideOnAction(
string action,

View File

@ -0,0 +1,68 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.TestHost;
using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class SerializableErrorTests
{
private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite));
private readonly Action<IApplicationBuilder> _app = new XmlFormattersWebSite.Startup().Configure;
[Theory]
[InlineData("application/xml-xmlser")]
[InlineData("application/xml-dcs")]
public async Task ModelStateErrors_AreSerialized(string acceptHeader)
{
// Arrange
var server = TestServer.Create(_services, _app);
var client = server.CreateClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
var expectedXml = "<Error><key1>key1-error</key1><key2>The input was not valid.</key2></Error>";
// Act
var response = await client.GetAsync("http://localhost/SerializableError/ModelStateErrors");
//Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal(acceptHeader, response.Content.Headers.ContentType.MediaType);
var responseData = await response.Content.ReadAsStringAsync();
Assert.Equal(expectedXml, responseData);
}
[Theory]
[InlineData("application/xml-xmlser")]
[InlineData("application/xml-dcs")]
public async Task PostedSerializableError_IsBound(string acceptHeader)
{
// Arrange
var server = TestServer.Create(_services, _app);
var client = server.CreateClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptHeader));
var expectedXml = "<Error><key1>key1-error</key1><key2>The input was not valid.</key2></Error>";
var requestContent = new StringContent(expectedXml, Encoding.UTF8, acceptHeader);
// Act
var response = await client.PostAsync("http://localhost/SerializableError/LogErrors", requestContent);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.NotNull(response.Content);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal(acceptHeader, response.Content.Headers.ContentType.MediaType);
var responseData = await response.Content.ReadAsStringAsync();
Assert.Equal(expectedXml, responseData);
}
}
}

View File

@ -14,8 +14,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class XmlSerializerInputFormatterTests
{
private readonly IServiceProvider _services = TestHelper.CreateServices("XmlSerializerWebSite");
private readonly Action<IApplicationBuilder> _app = new XmlSerializerWebSite.Startup().Configure;
private readonly IServiceProvider _services = TestHelper.CreateServices(nameof(XmlFormattersWebSite));
private readonly Action<IApplicationBuilder> _app = new XmlFormattersWebSite.Startup().Configure;
[Fact]
public async Task CheckIfXmlSerializerInputFormatterIsCalled()
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<DummyClass><SampleInt>"
+ sampleInputInt.ToString() + "</SampleInt></DummyClass>";
var content = new StringContent(input, Encoding.UTF8, "application/xml");
var content = new StringContent(input, Encoding.UTF8, "application/xml-xmlser");
// Act
var response = await client.PostAsync("http://localhost/Home/Index", content);
@ -46,9 +46,9 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
var sampleInputInt = 10;
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<DummyClas xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"i:type=\"DerivedDummyClass\" xmlns=\"http://schemas.datacontract.org/2004/07/XmlSerializerWebSite\">" +
"i:type=\"DerivedDummyClass\" xmlns=\"http://schemas.datacontract.org/2004/07/XmlFormattersWebSite\">" +
"<SampleInt>" + sampleInputInt.ToString() + "</SampleInt></DummyClass>";
var content = new StringContent(input, Encoding.UTF8, "application/xml");
var content = new StringContent(input, Encoding.UTF8, "application/xml-xmlser");
// Act
var response = await client.PostAsync("http://localhost/Home/Index", content);

View File

@ -35,7 +35,7 @@
"ValueProvidersWebSite": "1.0.0",
"VersioningWebSite": "1.0.0",
"ViewComponentWebSite": "1.0.0",
"XmlSerializerWebSite": "1.0.0",
"XmlFormattersWebSite": "1.0.0",
"WebApiCompatShimWebSite": "1.0.0",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
namespace ActionResultsWebSite
{

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -3,6 +3,7 @@
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
namespace FiltersWebSite
{

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
namespace FiltersWebSite
{

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
namespace FormatterWebSite
{

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
namespace FormatterWebSite
{

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -3,7 +3,7 @@
using Microsoft.AspNet.Mvc;
namespace XmlSerializerWebSite
namespace XmlFormattersWebSite
{
public class HomeController : Controller
{

View File

@ -0,0 +1,37 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc;
namespace XmlFormattersWebSite.Controllers
{
public class SerializableErrorController : Controller
{
[HttpGet]
public IActionResult ModelStateErrors()
{
InvalidOperationException exception = null;
try
{
throw new InvalidOperationException("Error in executing the action");
}
catch (InvalidOperationException invalidOperationEx)
{
exception = invalidOperationEx;
}
ModelState.AddModelError("key1", "key1-error");
ModelState.AddModelError("key2", exception);
return new ObjectResult(new SerializableError(ModelState));
}
[HttpPost]
public SerializableError LogErrors([FromBody] SerializableError serializableError)
{
return serializableError;
}
}
}

View File

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace XmlSerializerWebSite
namespace XmlFormattersWebSite
{
public class DummyClass
{

View File

@ -0,0 +1,78 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Xml;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Net.Http.Headers;
namespace XmlFormattersWebSite
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
var configuration = app.GetTestConfiguration();
// Set up application services
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);
services.Configure<MvcOptions>(options =>
{
options.InputFormatters.Clear();
options.OutputFormatters.Clear();
// Since both XmlSerializer and DataContractSerializer based formatters
// have supported media types of 'application/xml' and 'text/xml', it
// would be difficult for a test to choose a particular formatter based on
// request information (Ex: Accept header).
// So here we instead clear out the default supported media types and create new
// ones which are distinguishable between formatters.
var xmlSerializerInputFormatter = new XmlSerializerInputFormatter();
xmlSerializerInputFormatter.SupportedMediaTypes.Clear();
xmlSerializerInputFormatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/xml-xmlser"));
xmlSerializerInputFormatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("text/xml-xmlser"));
var xmlSerializerOutputFormatter = new XmlSerializerOutputFormatter();
xmlSerializerOutputFormatter.SupportedMediaTypes.Clear();
xmlSerializerOutputFormatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/xml-xmlser"));
xmlSerializerOutputFormatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("text/xml-xmlser"));
var dcsInputFormatter = new XmlDataContractSerializerInputFormatter();
dcsInputFormatter.SupportedMediaTypes.Clear();
dcsInputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml-dcs"));
dcsInputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml-dcs"));
var dcsOutputFormatter = new XmlDataContractSerializerOutputFormatter();
dcsOutputFormatter.SupportedMediaTypes.Clear();
dcsOutputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml-dcs"));
dcsOutputFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/xml-dcs"));
options.InputFormatters.Add(dcsInputFormatter);
options.InputFormatters.Add(xmlSerializerInputFormatter);
options.OutputFormatters.Add(dcsOutputFormatter);
options.OutputFormatters.Add(xmlSerializerOutputFormatter);
});
});
app.UseErrorReporter();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute("ActionAsMethod", "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
}

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="__ToolsVersion__" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>c3123a70-41c4-4122-ad1c-d35df8958dd7</ProjectGuid>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration">
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>46481</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" />
<ProjectExtensions>
<VisualStudio>
<UserProperties project_1json__JSONSchema="http://www.asp.net/media/4878834/project.json" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -6,6 +6,7 @@
"dependencies": {
"Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.IIS": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",

View File

@ -1,41 +0,0 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection;
namespace XmlSerializerWebSite
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
var configuration = app.GetTestConfiguration();
// Set up application services
app.UseServices(services =>
{
// Add MVC services to the services container
services.AddMvc(configuration);
services.Configure<MvcOptions>(options =>
{
options.InputFormatters.Clear();
options.InputFormatters.Insert(0, new XmlSerializerInputFormatter());
});
});
app.UseErrorReporter();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute("ActionAsMethod", "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
}