diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-12-31 18:20:50 -0600 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2022-01-01 10:24:08 -0600 |
commit | 95b1be66d4c16b1b05b761c1771df229ac0e539c (patch) | |
tree | 7ea6a46cd25ea83c41d0a7ba66df177925d95f44 /src/internal/WixBuildTools.TestSupport/WixAssert.cs | |
parent | 5be795c6bcbc03bc37f7cf7c758298ccfaa884ca (diff) | |
download | wix-95b1be66d4c16b1b05b761c1771df229ac0e539c.tar.gz wix-95b1be66d4c16b1b05b761c1771df229ac0e539c.tar.bz2 wix-95b1be66d4c16b1b05b761c1771df229ac0e539c.zip |
Try to get more helpful test failure messages.
Diffstat (limited to 'src/internal/WixBuildTools.TestSupport/WixAssert.cs')
-rw-r--r-- | src/internal/WixBuildTools.TestSupport/WixAssert.cs | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/src/internal/WixBuildTools.TestSupport/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/WixAssert.cs index 5638a787..938902ec 100644 --- a/src/internal/WixBuildTools.TestSupport/WixAssert.cs +++ b/src/internal/WixBuildTools.TestSupport/WixAssert.cs | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace WixBuildTools.TestSupport | 3 | namespace WixBuildTools.TestSupport |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | ||
6 | using System.Linq; | 7 | using System.Linq; |
7 | using System.Xml.Linq; | 8 | using System.Xml.Linq; |
8 | using Xunit; | 9 | using Xunit; |
@@ -14,10 +15,10 @@ namespace WixBuildTools.TestSupport | |||
14 | for (var i = 0; i < expectedLines.Length; ++i) | 15 | for (var i = 0; i < expectedLines.Length; ++i) |
15 | { | 16 | { |
16 | Assert.True(actualLines.Length > i, $"{i}: expectedLines longer than actualLines"); | 17 | Assert.True(actualLines.Length > i, $"{i}: expectedLines longer than actualLines"); |
17 | Assert.Equal($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}"); | 18 | WixAssert.StringEqual($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}"); |
18 | } | 19 | } |
19 | 20 | ||
20 | Assert.True(expectedLines.Length == actualLines.Length, "actualLines longer than expectedLines"); | 21 | Assert.True(expectedLines.Length == actualLines.Length, $"actualLines ({actualLines.Length}) longer than expectedLines ({expectedLines.Length})"); |
21 | } | 22 | } |
22 | 23 | ||
23 | public static void CompareXml(XContainer xExpected, XContainer xActual) | 24 | public static void CompareXml(XContainer xExpected, XContainer xActual) |
@@ -43,5 +44,48 @@ namespace WixBuildTools.TestSupport | |||
43 | throw new SucceededException(hr, String.Format(format, formatArgs)); | 44 | throw new SucceededException(hr, String.Format(format, formatArgs)); |
44 | } | 45 | } |
45 | } | 46 | } |
47 | |||
48 | public static void StringCollectionEmpty(IList<string> collection) | ||
49 | { | ||
50 | if (collection.Count > 0) | ||
51 | { | ||
52 | Assert.True(false, $"The collection was expected to be empty, but instead was [{Environment.NewLine}\"{String.Join($"\", {Environment.NewLine}\"", collection)}\"{Environment.NewLine}]"); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public static void StringEqual(string expected, string actual, bool ignoreCase = false) | ||
57 | { | ||
58 | var comparer = ignoreCase ? StringObjectEqualityComparer.InvariantCultureIgnoreCase : StringObjectEqualityComparer.InvariantCulture; | ||
59 | Assert.Equal<object>(expected, actual, comparer); | ||
60 | } | ||
61 | |||
62 | public static void NotStringEqual(string expected, string actual, bool ignoreCase = false) | ||
63 | { | ||
64 | var comparer = ignoreCase ? StringObjectEqualityComparer.InvariantCultureIgnoreCase : StringObjectEqualityComparer.InvariantCulture; | ||
65 | Assert.NotEqual<object>(expected, actual, comparer); | ||
66 | } | ||
67 | |||
68 | private class StringObjectEqualityComparer : IEqualityComparer<object> | ||
69 | { | ||
70 | public static readonly StringObjectEqualityComparer InvariantCultureIgnoreCase = new StringObjectEqualityComparer(true); | ||
71 | public static readonly StringObjectEqualityComparer InvariantCulture = new StringObjectEqualityComparer(false); | ||
72 | |||
73 | private readonly StringComparer _stringComparer; | ||
74 | |||
75 | public StringObjectEqualityComparer(bool ignoreCase) | ||
76 | { | ||
77 | this._stringComparer = ignoreCase ? StringComparer.InvariantCultureIgnoreCase : StringComparer.InvariantCulture; | ||
78 | } | ||
79 | |||
80 | public new bool Equals(object x, object y) | ||
81 | { | ||
82 | return this._stringComparer.Equals((string)x,(string)y); | ||
83 | } | ||
84 | |||
85 | public int GetHashCode(object obj) | ||
86 | { | ||
87 | return this._stringComparer.GetHashCode((string)obj); | ||
88 | } | ||
89 | } | ||
46 | } | 90 | } |
47 | } | 91 | } |