-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTUnitProject.cs
More file actions
184 lines (147 loc) · 5.23 KB
/
Copy pathTUnitProject.cs
File metadata and controls
184 lines (147 loc) · 5.23 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace tunit {
public class TUnitProject {
public TUnitProject() {
this.Reset();
}
public TUnitProject(string fileName) {
this.FileName = fileName;
this.Reset();
}
public string Description {
get { return this.File.Description; }
set { this.File.Description = value; }
}
public TimeSpan Duration { get; set; }
public string Name {
get { return this.File.Name; }
set { this.File.Name = value; }
}
public string FileName { get; set; }
public int TestCount {
get {
int count = 0;
foreach (var unitTest in this.unitTests) {
count += unitTest.Value.TestCount;
}
return count;
}
}
public int RanCount { get; set; }
public int SucceedCount { get; set; }
public int IngoredCount { get; set; }
public int AbortedCount { get; set; }
public int FailedCount { get; set; }
public TimeSpan ElapsedTime { get; set; }
public string[] TextOutput {
get {
List<string> textOutput = new List<string>();
bool first = true;
foreach (var unitTest in this.unitTests) {
if (!first) textOutput.Add("");
textOutput.AddRange(unitTest.Value.TextOutput);
first = false;
}
return textOutput.ToArray();
}
}
public bool Saved {
get { return this.File != null ? this.File.Saved : true; }
}
public UnitTest this[string fileName] {
get { return this.unitTests[fileName];}
}
public string[] UnitTestNames {
get { return this.unitTests.Keys.ToArray(); }
}
public UnitTest[] UnitTests {
get { return this.unitTests.Values.ToArray(); }
}
public TestStatus Status { get; set; }
private ProjectFile File { get; set; }
public EventHandler TUnitProjectStart = null;
public EventHandler TUnitProjectEnd = null;
public TestEventHandler TestStart = null;
public TestEventHandler TestEnd = null;
private static void OnTestStart(object sender, TestEventArgs e) { }
public void AddUnitTest(string fileName) {
if (this.unitTests.ContainsKey(fileName)) throw new ArgumentException("fileName already exist");
this.File.UnitTests = this.File.UnitTests.Append(fileName).ToArray();
this.unitTests.Add(fileName, new UnitTest(this, fileName));
this[fileName].Load();
}
public void RemoveUnitTest(string fileName) {
this.unitTests.Remove(fileName);
//this.File.UnitTests.Re
}
public void Load() {
this.File = ProjectFile.Read(this.FileName);
foreach (string fileName in this.File.UnitTests) {
this.unitTests.Add(fileName, new UnitTest(this, fileName));
this.unitTests[fileName].Load();
}
}
public void New() {
this.File = new ProjectFile();
}
public void New(string name) {
this.File = new ProjectFile(name);
}
public void Reset() {
this.Status = TestStatus.NotStarted;
foreach (var unitTest in this.unitTests)
unitTest.Value.Reset();
this.RanCount = 0;
this.SucceedCount = 0;
this.IngoredCount = 0;
this.AbortedCount = 0;
this.FailedCount = 0;
this.ElapsedTime = TimeSpan.Zero;
}
public void Run() {
if (this.TUnitProjectStart != null) this.TUnitProjectStart(this, EventArgs.Empty);
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
foreach (var unitTest in this.unitTests)
unitTest.Value.Run("");
sw.Stop();
this.ElapsedTime = sw.Elapsed;
if (this.TUnitProjectEnd != null) this.TUnitProjectEnd(this, EventArgs.Empty);
}
public void Run(UnitTest unitTest) {
if (this.TUnitProjectStart != null) this.TUnitProjectStart(this, EventArgs.Empty);
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
unitTest.Run();
sw.Stop();
this.ElapsedTime = sw.Elapsed;
if (this.TUnitProjectEnd != null) this.TUnitProjectEnd(this, EventArgs.Empty);
}
public void Run(TestFixture fixture) {
if (this.TUnitProjectStart != null) this.TUnitProjectStart(this, EventArgs.Empty);
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
fixture.UnitTest.Run($"--filter_tests={fixture.Name}.*");
sw.Stop();
this.ElapsedTime = sw.Elapsed;
if (this.TUnitProjectEnd != null) this.TUnitProjectEnd(this, EventArgs.Empty);
}
public void Run(Test test) {
if (this.TUnitProjectStart != null) this.TUnitProjectStart(this, EventArgs.Empty);
System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
test.TestFixture.UnitTest.Run($"--filter_tests={test.TestFixture.Name}.{test.Name}");
sw.Stop();
this.ElapsedTime = sw.Elapsed;
if (this.TUnitProjectEnd != null) this.TUnitProjectEnd(this, EventArgs.Empty);
}
public void Stop() {
foreach (var unitTest in this.unitTests)
unitTest.Value.Stop();
}
public void Save() {
ProjectFile.Write(this.FileName, this.File);
}
private Dictionary<string, UnitTest> unitTests = new Dictionary<string, UnitTest>();
}
}