@joebigelow / wix / commits / 137d438f

Add CompareXml methods to assert XML equality.

Bob Arnson committed Aug 20, 2020 at 20:57 UTC 137d438f743198030c6df626b046af04d10abb99
1 file changed +19
src/WixBuildTools.TestSupport/WixAssert.cs
+19
@@ -3,6 +3,8 @@
3 namespace WixBuildTools.TestSupport
4 {
5 using System;
6 + using System.Linq;
7 + using System.Xml.Linq;
8 using Xunit;
9
10 public class WixAssert : Assert
@@ -14,9 +16,26 @@ namespace WixBuildTools.TestSupport
16 Assert.True(actualLines.Length > i, $"{i}: expectedLines longer than actualLines");
17 Assert.Equal($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}");
18 }
19 +
20 Assert.True(expectedLines.Length == actualLines.Length, "actualLines longer than expectedLines");
21 }
22
23 + public static void CompareXml(XContainer xExpected, XContainer xActual)
24 + {
25 + 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}"))}");
26 + 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}"))}");
27 +
28 + CompareLineByLine(expecteds.OrderBy(s => s).ToArray(), actuals.OrderBy(s => s).ToArray());
29 + }
30 +
31 + public static void CompareXml(string expectedPath, string actualPath)
32 + {
33 + var expectedDoc = XDocument.Load(expectedPath, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
34 + var actualDoc = XDocument.Load(actualPath, LoadOptions.PreserveWhitespace | LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
35 +
36 + CompareXml(expectedDoc, actualDoc);
37 + }
38 +
39 public static void Succeeded(int hr, string format, params object[] formatArgs)
40 {
41 if (0 > hr)