@@ -43,14 +43,12 @@ public void Validation_Run_WithTrxResultsFile_WritesTrxFile()
4343 var trxFile = Path . Combine ( tempDir , "results.trx" ) ;
4444 var args = new [ ] { "--validate" , "--results" , trxFile } ;
4545
46- StringWriter ? outputWriter = null ;
47- StringWriter ? errorWriter = null ;
46+ using var outputWriter = new StringWriter ( ) ;
47+ using var errorWriter = new StringWriter ( ) ;
4848
4949 try
5050 {
5151 // Capture console output
52- outputWriter = new StringWriter ( ) ;
53- errorWriter = new StringWriter ( ) ;
5452 Console . SetOut ( outputWriter ) ;
5553 Console . SetError ( errorWriter ) ;
5654
@@ -73,9 +71,6 @@ public void Validation_Run_WithTrxResultsFile_WritesTrxFile()
7371 Console . SetOut ( standardOutput ) ;
7472 var standardError = new StreamWriter ( Console . OpenStandardError ( ) ) { AutoFlush = true } ;
7573 Console . SetError ( standardError ) ;
76-
77- outputWriter ? . Dispose ( ) ;
78- errorWriter ? . Dispose ( ) ;
7974 }
8075 }
8176 finally
@@ -103,14 +98,12 @@ public void Validation_Run_WithXmlResultsFile_WritesJUnitFile()
10398 var xmlFile = Path . Combine ( tempDir , "results.xml" ) ;
10499 var args = new [ ] { "--validate" , "--results" , xmlFile } ;
105100
106- StringWriter ? outputWriter = null ;
107- StringWriter ? errorWriter = null ;
101+ using var outputWriter = new StringWriter ( ) ;
102+ using var errorWriter = new StringWriter ( ) ;
108103
109104 try
110105 {
111106 // Capture console output
112- outputWriter = new StringWriter ( ) ;
113- errorWriter = new StringWriter ( ) ;
114107 Console . SetOut ( outputWriter ) ;
115108 Console . SetError ( errorWriter ) ;
116109
@@ -133,9 +126,6 @@ public void Validation_Run_WithXmlResultsFile_WritesJUnitFile()
133126 Console . SetOut ( standardOutput ) ;
134127 var standardError = new StreamWriter ( Console . OpenStandardError ( ) ) { AutoFlush = true } ;
135128 Console . SetError ( standardError ) ;
136-
137- outputWriter ? . Dispose ( ) ;
138- errorWriter ? . Dispose ( ) ;
139129 }
140130 }
141131 finally
@@ -163,12 +153,11 @@ public void Validation_Run_WithUnsupportedResultsFileExtension_ShowsError()
163153 var unsupportedFile = Path . Combine ( tempDir , "results.json" ) ;
164154 var args = new [ ] { "--validate" , "--results" , unsupportedFile } ;
165155
166- StringWriter ? outputWriter = null ;
156+ using var outputWriter = new StringWriter ( ) ;
167157
168158 try
169159 {
170160 // Capture console output
171- outputWriter = new StringWriter ( ) ;
172161 Console . SetOut ( outputWriter ) ;
173162
174163 // Act
@@ -184,8 +173,6 @@ public void Validation_Run_WithUnsupportedResultsFileExtension_ShowsError()
184173 // Restore console output
185174 var standardOutput = new StreamWriter ( Console . OpenStandardOutput ( ) ) { AutoFlush = true } ;
186175 Console . SetOut ( standardOutput ) ;
187-
188- outputWriter ? . Dispose ( ) ;
189176 }
190177 }
191178 finally
@@ -208,12 +195,11 @@ public void Validation_Run_WithInvalidResultsFilePath_ShowsError()
208195 var invalidPath = Path . Combine ( "/invalid_path_that_does_not_exist_12345678" , "results.trx" ) ;
209196 var args = new [ ] { "--validate" , "--results" , invalidPath } ;
210197
211- StringWriter ? outputWriter = null ;
198+ using var outputWriter = new StringWriter ( ) ;
212199
213200 try
214201 {
215202 // Capture console output
216- outputWriter = new StringWriter ( ) ;
217203 Console . SetOut ( outputWriter ) ;
218204
219205 // Act
@@ -229,8 +215,6 @@ public void Validation_Run_WithInvalidResultsFilePath_ShowsError()
229215 // Restore console output
230216 var standardOutput = new StreamWriter ( Console . OpenStandardOutput ( ) ) { AutoFlush = true } ;
231217 Console . SetOut ( standardOutput ) ;
232-
233- outputWriter ? . Dispose ( ) ;
234218 }
235219 }
236220}
0 commit comments