// 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;
using Microsoft.AspNet.Testing;
using Microsoft.AspNet.Testing.xunit;
using Xunit;
using Xunit.Sdk;
namespace Microsoft.AspNet.Mvc.Formatters.Xml
{
public class XmlAssertTest
{
[Theory]
[InlineData("hello", "hey")]
[InlineData("hello world", "hello world!!")]
[InlineData("helloworld", "helloworld")]
[InlineData("helloworld", "helloworld")]
[InlineData("helloworldhello", "helloworldgoodbye")]
[InlineData("helloworld", "hellogoodbye")]
public void Throws_WithMismatchedTextNodes(string input1, string input2)
{
var equalException = Assert.Throws(() => XmlAssert.Equal(input1, input2));
Assert.Equal(input1, equalException.Expected);
Assert.Equal(input2, equalException.Actual);
}
[Theory]
[InlineData("helloworldhello", "helloworldhello")]
[InlineData("hellohello", "hellohello")]
[InlineData(
"helloworldhello",
"helloworldhello")]
public void ReturnsSuccessfully_WithMatchingTextNodes(string input1, string input2)
{
XmlAssert.Equal(input1, input2);
}
[Theory]
[InlineData("", "")]
[InlineData("", "")]
[InlineData("", "")]
[InlineData("]]>", "]]>")]
public void ReturnsSuccessfully_WithEmptyElements(string input1, string input2)
{
// DeepEquals returns false even though the generated XML documents are equal.
// This is fixed in Mono 4.3.0
if (TestPlatformHelper.IsMono
&& input1 == "]]>")
{
return;
}
XmlAssert.Equal(input1, input2);
}
[Theory]
[InlineData("",
"")]
[InlineData("",
"")]
public void Throws_WithMismatchedXmlDeclaration(string input1, string input2)
{
Assert.Throws(() => XmlAssert.Equal(input1, input2));
}
[ConditionalTheory]
// DeepEquals returns false even though the generated XML documents are equal.
// This is fixed in Mono 4.3.0
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void ReturnsSuccessfully_WithMatchingXmlDeclaration_IgnoringCase()
{
// Arrange
var input1 = "" +
"hello world";
var input2 = "" +
"hello world";
// Act and Assert
XmlAssert.Equal(input1, input2);
}
[Theory]
[InlineData(
"",
"")]
[InlineData(
"hello world",
"hello world")]
public void ReturnsSuccessfully_WithMatchingContent_IgnoringAttributeOrder(string input1, string input2)
{
XmlAssert.Equal(input1, input2);
}
[Fact]
public void Throws_WithMismatchedAttributeValues_ReorderingAttributes()
{
// Arrange
var expected = "hellohello worldhi";
var actual = "hellohello worldhi";
var exceptionMessageForExpected = "hellohello worldhi";
var exceptionMessageForActual = "hellohello worldhi";
// Act and Assert
var equalException = Assert.Throws(() => XmlAssert.Equal(expected, actual));
Assert.Equal(exceptionMessageForExpected, equalException.Expected);
Assert.Equal(exceptionMessageForActual, equalException.Actual);
}
}
}