diff options
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport/WixAssert.cs')
| -rw-r--r-- | src/internal/WixBuildTools.TestSupport/WixAssert.cs | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/internal/WixBuildTools.TestSupport/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/WixAssert.cs new file mode 100644 index 00000000..5638a787 --- /dev/null +++ b/src/internal/WixBuildTools.TestSupport/WixAssert.cs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 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 | ||
| 11 | { | ||
| 12 | public static void CompareLineByLine(string[] expectedLines, string[] actualLines) | ||
| 13 | { | ||
| 14 | for (var i = 0; i < expectedLines.Length; ++i) | ||
| 15 | { | ||
| 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 expecteds = xExpected.Descendants().Select(x => $"{x.Name.LocalName}:{String.Join(",", x.Attributes().OrderBy(a => a.Name.LocalName).Select(a => $"{a.Name.LocalName}={a.Value}"))}"); | ||
| 26 | 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}"))}"); | ||
| 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) | ||
| 42 | { | ||
| 43 | throw new SucceededException(hr, String.Format(format, formatArgs)); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
