diff options
Diffstat (limited to 'src/internal/WixInternal.TestSupport/Query.cs')
-rw-r--r-- | src/internal/WixInternal.TestSupport/Query.cs | 127 |
1 files changed, 81 insertions, 46 deletions
diff --git a/src/internal/WixInternal.TestSupport/Query.cs b/src/internal/WixInternal.TestSupport/Query.cs index 38f5df64..4b396454 100644 --- a/src/internal/WixInternal.TestSupport/Query.cs +++ b/src/internal/WixInternal.TestSupport/Query.cs | |||
@@ -26,6 +26,20 @@ namespace WixInternal.TestSupport | |||
26 | return results.ToArray(); | 26 | return results.ToArray(); |
27 | } | 27 | } |
28 | 28 | ||
29 | public static string[] QueryDatabase(Database db, string[] tables) | ||
30 | { | ||
31 | var results = new List<string>(); | ||
32 | var resultsByTable = QueryDatabaseByTable(db, tables); | ||
33 | var sortedTables = tables.ToList(); | ||
34 | sortedTables.Sort(); | ||
35 | foreach (var tableName in sortedTables) | ||
36 | { | ||
37 | var rows = resultsByTable[tableName]; | ||
38 | rows?.ForEach(r => results.Add($"{tableName}:{r}")); | ||
39 | } | ||
40 | return results.ToArray(); | ||
41 | } | ||
42 | |||
29 | /// <summary> | 43 | /// <summary> |
30 | /// Returns rows from requested tables formatted to facilitate testing. | 44 | /// Returns rows from requested tables formatted to facilitate testing. |
31 | /// If the table did not exist in the database, its list will be null. | 45 | /// If the table did not exist in the database, its list will be null. |
@@ -39,68 +53,89 @@ namespace WixInternal.TestSupport | |||
39 | 53 | ||
40 | if (tables?.Length > 0) | 54 | if (tables?.Length > 0) |
41 | { | 55 | { |
42 | var sb = new StringBuilder(); | ||
43 | using (var db = new Database(path)) | 56 | using (var db = new Database(path)) |
44 | { | 57 | { |
45 | foreach (var table in tables) | 58 | results = QueryDatabaseByTable(db, tables); |
59 | } | ||
60 | } | ||
61 | |||
62 | return results; | ||
63 | } | ||
64 | |||
65 | /// <summary> | ||
66 | /// Returns rows from requested tables formatted to facilitate testing. | ||
67 | /// If the table did not exist in the database, its list will be null. | ||
68 | /// </summary> | ||
69 | /// <param name="db"></param> | ||
70 | /// <param name="tables"></param> | ||
71 | /// <returns></returns> | ||
72 | public static Dictionary<string, List<string>> QueryDatabaseByTable(Database db, string[] tables) | ||
73 | { | ||
74 | var results = new Dictionary<string, List<string>>(); | ||
75 | |||
76 | if (tables?.Length > 0) | ||
77 | { | ||
78 | var sb = new StringBuilder(); | ||
79 | |||
80 | foreach (var table in tables) | ||
81 | { | ||
82 | if (table == "_SummaryInformation") | ||
46 | { | 83 | { |
47 | if (table == "_SummaryInformation") | 84 | var entries = new List<string>(); |
48 | { | 85 | results.Add(table, entries); |
49 | var entries = new List<string>(); | 86 | |
50 | results.Add(table, entries); | 87 | entries.Add($"Title\t{db.SummaryInfo.Title}"); |
51 | 88 | entries.Add($"Subject\t{db.SummaryInfo.Subject}"); | |
52 | entries.Add($"Title\t{db.SummaryInfo.Title}"); | 89 | entries.Add($"Author\t{db.SummaryInfo.Author}"); |
53 | entries.Add($"Subject\t{db.SummaryInfo.Subject}"); | 90 | entries.Add($"Keywords\t{db.SummaryInfo.Keywords}"); |
54 | entries.Add($"Author\t{db.SummaryInfo.Author}"); | 91 | entries.Add($"Comments\t{db.SummaryInfo.Comments}"); |
55 | entries.Add($"Keywords\t{db.SummaryInfo.Keywords}"); | 92 | entries.Add($"Template\t{db.SummaryInfo.Template}"); |
56 | entries.Add($"Comments\t{db.SummaryInfo.Comments}"); | 93 | entries.Add($"CodePage\t{db.SummaryInfo.CodePage}"); |
57 | entries.Add($"Template\t{db.SummaryInfo.Template}"); | 94 | entries.Add($"PageCount\t{db.SummaryInfo.PageCount}"); |
58 | entries.Add($"CodePage\t{db.SummaryInfo.CodePage}"); | 95 | entries.Add($"WordCount\t{db.SummaryInfo.WordCount}"); |
59 | entries.Add($"PageCount\t{db.SummaryInfo.PageCount}"); | 96 | entries.Add($"CharacterCount\t{db.SummaryInfo.CharacterCount}"); |
60 | entries.Add($"WordCount\t{db.SummaryInfo.WordCount}"); | 97 | entries.Add($"Security\t{db.SummaryInfo.Security}"); |
61 | entries.Add($"CharacterCount\t{db.SummaryInfo.CharacterCount}"); | 98 | |
62 | entries.Add($"Security\t{db.SummaryInfo.Security}"); | 99 | continue; |
63 | 100 | } | |
64 | continue; | ||
65 | } | ||
66 | 101 | ||
67 | if (!db.IsTablePersistent(table)) | 102 | if (!db.IsTablePersistent(table)) |
68 | { | 103 | { |
69 | results.Add(table, null); | 104 | results.Add(table, null); |
70 | continue; | 105 | continue; |
71 | } | 106 | } |
72 | 107 | ||
73 | var rows = new List<string>(); | 108 | var rows = new List<string>(); |
74 | results.Add(table, rows); | 109 | results.Add(table, rows); |
75 | 110 | ||
76 | using (var view = db.OpenView("SELECT * FROM `{0}`", table)) | 111 | using (var view = db.OpenView("SELECT * FROM `{0}`", table)) |
112 | { | ||
113 | view.Execute(); | ||
114 | |||
115 | Record record; | ||
116 | while ((record = view.Fetch()) != null) | ||
77 | { | 117 | { |
78 | view.Execute(); | 118 | sb.Clear(); |
79 | 119 | ||
80 | Record record; | 120 | using (record) |
81 | while ((record = view.Fetch()) != null) | ||
82 | { | 121 | { |
83 | sb.Clear(); | 122 | for (var i = 0; i < record.FieldCount; ++i) |
84 | |||
85 | using (record) | ||
86 | { | 123 | { |
87 | for (var i = 0; i < record.FieldCount; ++i) | 124 | if (i > 0) |
88 | { | 125 | { |
89 | if (i > 0) | 126 | sb.Append("\t"); |
90 | { | ||
91 | sb.Append("\t"); | ||
92 | } | ||
93 | |||
94 | sb.Append(record[i + 1]?.ToString()); | ||
95 | } | 127 | } |
96 | } | ||
97 | 128 | ||
98 | rows.Add(sb.ToString()); | 129 | sb.Append(record[i + 1]?.ToString()); |
130 | } | ||
99 | } | 131 | } |
132 | |||
133 | rows.Add(sb.ToString()); | ||
100 | } | 134 | } |
101 | rows.Sort(); | ||
102 | } | 135 | } |
103 | } | 136 | |
137 | rows.Sort(); | ||
138 | } | ||
104 | } | 139 | } |
105 | 140 | ||
106 | return results; | 141 | return results; |