Merge pull request #13 from wixtoolset/bob/CompareXml

Add CompareXml methods to assert XML equality.
This commit is contained in:
Bob Arnson 2020-08-21 16:42:33 -04:00 коммит произвёл GitHub
Родитель 1fb8fc82e5 137d438f74
Коммит c0bdce5ec3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 19 добавлений и 0 удалений

Просмотреть файл

@ -3,6 +3,8 @@
namespace WixBuildTools.TestSupport
{
using System;
using System.Linq;
using System.Xml.Linq;
using Xunit;
public class WixAssert : Assert
@ -14,9 +16,26 @@ namespace WixBuildTools.TestSupport
Assert.True(actualLines.Length > i, $"{i}: expectedLines longer than actualLines");
Assert.Equal($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}");
}
Assert.True(expectedLines.Length == actualLines.Length, "actualLines longer than expectedLines");
}
public static void CompareXml(XContainer xExpected, XContainer xActual)
{
var actuals = xActual.Descendants().Select(x => $"{x.Name.LocalName}:{String.Join(",", x.Attributes().OrderBy(a => a.Name.LocalName).Select(a => $"{a.Name.LocalName}={a.Value}"))}");
var expecteds = xExpected.Descendants().Select(x => $"{x.Name.LocalName}:{String.Join(",", x.Attributes().OrderBy(a => a.Name.LocalName).Select(a => $"{a.Name.LocalName}={a.Value}"))}");
CompareLineByLine(expecteds.OrderBy(s => s).ToArray(), actuals.OrderBy(s => s).ToArray());
}
public static void CompareXml(string expectedPath, string actualPath)
{
var expectedDoc = XDocument.Load(expectedPath, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
var actualDoc = XDocument.Load(actualPath, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
CompareXml(expectedDoc, actualDoc);
}
public static void Succeeded(int hr, string format, params object[] formatArgs)
{
if (0 > hr)