-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
279 lines (258 loc) · 10.2 KB
/
MainWindow.xaml.cs
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
using CbOrm.Gen.Test;
using CbOrm.Test;
using CbOrm.Util;
using CbOrm.Xdl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace CbOrmTester
{
public static class CDispatcherExtensions
{
public static void BeginInvoke(this Dispatcher aDispatcher, Action aAction)
{
aDispatcher.BeginInvoke(aAction);
}
}
/// <summary>
/// Interaktionslogik für MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var aDirectoryInfo = new DirectoryInfo(
System.IO.Path.Combine(new FileInfo(this.GetType().Assembly.Location).Directory.Parent.Parent.Parent.FullName,
@"CbOrm\UnitTest"
));
var aFileInfo = new FileInfo(System.IO.Path.Combine(aDirectoryInfo.FullName, "TestSequence.xdl"));
var aRows = CRflRow.NewFromTextFile(aFileInfo);
var aVms = (from aRow in aRows
where aRow.RecognizeBool
select new CTestCaseVm(aFileInfo.Directory, aRow)).ToArray();
this.TestCaseVms = aVms;
this.RefreshTestCase();
this.InterceptionBorder.Visibility = Visibility.Collapsed;
this.TestSequenceFile = aFileInfo;
}
private readonly FileInfo TestSequenceFile;
private IEnumerable<CTestCaseVm> TestCaseVms {
get => (IEnumerable<CTestCaseVm>)this.DataContext;
set => this.DataContext = value; }
private CTestCaseVm TestCaseVmNullable { get => (CTestCaseVm)this.TestCasesListBox.SelectedItem; }
private void TestCasesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
this.RefreshTestCase();
}
private void RefreshTestCase()
{
var aTestCaseVm = (CTestCaseVm)this.TestCasesListBox.SelectedItem;
if (!aTestCaseVm.IsNullRef())
{
aTestCaseVm.Refresh();
}
this.TestCaseGrid.DataContext = aTestCaseVm;
}
private bool? Accept;
private DispatcherFrame InterceptorFrame;
private bool TestRunning;
private void Run(IEnumerable<CTestCaseVm> aTestCaseVms)
{
if (this.TestRunning)
{
throw new InvalidOperationException();
}
else
{
foreach(var aTestCaseVm in this.TestCaseVms)
{
aTestCaseVm.Ok = default(bool?);
}
this.TestRunning = true;
this.Cursor = Cursors.Wait;
try
{
var aRunFrame = new DispatcherFrame();
var aRun = new Action(delegate ()
{
var aGenUnitTest = new CGenUnitTest(this.TestSequenceFile);
aGenUnitTest.TestInterceptor.Intercepting += delegate (object aSender, EventArgs aArgs)
{
var aTestInterceptEventArgs = aArgs as CTestResultEventArgs;
if (!aTestInterceptEventArgs.IsNullRef())
{
var aOk = (bool)aTestInterceptEventArgs.TestResult.Dyn().Ok;
if (!aOk)
{
this.Accept = default(bool?);
this.InterceptorFrame = new DispatcherFrame();
this.Dispatcher.BeginInvoke(new Action(delegate ()
{
this.OutTestFileGui.Refresh();
this.TestResultListBox.DataContext = aTestInterceptEventArgs.TestResult;
this.InterceptionBorder.Visibility = Visibility.Visible;
}));
Dispatcher.PushFrame(this.InterceptorFrame);
aGenUnitTest.TestInterceptor.Accepted = this.Accept.GetValueOrDefault(false);
this.Dispatcher.BeginInvoke(new Action(delegate ()
{
this.InterceptionBorder.Visibility = Visibility.Collapsed;
}));
}
this.Dispatcher.BeginInvoke(delegate ()
{
var aTestCaseId = aTestInterceptEventArgs.TestCase.Name;
var aTestCaseVm = (from aTest in this.TestCaseVms where aTest.Row.TypName == aTestCaseId select aTest).FirstOrDefault();
if (!aTestCaseVm.IsNullRef())
{
aTestCaseVm.Ok = (bool)aTestInterceptEventArgs.TestResult.Dyn().Ok;
}
});
}
};
var aTestCaseTyps = from aTestCaseVm in aTestCaseVms
where aTestCaseVm.Row.RecognizeBool
select aGenUnitTest.TestSequence.GetTypByName(aTestCaseVm.Row.TypName);
try
{
foreach (var aTestCaseTyp in aTestCaseTyps)
{
aGenUnitTest.Run(aTestCaseTyp);
}
}
catch(Exception)
{
}
aRunFrame.Continue = false;
});
var aThread = new System.Threading.Thread(new System.Threading.ThreadStart(aRun));
aThread.Start();
Dispatcher.PushFrame(aRunFrame);
}
finally
{
this.TestRunning = false;
this.Cursor = Cursors.Arrow;
}
}
}
private void RunAllButton_Click(object sender, RoutedEventArgs e)
{
CGuiCommand.Invoke(delegate () { this.Run(this.TestCaseVms); });
}
private void RunSelectedButton_Click(object sender, RoutedEventArgs e)
{
CGuiCommand.Invoke(delegate () { if (this.TestCaseVmNullable != null)
this.Run(new CTestCaseVm[] { this.TestCaseVmNullable }); });
}
private void TestResultListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(!this.TestCaseVmNullable.IsNullRef())
{
this.TestCaseVmNullable.Refresh();
}
}
private void OnAcceptButtonClick(object sender, RoutedEventArgs e)
{
CGuiCommand.Invoke(delegate ()
{
this.Accept = true;
this.InterceptorFrame.Continue = false;
});
}
private void OnRejectButtonClick(object sender, RoutedEventArgs e)
{
CGuiCommand.Invoke(delegate ()
{
this.Accept = false;
this.InterceptorFrame.Continue = false;
});
}
}
public class CFileVm : CViewModel
{
public CFileVm(FileInfo aFileInfo)
{
this.FileInfo = aFileInfo;
this.Refresh();
}
public FileInfo FileInfo { get; set; }
private string ContentM;
public string Content { get { return this.ContentM; }set { this.ContentM = value; this.OnPropertyChanged(nameof(this.Content)); } }
public void Refresh()
{
this.Content = this.Exists
? System.IO.File.ReadAllLines(this.FileInfo.FullName).JoinString(Environment.NewLine)
: string.Empty
;
}
public bool Exists
{
get
{
return new FileInfo(this.FileInfo.FullName).Exists;
}
}
}
public abstract class CViewModel :INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string aPropertyName)
{
if (!this.PropertyChanged.IsNullRef())
{
this.PropertyChanged(this, new PropertyChangedEventArgs(aPropertyName));
}
}
}
public class CTestCaseVm : CViewModel
{
public CTestCaseVm(DirectoryInfo aDir, CRflRow aRow)
{
var aMI = new CTestModelInterpreter();
var aPrefix = System.IO.Path.Combine(aDir.FullName, "TestCases", aRow.TypName + "");
var aInFile = new FileInfo(aPrefix + "-in.xdl");
var aTestFile = new FileInfo(aPrefix + "-out-test.cs");
var aOkFile = new FileInfo(aPrefix + "-out-ok.cs");
this.InFileVm = new CFileVm(aInFile);
this.OutTestFileVm = new CFileVm(aTestFile);
this.OutOkFileVm = new CFileVm(aOkFile);
this.Row = aRow;
}
public CRflRow Row { get; set; }
public CFileVm InFileVm { get; set; }
public CFileVm OutTestFileVm { get; set; }
public CFileVm OutOkFileVm { get; set; }
private bool? OkM;
public bool? Ok
{
get => this.OkM;
set
{
this.OkM = value;
this.OnPropertyChanged(nameof(this.Ok));
}
}
internal void Refresh()
{
this.InFileVm.Refresh();
this.OutTestFileVm.Refresh();
this.OutOkFileVm.Refresh();
}
}
}