This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing XmlSerializerInputFormatter from the list of Formatters.
Introducing a functional test for XmlSerializerInputFormatter.
- Loading branch information
sornaks
committed
Sep 22, 2014
1 parent
4c951cc
commit 0b1ad4c
Showing
11 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/Microsoft.AspNet.Mvc.FunctionalTests/XmlSerializerInputFormatterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// 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.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.TestHost; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNet.Mvc.FunctionalTests | ||
{ | ||
public class XmlSerializerInputFormatterTests | ||
{ | ||
private readonly IServiceProvider _services = TestHelper.CreateServices("XmlSerializerWebSite"); | ||
private readonly Action<IApplicationBuilder> _app = new XmlSerializerWebSite.Startup().Configure; | ||
|
||
[Fact] | ||
public async Task CheckIfXmlSerializerInputFormatterIsCalled() | ||
{ | ||
// Arrange | ||
var server = TestServer.Create(_services, _app); | ||
var client = server.CreateClient(); | ||
var sampleInputInt = 10; | ||
var input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + | ||
"<DummyClass><SampleInt>" | ||
+ sampleInputInt.ToString() + "</SampleInt></DummyClass>"; | ||
var content = new StringContent(input, Encoding.UTF8, "application/xml"); | ||
|
||
// Act | ||
var response = await client.PostAsync("http://localhost/Home/Index", content); | ||
|
||
//Assert | ||
Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
Assert.Equal(sampleInputInt.ToString(), await response.Content.ReadAsStringAsync()); | ||
} | ||
|
||
[Fact] | ||
public async Task XmlSerializerFormatter_ThrowsOnIncorrectInputNamespace() | ||
{ | ||
// Arrange | ||
var server = TestServer.Create(_services, _app); | ||
var client = server.CreateClient(); | ||
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\">" + | ||
"<SampleInt>" + sampleInputInt.ToString() + "</SampleInt></DummyClass>"; | ||
var content = new StringContent(input, Encoding.UTF8, "application/xml"); | ||
|
||
// Act & Assert | ||
await Assert.ThrowsAsync<InvalidOperationException>( | ||
async () => await client.PostAsync("http://localhost/Home/Index", content)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
test/WebSites/XmlSerializerWebSite/Controllers/HomeController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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; | ||
|
||
namespace XmlSerializerWebSite | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
[HttpPost] | ||
public IActionResult Index([FromBody]DummyClass dummyObject) | ||
{ | ||
return Content(dummyObject.SampleInt.ToString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 XmlSerializerWebSite | ||
{ | ||
public class DummyClass | ||
{ | ||
public int SampleInt { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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.SetupOptions<MvcOptions>(options => | ||
{ | ||
options.InputFormatters.Clear(); | ||
options.InputFormatters.Insert(0, new XmlSerializerInputFormatter()); | ||
}); | ||
}); | ||
|
||
// Add MVC to the request pipeline | ||
app.UseMvc(routes => | ||
{ | ||
routes.MapRoute("ActionAsMethod", "{controller}/{action}", | ||
defaults: new { controller = "Home", action = "Index" }); | ||
}); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/WebSites/XmlSerializerWebSite/XmlSerializerWebSite.kproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="__ToolsVersion__" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">12.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> | ||
<OutputType>Library</OutputType> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="$(OutputType) == 'Console'"> | ||
<DebuggerFlavor>ConsoleDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(OutputType) == 'Web'"> | ||
<DebuggerFlavor>WebDebugger</DebuggerFlavor> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'" Label="Configuration"> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'" Label="Configuration"> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\AspNet\Microsoft.Web.AspNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"dependencies": { | ||
"Microsoft.AspNet.Mvc": "", | ||
"Microsoft.AspNet.Mvc.TestConfiguration": "" | ||
}, | ||
"configurations": { | ||
"aspnet50": { }, | ||
"aspnetcore50": { } | ||
} | ||
} |