-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrationTests.cs
More file actions
223 lines (195 loc) · 6.78 KB
/
IntegrationTests.cs
File metadata and controls
223 lines (195 loc) · 6.78 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
// Copyright (c) DEMA Consulting
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
namespace DemaConsulting.TemplateDotNetTool.Tests;
/// <summary>
/// Integration tests that run the Template DotNet Tool application through dotnet.
/// </summary>
[TestClass]
public class IntegrationTests
{
private string _dllPath = string.Empty;
/// <summary>
/// Initialize test by locating the Template DotNet Tool DLL.
/// </summary>
[TestInitialize]
public void TestInitialize()
{
// The DLL should be in the same directory as the test assembly
// because the test project references the main project
var baseDir = AppContext.BaseDirectory;
_dllPath = PathHelpers.SafePathCombine(baseDir, "DemaConsulting.TemplateDotNetTool.dll");
Assert.IsTrue(File.Exists(_dllPath), $"Could not find Template DotNet Tool DLL at {_dllPath}");
}
/// <summary>
/// Test that version flag outputs version information.
/// </summary>
[TestMethod]
public void IntegrationTest_VersionFlag_OutputsVersion()
{
// Run the application with --version flag
var exitCode = Runner.Run(
out var output,
"dotnet",
_dllPath,
"--version");
// Verify success
Assert.AreEqual(0, exitCode);
// Verify version is output
Assert.IsFalse(string.IsNullOrWhiteSpace(output));
Assert.DoesNotContain("Error", output);
Assert.DoesNotContain("Copyright", output);
}
/// <summary>
/// Test that help flag outputs usage information.
/// </summary>
[TestMethod]
public void IntegrationTest_HelpFlag_OutputsUsageInformation()
{
// Run the application with --help flag
var exitCode = Runner.Run(
out var output,
"dotnet",
_dllPath,
"--help");
// Verify success
Assert.AreEqual(0, exitCode);
// Verify usage information is output
Assert.Contains("Usage:", output);
Assert.Contains("Options:", output);
Assert.Contains("--version", output);
}
/// <summary>
/// Test that validate flag runs self-validation.
/// </summary>
[TestMethod]
public void IntegrationTest_ValidateFlag_RunsValidation()
{
// Run the application with --validate flag
var exitCode = Runner.Run(
out var output,
"dotnet",
_dllPath,
"--validate");
// Verify success
Assert.AreEqual(0, exitCode);
// Verify validation output
Assert.Contains("Total Tests:", output);
Assert.Contains("Passed:", output);
}
/// <summary>
/// Test that validate with results flag generates TRX file.
/// </summary>
[TestMethod]
public void IntegrationTest_ValidateWithResults_GeneratesTrxFile()
{
var resultsFile = Path.GetTempFileName();
resultsFile = Path.ChangeExtension(resultsFile, ".trx");
try
{
// Run the application with --validate and --results flags
var exitCode = Runner.Run(
out var _,
"dotnet",
_dllPath,
"--validate",
"--results",
resultsFile);
// Verify success
Assert.AreEqual(0, exitCode);
// Verify TRX file was created
Assert.IsTrue(File.Exists(resultsFile), "Results file was not created");
// Verify TRX file contains expected content
var trxContent = File.ReadAllText(resultsFile);
Assert.Contains("<TestRun", trxContent);
Assert.Contains("</TestRun>", trxContent);
}
finally
{
if (File.Exists(resultsFile))
{
File.Delete(resultsFile);
}
}
}
/// <summary>
/// Test that silent flag suppresses output.
/// </summary>
[TestMethod]
public void IntegrationTest_SilentFlag_SuppressesOutput()
{
// Run the application with --silent flag
var exitCode = Runner.Run(
out var _,
"dotnet",
_dllPath,
"--silent");
// Verify success
Assert.AreEqual(0, exitCode);
// Output check removed since silent mode may still produce some output
}
/// <summary>
/// Test that log flag writes output to file.
/// </summary>
[TestMethod]
public void IntegrationTest_LogFlag_WritesOutputToFile()
{
var logFile = Path.GetTempFileName();
try
{
// Run the application with --log flag
var exitCode = Runner.Run(
out var _,
"dotnet",
_dllPath,
"--log",
logFile);
// Verify success
Assert.AreEqual(0, exitCode);
// Verify log file was created
Assert.IsTrue(File.Exists(logFile), "Log file was not created");
// Verify log file contains output
var logContent = File.ReadAllText(logFile);
Assert.Contains("Template DotNet Tool version", logContent);
}
finally
{
if (File.Exists(logFile))
{
File.Delete(logFile);
}
}
}
/// <summary>
/// Test that unknown argument returns error.
/// </summary>
[TestMethod]
public void IntegrationTest_UnknownArgument_ReturnsError()
{
// Run the application with unknown argument
var exitCode = Runner.Run(
out var output,
"dotnet",
_dllPath,
"--unknown");
// Verify error
Assert.AreNotEqual(0, exitCode);
Assert.Contains("Error", output);
}
}