diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-04-03 14:06:49 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-04-03 20:42:53 +1000 |
| commit | 8185b8482fe9576281a3a89947e54182e213a24b (patch) | |
| tree | 0d5067ec322f84712d54afe16d78e32200608a32 /src | |
| parent | dfa44dcb277235051654fe4e951d957b5e3f9dc6 (diff) | |
| download | wix-8185b8482fe9576281a3a89947e54182e213a24b.tar.gz wix-8185b8482fe9576281a3a89947e54182e213a24b.tar.bz2 wix-8185b8482fe9576281a3a89947e54182e213a24b.zip | |
Add QueryDatabaseByTable.
Diffstat (limited to 'src')
| -rw-r--r-- | src/WixBuildTools.TestSupport/Query.cs | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/WixBuildTools.TestSupport/Query.cs b/src/WixBuildTools.TestSupport/Query.cs index bbd9f89a..b4e6b7f9 100644 --- a/src/WixBuildTools.TestSupport/Query.cs +++ b/src/WixBuildTools.TestSupport/Query.cs | |||
| @@ -15,6 +15,27 @@ namespace WixBuildTools.TestSupport | |||
| 15 | public static string[] QueryDatabase(string path, string[] tables) | 15 | public static string[] QueryDatabase(string path, string[] tables) |
| 16 | { | 16 | { |
| 17 | var results = new List<string>(); | 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>>(); | ||
| 18 | 39 | ||
| 19 | if (tables?.Length > 0) | 40 | if (tables?.Length > 0) |
| 20 | { | 41 | { |
| @@ -25,9 +46,12 @@ namespace WixBuildTools.TestSupport | |||
| 25 | { | 46 | { |
| 26 | if (!db.IsTablePersistent(table)) | 47 | if (!db.IsTablePersistent(table)) |
| 27 | { | 48 | { |
| 49 | results.Add(table, null); | ||
| 28 | continue; | 50 | continue; |
| 29 | } | 51 | } |
| 30 | 52 | ||
| 53 | var rows = new List<string>(); | ||
| 54 | results.Add(table, rows); | ||
| 31 | using (var view = db.OpenView("SELECT * FROM `{0}`", table)) | 55 | using (var view = db.OpenView("SELECT * FROM `{0}`", table)) |
| 32 | { | 56 | { |
| 33 | view.Execute(); | 57 | view.Execute(); |
| @@ -36,7 +60,6 @@ namespace WixBuildTools.TestSupport | |||
| 36 | while ((record = view.Fetch()) != null) | 60 | while ((record = view.Fetch()) != null) |
| 37 | { | 61 | { |
| 38 | sb.Clear(); | 62 | sb.Clear(); |
| 39 | sb.AppendFormat("{0}:", table); | ||
| 40 | 63 | ||
| 41 | using (record) | 64 | using (record) |
| 42 | { | 65 | { |
| @@ -51,15 +74,15 @@ namespace WixBuildTools.TestSupport | |||
| 51 | } | 74 | } |
| 52 | } | 75 | } |
| 53 | 76 | ||
| 54 | results.Add(sb.ToString()); | 77 | rows.Add(sb.ToString()); |
| 55 | } | 78 | } |
| 56 | } | 79 | } |
| 80 | rows.Sort(); | ||
| 57 | } | 81 | } |
| 58 | } | 82 | } |
| 59 | } | 83 | } |
| 60 | 84 | ||
| 61 | results.Sort(); | 85 | return results; |
| 62 | return results.ToArray(); | ||
| 63 | } | 86 | } |
| 64 | 87 | ||
| 65 | public static CabFileInfo[] GetCabinetFiles(string path) | 88 | public static CabFileInfo[] GetCabinetFiles(string path) |
