diff options
author | Rob Mensching <rob@firegiant.com> | 2021-04-22 16:36:39 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-04-22 16:50:15 -0700 |
commit | 6a24996a2e831cfe402398af65b31fb1ecd575a9 (patch) | |
tree | e377370df4bc7901745c6b5f50268fa665edb3f8 /src/internal/WixBuildTools.TestSupport/WixAssert.cs | |
parent | 2587a8b46b705d53156f5cd1bd866f855049081d (diff) | |
download | wix-6a24996a2e831cfe402398af65b31fb1ecd575a9.tar.gz wix-6a24996a2e831cfe402398af65b31fb1ecd575a9.tar.bz2 wix-6a24996a2e831cfe402398af65b31fb1ecd575a9.zip |
Move WixBuildTools into internal
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 | } | ||