@joebigelow / wix / commits / 8185b848

Add QueryDatabaseByTable.

Sean Hall committed Apr 3, 2020 at 14:06 UTC 8185b8482fe9576281a3a89947e54182e213a24b
1 file changed +27 -4
src/WixBuildTools.TestSupport/Query.cs
+27 -4
@@ -15,6 +15,27 @@ namespace WixBuildTools.TestSupport
15 public static string[] QueryDatabase(string path, string[] tables)
16 {
17 var results = new List<string>();
18 + var resultsByTable = QueryDatabaseByTable(path, tables);
19 + var sortedTables = tables.ToList();
20 + sortedTables.Sort();
21 + foreach (var tableName in sortedTables)
22 + {
23 + var rows = resultsByTable[tableName];
24 + rows?.ForEach(r => results.Add($"{tableName}:{r}"));
25 + }
26 + return results.ToArray();
27 + }
28 +
29 + /// <summary>
30 + /// Returns rows from requested tables formatted to facilitate testing.
31 + /// If the table did not exist in the database, its list will be null.
32 + /// </summary>
33 + /// <param name="path"></param>
34 + /// <param name="tables"></param>
35 + /// <returns></returns>
36 + public static Dictionary<string, List<string>> QueryDatabaseByTable(string path, string[] tables)
37 + {
38 + var results = new Dictionary<string, List<string>>();
39
40 if (tables?.Length > 0)
41 {
@@ -25,9 +46,12 @@ namespace WixBuildTools.TestSupport
46 {
47 if (!db.IsTablePersistent(table))
48 {
49 + results.Add(table, null);
50 continue;
51 }
52
53 + var rows = new List<string>();
54 + results.Add(table, rows);
55 using (var view = db.OpenView("SELECT * FROM `{0}`", table))
56 {
57 view.Execute();
@@ -36,7 +60,6 @@ namespace WixBuildTools.TestSupport
60 while ((record = view.Fetch()) != null)
61 {
62 sb.Clear();
39 - sb.AppendFormat("{0}:", table);
63
64 using (record)
65 {
@@ -51,15 +74,15 @@ namespace WixBuildTools.TestSupport
74 }
75 }
76
54 - results.Add(sb.ToString());
77 + rows.Add(sb.ToString());
78 }
79 }
80 + rows.Sort();
81 }
82 }
83 }
84
61 - results.Sort();
62 - return results.ToArray();
85 + return results;
86 }
87
88 public static CabFileInfo[] GetCabinetFiles(string path)