(NpgsqlCommand cmd)
| 98 | } |
| 99 | |
| 100 | public bool Run(NpgsqlCommand cmd) |
| 101 | { |
| 102 | try |
| 103 | { |
| 104 | Console.WriteLine("Running test: " + query); |
| 105 | cmd.CommandText = query; |
| 106 | using (var reader = cmd.ExecuteReader()) |
| 107 | { |
| 108 | if (!reader.HasRows) |
| 109 | { |
| 110 | if (expectedResults.Length != 0) |
| 111 | { |
| 112 | Console.Error.WriteLine($"Expected {expectedResults.Length} rows, got 0"); |
| 113 | return false; |
| 114 | } |
| 115 | Console.WriteLine("Returns 0 rows"); |
| 116 | return true; |
| 117 | } |
| 118 | if (reader.FieldCount != expectedResults[0].Length) |
| 119 | { |
| 120 | Console.Error.WriteLine($"Expected {expectedResults[0].Length} columns, got {reader.FieldCount}"); |
| 121 | return false; |
| 122 | } |
| 123 | int rows = 0; |
| 124 | while (reader.Read()) |
| 125 | { |
| 126 | for (int col = 0; col < expectedResults[rows].Length; col++) |
| 127 | { |
| 128 | string result = reader.GetValue(col).ToString().Trim(); |
| 129 | if (expectedResults[rows][col] != result) |
| 130 | { |
| 131 | Console.Error.WriteLine($"Expected:\n'{expectedResults[rows][col]}'"); |
| 132 | Console.Error.WriteLine($"Result:\n'{result}'"); |
| 133 | return false; |
| 134 | } |
| 135 | } |
| 136 | rows++; |
| 137 | } |
| 138 | Console.WriteLine("Returns " + rows + " rows"); |
| 139 | if (rows != expectedResults.Length) |
| 140 | { |
| 141 | Console.Error.WriteLine($"Expected {expectedResults.Length} rows"); |
| 142 | return false; |
| 143 | } |
| 144 | return true; |
| 145 | } |
| 146 | } |
| 147 | catch (NpgsqlException e) |
| 148 | { |
| 149 | Console.Error.WriteLine(e.Message); |
| 150 | return false; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 |
no test coverage detected