@@ -84,11 +84,11 @@ public void CopyTo_CallMultipleTimesWithStreamSupportingSeeking_ContentIsSeriali
8484 var source = new MockStream ( new byte [ 10 ] , true , true ) ;
8585 var content = new StreamContent ( source ) ;
8686
87- var destination1 = new MemoryStream ( ) ;
87+ using var destination1 = new MemoryStream ( ) ;
8888 content . CopyTo ( destination1 ) ;
8989 Assert . AreEqual ( source . Length , destination1 . Length ) ;
9090
91- var destination2 = new MemoryStream ( ) ;
91+ using var destination2 = new MemoryStream ( ) ;
9292 content . CopyTo ( destination2 ) ;
9393 Assert . AreEqual ( source . Length , destination2 . Length ) ;
9494 }
@@ -101,11 +101,11 @@ public void CopyTo_CallMultipleTimesWithStreamSupportingSeekingPartiallyConsumed
101101 source . Read ( new byte [ consumed ] , 0 , consumed ) ;
102102 var content = new StreamContent ( source ) ;
103103
104- var destination1 = new MemoryStream ( ) ;
104+ using var destination1 = new MemoryStream ( ) ;
105105 content . CopyTo ( destination1 ) ;
106106 Assert . AreEqual ( source . Length - consumed , destination1 . Length ) ;
107107
108- var destination2 = new MemoryStream ( ) ;
108+ using var destination2 = new MemoryStream ( ) ;
109109 content . CopyTo ( destination2 ) ;
110110 Assert . AreEqual ( source . Length - consumed , destination2 . Length ) ;
111111 }
@@ -116,14 +116,14 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeeking_ThrowsInvalid
116116 var source = new MockStream ( new byte [ 10 ] , false , true ) ; // doesn't support seeking.
117117 var content = new StreamContent ( source ) ;
118118
119- var destination1 = new MemoryStream ( ) ;
119+ using var destination1 = new MemoryStream ( ) ;
120120 content . CopyTo ( destination1 ) ;
121121
122122 // Use hardcoded expected length, since source.Length would throw (source stream gets disposed if non-seekable).
123123 Assert . AreEqual ( 10 , destination1 . Length ) ;
124124
125125 // Note that the InvalidOperationException is thrown in CopyToAsync(). It is not thrown inside the task.
126- var destination2 = new MemoryStream ( ) ;
126+ using var destination2 = new MemoryStream ( ) ;
127127 Assert . ThrowsException ( typeof ( InvalidOperationException ) ,
128128 ( ) =>
129129 {
@@ -141,12 +141,12 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeekingButBufferedStr
141141 // multiple times, even though the stream doesn't support seeking.
142142 content . LoadIntoBuffer ( ) ;
143143
144- var destination1 = new MemoryStream ( ) ;
144+ using var destination1 = new MemoryStream ( ) ;
145145 content . CopyTo ( destination1 ) ;
146146 // Use hardcoded expected length, since source.Length would throw (source stream gets disposed if non-seekable)
147147 Assert . AreEqual ( 10 , destination1 . Length ) ;
148148
149- var destination2 = new MemoryStream ( ) ;
149+ using var destination2 = new MemoryStream ( ) ;
150150 content . CopyTo ( destination2 ) ;
151151 Assert . AreEqual ( 10 , destination2 . Length ) ;
152152 }
@@ -163,12 +163,12 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeekingButBufferedStr
163163 // multiple times, even though the stream doesn't support seeking.
164164 content . LoadIntoBuffer ( ) ;
165165
166- var destination1 = new MemoryStream ( ) ;
166+ using var destination1 = new MemoryStream ( ) ;
167167 content . CopyTo ( destination1 ) ;
168168 // Use hardcoded expected length, since source.Length would throw (source stream gets disposed if non-seekable).
169169 Assert . AreEqual ( 10 - consumed , destination1 . Length ) ;
170170
171- var destination2 = new MemoryStream ( ) ;
171+ using var destination2 = new MemoryStream ( ) ;
172172 content . CopyTo ( destination2 ) ;
173173 Assert . AreEqual ( 10 - consumed , destination2 . Length ) ;
174174 }
@@ -185,7 +185,7 @@ public void CopyTo_NoLoadIntoBuffer_NotBuffered()
185185
186186 var content = new StreamContent ( sourceStream ) ;
187187
188- var destination1 = new MemoryStream ( ) ;
188+ using var destination1 = new MemoryStream ( ) ;
189189 content . CopyTo ( destination1 ) ;
190190
191191 Assert . AreEqual ( 10 , destination1 . Length ) ;
@@ -195,7 +195,7 @@ public void CopyTo_NoLoadIntoBuffer_NotBuffered()
195195 var replacedSourceContent = new byte [ 10 ] { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
196196 Array . Copy ( replacedSourceContent , sourceContent , 10 ) ;
197197
198- var destination2 = new MemoryStream ( ) ;
198+ using var destination2 = new MemoryStream ( ) ;
199199 content . CopyTo ( destination2 ) ;
200200 Assert . AreEqual ( 10 , destination2 . Length ) ;
201201 CollectionAssert . AreEqual ( replacedSourceContent , destination2 . ToArray ( ) ) ;
@@ -216,7 +216,7 @@ public void CopyTo_LoadIntoBuffer_Buffered()
216216 // buffer so changing the source stream doesn't change the Content
217217 content . LoadIntoBuffer ( ) ;
218218
219- var destination1 = new MemoryStream ( ) ;
219+ using var destination1 = new MemoryStream ( ) ;
220220 content . CopyTo ( destination1 ) ;
221221
222222 Assert . AreEqual ( 10 , destination1 . Length ) ;
@@ -226,7 +226,7 @@ public void CopyTo_LoadIntoBuffer_Buffered()
226226 var replacedSourceContent = new byte [ 10 ] { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
227227 Array . Copy ( replacedSourceContent , sourceContent , 10 ) ;
228228
229- var destination2 = new MemoryStream ( ) ;
229+ using var destination2 = new MemoryStream ( ) ;
230230 content . CopyTo ( destination2 ) ;
231231 Assert . AreEqual ( 10 , destination2 . Length ) ;
232232 CollectionAssert . AreEqual ( initialSourceContent , destination2 . ToArray ( ) ) ;
@@ -238,7 +238,8 @@ public void ContentReadStream_GetProperty_ReturnOriginalStream()
238238 var source = new MockStream ( new byte [ 10 ] ) ;
239239 var content = new StreamContent ( source ) ;
240240
241- Stream stream = content . ReadAsStream ( ) ;
241+ using Stream stream = content . ReadAsStream ( ) ;
242+
242243 Assert . IsFalse ( stream . CanWrite ) ;
243244 Assert . AreEqual ( source . Length , stream . Length ) ;
244245 Assert . AreEqual ( 0 , source . ReadCount ) ;
@@ -250,9 +251,8 @@ public void ContentReadStream_GetProperty_LoadIntoBuffer_ReturnOriginalStream()
250251 {
251252 var source = new MockStream ( new byte [ 10 ] ) ;
252253 var content = new StreamContent ( source ) ;
253- content . LoadIntoBuffer ( ) ;
254254
255- Stream stream = content . ReadAsStream ( ) ;
255+ using Stream stream = content . ReadAsStream ( ) ;
256256 Assert . IsFalse ( stream . CanWrite ) ;
257257 Assert . AreEqual ( source . Length , stream . Length ) ;
258258 Assert . AreEqual ( 0 , source . ReadCount ) ;
@@ -267,7 +267,7 @@ public void ContentReadStream_GetPropertyPartiallyConsumed_ReturnOriginalStream(
267267 source . Read ( new byte [ consumed ] , 0 , consumed ) ;
268268 var content = new StreamContent ( source ) ;
269269
270- Stream stream = content . ReadAsStream ( ) ;
270+ using Stream stream = content . ReadAsStream ( ) ;
271271 Assert . IsFalse ( stream . CanWrite ) ;
272272 Assert . AreEqual ( source . Length , stream . Length ) ;
273273 Assert . AreEqual ( 1 , source . ReadCount ) ;
@@ -286,9 +286,8 @@ public void ContentReadStream_CheckResultProperties_ValuesRepresentReadOnlyStrea
286286 }
287287
288288 var source = new MockStream ( data ) ;
289-
290289 var content = new StreamContent ( source ) ;
291- Stream contentReadStream = content . ReadAsStream ( ) ;
290+ using Stream contentReadStream = content . ReadAsStream ( ) ;
292291
293292 // The following checks verify that the stream returned passes all read-related properties to the
294293 // underlying MockStream and throws when using write-related members.
0 commit comments