-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRealTimeTestResultWindow.cs
More file actions
326 lines (275 loc) · 11.4 KB
/
Copy pathRealTimeTestResultWindow.cs
File metadata and controls
326 lines (275 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using FontAwesome.Sharp;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using utPLSQL;
namespace PlsqlDeveloperUtPlsqlPlugin
{
public partial class RealTimeTestResultWindow : Form
{
private const int IconSize = 24;
private readonly RealTimeTestRunner testRunner;
private BindingList<TestResult> testResults = new BindingList<TestResult>();
private int totalNumberOfTests;
private bool running;
public RealTimeTestResultWindow(RealTimeTestRunner testRunner)
{
this.testRunner = testRunner;
InitializeComponent();
var bindingSource = new BindingSource();
bindingSource.DataSource = testResults;
gridResults.DataSource = bindingSource;
gridResults.Columns[0].HeaderText = "";
gridResults.Columns[0].MinimumWidth = 30;
gridResults.Columns[1].MinimumWidth = 235;
gridResults.Columns[2].MinimumWidth = 600;
gridResults.Columns[3].MinimumWidth = 100;
gridResults.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
internal void RunTests(string type, string owner, string name, string subType)
{
running = true;
ResetComponents();
testResults.Clear();
setWindowTitle(type, owner, name, subType);
CenterToScreen();
Show();
new Thread(() =>
{
testRunner.RunTests(type, owner, name, subType);
}).Start();
new Thread(() =>
{
var completetedTests = 0;
testRunner.ConsumeResult(@event =>
{
gridResults.BeginInvoke((MethodInvoker)delegate ()
{
if (@event.type.Equals("pre-run"))
{
totalNumberOfTests = @event.totalNumberOfTests;
progressBar.Minimum = 0;
progressBar.Maximum = totalNumberOfTests;
CreateTestResults(@event);
gridResults.Rows[0].Selected = false;
}
else if (@event.type.Equals("post-test"))
{
completetedTests++;
txtTests.Text = (completetedTests > totalNumberOfTests ? totalNumberOfTests : completetedTests) + "/" + totalNumberOfTests;
progressBar.Value = completetedTests;
UpdateTestResult(@event);
}
else if (@event.type.Equals("post-run"))
{
txtStart.Text = @event.run.startTime.ToString();
txtEnd.Text = @event.run.endTime.ToString();
txtTime.Text = @event.run.executionTime + " s";
txtStatus.Text = "Finished";
txtTests.Text = (completetedTests > totalNumberOfTests ? totalNumberOfTests : completetedTests) + "/" + totalNumberOfTests;
txtFailures.Text = @event.run.counter.failure + "";
txtErrors.Text = @event.run.counter.error + "";
txtDisabled.Text = @event.run.counter.disabled + "";
if (@event.run.counter.failure > 0 || @event.run.counter.error > 0)
{
progressBar.ForeColor = Color.DarkRed;
}
gridResults.Rows[0].Selected = true;
running = false;
}
});
});
}).Start();
}
private void setWindowTitle(string type, string owner, string name, string subType)
{
var startTime = DateTime.Now.ToString();
txtStart.Text = startTime;
if (type.Equals("USER"))
{
this.Text = name + " " + startTime;
txtTestExecution.Text = $"All Tests of {name}";
}
else if (type.Equals("PACKAGE"))
{
this.Text = $"{owner}.{name}" + " " + startTime;
txtTestExecution.Text = $"Package {owner}.{name}";
}
else if (type.Equals("_ALL"))
{
this.Text = owner + " " + startTime;
txtTestExecution.Text = $"All Tests of {owner}";
}
}
private void ResetComponents()
{
txtTestExecution.Text = "";
txtStart.Text = "";
txtTime.Text = "";
txtEnd.Text = "";
txtTests.Text = "";
txtFailures.Text = "";
txtErrors.Text = "";
txtDisabled.Text = "";
txtStatus.Text = "";
txtStatus.Text = "Running...";
txtTestOwner.Text = "";
txtTestPackage.Text = "";
txtTestProcuedure.Text = "";
txtTestName.Text = "";
txtTestDescription.Text = "";
txtTestSuitePath.Text = "";
txtTestStart.Text = "";
txtTestEnd.Text = "";
txtTestTime.Text = "";
txtErrorMessage.Text = "";
var bindingSource = new BindingSource();
bindingSource.DataSource = new BindingList<Expectation>();
gridTestFailures.DataSource = bindingSource;
progressBar.ForeColor = Color.Green;
progressBar.Minimum = 0;
progressBar.Maximum = 100;
progressBar.Value = 0;
}
private void UpdateTestResult(@event @event)
{
if (@event.test != null)
{
foreach (var testResult in testResults)
{
if (testResult.Id.Equals(@event.test.id))
{
testResult.Start = @event.test.startTime;
testResult.End = @event.test.endTime;
testResult.Time = @event.test.executionTime;
var counter = @event.test.counter;
if (counter.disabled > 0)
{
testResult.Icon = IconChar.Ban.ToBitmap(Color.Gray, IconSize);
}
else if (counter.success > 0)
{
testResult.Icon = IconChar.Check.ToBitmap(Color.Green, IconSize);
}
else if (counter.failure > 0)
{
testResult.Icon = IconChar.TimesCircle.ToBitmap(IconFont.Solid, IconSize, Color.Orange);
}
else if (counter.error > 0)
{
testResult.Icon = IconChar.ExclamationCircle.ToBitmap(Color.Red, IconSize);
}
else if (counter.warning > 0)
{
testResult.Icon = IconChar.ExclamationTriangle.ToBitmap(Color.Orange, IconSize);
}
if (@event.test.errorStack != null)
{
testResult.Error = @event.test.errorStack;
}
if (@event.test.failedExpectations != null)
{
foreach (var expectation in @event.test.failedExpectations)
{
testResult.failedExpectations.Add(new Expectation(expectation.message, expectation.caller));
}
}
gridResults.Refresh();
}
}
}
}
private void CreateTestResults(@event @event)
{
CreateTestResults(@event.items);
CreateTestResults(@event.suite);
CreateTestResults(@event.test);
}
private void CreateTestResults(items items)
{
if (items != null)
{
if (items.suite != null)
{
foreach (var itemSuite in items.suite)
{
CreateTestResults(itemSuite);
}
}
if (items.test != null)
{
foreach (var test in items.test)
{
CreateTestResults(test);
}
}
}
}
private void CreateTestResults(suite suite)
{
if (suite != null && suite.items != null)
{
CreateTestResults(suite.items);
}
}
private void CreateTestResults(test test)
{
if (test != null)
{
testResults.Add(new TestResult
{
Id = test.id,
Owner = test.ownerName,
Package = test.objectName,
Procedure = test.procedureName,
Name = test.name,
Description = test.description,
Icon = IconChar.None.ToBitmap(Color.Black, IconSize)
});
}
}
private void btnClose_Click(object sender, System.EventArgs e)
{
Close();
}
private void TestResultWindow_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
if (running)
{
var confirmResult = MessageBox.Show("Tests are still running.\r\nDo you really want to close the Dialog?", "Running Tests", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (confirmResult == DialogResult.No)
{
e.Cancel = true;
}
}
}
}
private void gridResults_SelectionChanged(object sender, EventArgs e)
{
if (gridResults.SelectedRows.Count > 0)
{
DataGridViewRow row = gridResults.SelectedRows[0];
TestResult testResult = (TestResult)row.DataBoundItem;
txtTestOwner.Text = testResult.Owner;
txtTestPackage.Text = testResult.Package;
txtTestProcuedure.Text = testResult.Procedure;
txtTestName.Text = testResult.Name;
txtTestDescription.Text = testResult.Description;
txtTestSuitePath.Text = testResult.Id;
txtTestStart.Text = testResult.Start == null ? "" : testResult.Start.ToString();
txtTestEnd.Text = testResult.End == null ? "" : testResult.End.ToString();
txtTestTime.Text = testResult.Time + " s";
txtErrorMessage.Text = testResult.Error;
var bindingSource = new BindingSource();
bindingSource.DataSource = testResult.failedExpectations;
gridTestFailures.DataSource = bindingSource;
gridTestFailures.Columns[0].MinimumWidth = 480;
gridTestFailures.Columns[1].MinimumWidth = 480;
}
}
}
}