diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlOutputFormatterTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlOutputFormatterTests.cs
index 6b3b368ecb..2708fc1b11 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlOutputFormatterTests.cs
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/XmlOutputFormatterTests.cs
@@ -2,10 +2,10 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
-using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
+using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.TestHost;
@@ -29,10 +29,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Arrange
var server = TestServer.Create(_services, _app);
var client = server.CreateClient();
-
- // Act
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Home/GetDummyClass?sampleInput=10");
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
+
+ // Act
var response = await client.SendAsync(request);
//Assert
@@ -49,10 +49,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Arrange
var server = TestServer.Create(_services, _app);
var client = server.CreateClient();
-
- // Act
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/XmlSerializer/GetDummyClass?sampleInput=10");
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
+
+ // Act
var response = await client.SendAsync(request);
//Assert
@@ -68,11 +68,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Arrange
var server = TestServer.Create(_services, _app);
var client = server.CreateClient();
-
- // Act
var request = new HttpRequestMessage(HttpMethod.Post,
"http://localhost/DataContractSerializer/GetPerson?name=HelloWorld");
request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
+
+ // Act
var response = await client.SendAsync(request);
//Assert
@@ -82,5 +82,64 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
"HelloWorld",
await response.Content.ReadAsStringAsync());
}
+
+ [Fact]
+ public async Task XmlSerializerOutputFormatter_WhenDerivedClassIsReturned()
+ {
+ // Arrange
+ var server = TestServer.Create(_services, _app);
+ var client = server.CreateClient();
+ var request = new HttpRequestMessage(
+ HttpMethod.Post, "http://localhost/XmlSerializer/GetDerivedDummyClass?sampleInput=10");
+ request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
+
+ // Act
+ var response = await client.SendAsync(request);
+
+ //Assert
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+ Assert.Equal("" +
+ "1050",
+ await response.Content.ReadAsStringAsync());
+ }
+
+ [Fact]
+ public async Task XmlDataContractSerializerOutputFormatter_WhenDerivedClassIsReturned()
+ {
+ // Arrange
+ var server = TestServer.Create(_services, _app);
+ var client = server.CreateClient();
+ var request = new HttpRequestMessage(
+ HttpMethod.Post, "http://localhost/Home/GetDerivedDummyClass?sampleInput=10");
+ request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
+
+ // Act
+ var response = await client.SendAsync(request);
+
+ //Assert
+ Assert.Equal(HttpStatusCode.OK, response.StatusCode);
+ Assert.Equal("1050",
+ await response.Content.ReadAsStringAsync());
+ }
+
+ [Fact]
+ public async Task XmlSerializerFormatter_DoesNotWriteDictionaryObjects()
+ {
+ // Arrange
+ var server = TestServer.Create(_services, _app);
+ var client = server.CreateClient();
+ var request = new HttpRequestMessage(
+ HttpMethod.Post, "http://localhost/XmlSerializer/GetDictionary");
+ request.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse("application/xml;charset=utf-8"));
+
+ // Act
+ var response = await client.SendAsync(request);
+
+ //Assert
+ Assert.Equal(HttpStatusCode.NotAcceptable, response.StatusCode);
+ }
}
}
\ No newline at end of file
diff --git a/test/WebSites/FormatterWebSite/Controllers/HomeController.cs b/test/WebSites/FormatterWebSite/Controllers/HomeController.cs
index a15ed3820f..ad669bdabc 100644
--- a/test/WebSites/FormatterWebSite/Controllers/HomeController.cs
+++ b/test/WebSites/FormatterWebSite/Controllers/HomeController.cs
@@ -24,5 +24,15 @@ namespace FormatterWebSite.Controllers
{
return dummy != null;
}
+
+ [HttpPost]
+ public DummyClass GetDerivedDummyClass(int sampleInput)
+ {
+ return new DerivedDummyClass
+ {
+ SampleInt = sampleInput,
+ SampleIntInDerived = 50
+ };
+ }
}
}
\ No newline at end of file
diff --git a/test/WebSites/FormatterWebSite/Controllers/XmlSerializerController.cs b/test/WebSites/FormatterWebSite/Controllers/XmlSerializerController.cs
index 0a0c154ad5..f2544ce6e0 100644
--- a/test/WebSites/FormatterWebSite/Controllers/XmlSerializerController.cs
+++ b/test/WebSites/FormatterWebSite/Controllers/XmlSerializerController.cs
@@ -1,6 +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.
+using System.Collections.Generic;
using Microsoft.AspNet.Mvc;
namespace FormatterWebSite
@@ -23,5 +24,24 @@ namespace FormatterWebSite
{
return new DummyClass { SampleInt = sampleInput };
}
+
+ [HttpPost]
+ public DummyClass GetDerivedDummyClass(int sampleInput)
+ {
+ return new DerivedDummyClass
+ {
+ SampleInt = sampleInput,
+ SampleIntInDerived = 50
+ };
+ }
+
+ [HttpPost]
+ public Dictionary GetDictionary()
+ {
+ return new Dictionary
+ {
+ { "Hello", "World" }
+ };
+ }
}
}
\ No newline at end of file
diff --git a/test/WebSites/FormatterWebSite/Models/DerivedDummyClass.cs b/test/WebSites/FormatterWebSite/Models/DerivedDummyClass.cs
new file mode 100644
index 0000000000..c1e741eb11
--- /dev/null
+++ b/test/WebSites/FormatterWebSite/Models/DerivedDummyClass.cs
@@ -0,0 +1,10 @@
+// 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 FormatterWebSite
+{
+ public class DerivedDummyClass : DummyClass
+ {
+ public int SampleIntInDerived { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/test/WebSites/FormatterWebSite/Models/DummyClass.cs b/test/WebSites/FormatterWebSite/Models/DummyClass.cs
index a4f603db80..961b26e258 100644
--- a/test/WebSites/FormatterWebSite/Models/DummyClass.cs
+++ b/test/WebSites/FormatterWebSite/Models/DummyClass.cs
@@ -1,8 +1,13 @@
// 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.Runtime.Serialization;
+using System.Xml.Serialization;
+
namespace FormatterWebSite
{
+ [KnownType(typeof(DerivedDummyClass))]
+ [XmlInclude(typeof(DerivedDummyClass))]
public class DummyClass
{
public int SampleInt { get; set; }
diff --git a/test/WebSites/FormatterWebSite/project.json b/test/WebSites/FormatterWebSite/project.json
index 9ab0d45e17..5a2205e1a7 100644
--- a/test/WebSites/FormatterWebSite/project.json
+++ b/test/WebSites/FormatterWebSite/project.json
@@ -4,7 +4,16 @@
"Microsoft.AspNet.Mvc.TestConfiguration": ""
},
"configurations": {
- "aspnet50": { },
- "aspnetcore50": { }
+ "aspnet50": {
+ "dependencies": {
+ "System.Xml": ""
+ }
+ },
+ "aspnetcore50": {
+ "dependencies": {
+ "System.Runtime.Serialization.Xml": "4.0.0.0",
+ "System.Xml.ReaderWriter": "4.0.10.0"
+ }
+ }
}
}