parent
310ab25347
commit
0ec2a3131f
|
|
@ -10,8 +10,6 @@ using System.Threading.Tasks;
|
|||
using System.Xml;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -52,6 +50,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
public TestLevelOne TestOne { get; set; }
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("application/xml", true)]
|
||||
[InlineData("application/*", false)]
|
||||
[InlineData("*/*", false)]
|
||||
|
|
@ -86,6 +85,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedCanRead, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void XmlDataContractSerializer_CachesSerializerForType()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -129,6 +129,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.True(formatter.SupportedEncodings.Any(i => i.WebName == "utf-16"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ReadsSimpleTypes()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -155,6 +156,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedString, model.sampleString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ReadsComplexTypes()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -184,6 +186,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedString, model.TestOne.sampleString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ReadsWhenMaxDepthIsModified()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -207,6 +210,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedInt, model.SampleInt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ThrowsOnExceededMaxDepth()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -223,6 +227,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ThrowsWhenReaderQuotasAreChanged()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -249,6 +254,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Throws(typeof(ArgumentException), () => formatter.MaxDepth = 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_VerifyStreamIsOpenAfterRead()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -268,6 +274,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.True(context.HttpContext.Request.Body.CanRead);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_FallsbackToUTF8_WhenCharSet_NotInContentType()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -291,6 +298,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Contains("utf-16LE", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_UsesContentTypeCharSet_ToReadStream()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -319,6 +327,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Contains("utf-8", ex.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_IgnoresBOMCharacters()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -350,6 +359,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedBytes, Encoding.UTF8.GetBytes(model.SampleString));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_AcceptsUTF16Characters()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -387,6 +397,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedString, model.sampleString);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ThrowsWhenNotConfiguredWithRootName()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -405,6 +416,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ReadsWhenConfiguredWithRootName()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -441,6 +453,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
Assert.Equal(expectedInt, model.SampleInt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ThrowsWhenNotConfiguredWithKnownTypes()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -460,6 +473,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
await Assert.ThrowsAsync(typeof(SerializationException), async () => await formatter.ReadAsync(context));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAsync_ReadsWhenConfiguredWithKnownTypes()
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
|
|
@ -427,8 +427,6 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
}
|
||||
|
||||
#if !NETCOREAPP1_0
|
||||
// DataContractSerializer in CoreCLR does not throw if the declared type is different from the type being
|
||||
// serialized.
|
||||
[ConditionalFact]
|
||||
// Mono issue - https://github.com/aspnet/External/issues/18
|
||||
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
|
||||
|
|
@ -444,6 +442,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
|
|||
async () => await formatter.WriteAsync(outputFormatterContext));
|
||||
}
|
||||
#else
|
||||
// DataContractSerializer in CoreCLR does not throw if the declared type is different from the type being
|
||||
// serialized.
|
||||
[Fact]
|
||||
public async Task WriteAsync_SerializesObjectWhenDeclaredTypeIsDifferentFromActualType()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ using System.Net.Http.Headers;
|
|||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using XmlFormattersWebSite;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -34,6 +33,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
|
||||
public HttpClient Client { get; }
|
||||
|
||||
[Fact]
|
||||
public async Task ThrowsOnInvalidInput_AndAddsToModelState()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -53,6 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RequiredDataIsProvided_AndModelIsBound_NoValidationErrors()
|
||||
{
|
||||
// Arrange
|
||||
|
|
@ -79,6 +80,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
Assert.Empty(modelBindingInfo.ModelStateErrorMessages);
|
||||
}
|
||||
|
||||
// Verifies that the model state has errors related to body model validation.
|
||||
[Fact]
|
||||
public async Task DataMissingForRefereneceTypeProperties_AndModelIsBound_AndHasMixedValidationErrors()
|
||||
{
|
||||
// Arrange
|
||||
|
|
|
|||
Loading…
Reference in New Issue