@@ -176,6 +176,65 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeekingButBufferedStr
176176 Assert . Equal ( 10 - consumed , destination2 . Length ) ;
177177 }
178178
179+ [ TestMethod ]
180+ public void CopyTo_NoLoadIntoBuffer_NotBuffered ( )
181+ {
182+ var initialSourceContent = new byte [ 10 ] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
183+
184+ var sourceContent = new byte [ 10 ] ;
185+ Array . Copy ( initialSourceContent , sourceContent , 10 ) ;
186+
187+ var sourceStream = new MockStream ( sourceContent , true , true ) ;
188+
189+ var content = new StreamContent ( sourceStream ) ;
190+
191+ var destination1 = new MemoryStream ( ) ;
192+ content . CopyTo ( destination1 ) ;
193+
194+ Assert . AreEqual ( 10 , destination1 . Length ) ;
195+ CollectionAssert . AreEqual ( initialSourceContent , destination1 . ToArray ( ) ) ;
196+
197+ // replace source content to ensure data was not buffered in the content
198+ var replacedSourceContent = new byte [ 10 ] { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
199+ Array . Copy ( replacedSourceContent , sourceContent , 10 ) ;
200+
201+ var destination2 = new MemoryStream ( ) ;
202+ content . CopyTo ( destination2 ) ;
203+ Assert . AreEqual ( 10 , destination2 . Length ) ;
204+ CollectionAssert . AreEqual ( replacedSourceContent , destination2 . ToArray ( ) ) ;
205+ }
206+
207+ [ TestMethod ]
208+ public void CopyTo_LoadIntoBuffer_Buffered ( )
209+ {
210+ var initialSourceContent = new byte [ 10 ] { 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ;
211+
212+ var sourceContent = new byte [ 10 ] ;
213+ Array . Copy ( initialSourceContent , sourceContent , 10 ) ;
214+
215+ var sourceStream = new MockStream ( sourceContent , true , true ) ;
216+
217+ var content = new StreamContent ( sourceStream ) ;
218+
219+ // buffer so changing the source stream doesn't change the Content
220+ content . LoadIntoBuffer ( ) ;
221+
222+ var destination1 = new MemoryStream ( ) ;
223+ content . CopyTo ( destination1 ) ;
224+
225+ Assert . AreEqual ( 10 , destination1 . Length ) ;
226+ CollectionAssert . AreEqual ( initialSourceContent , destination1 . ToArray ( ) ) ;
227+
228+ // replace source content to ensure data was buffered in the content
229+ var replacedSourceContent = new byte [ 10 ] { 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 , 0 } ;
230+ Array . Copy ( replacedSourceContent , sourceContent , 10 ) ;
231+
232+ var destination2 = new MemoryStream ( ) ;
233+ content . CopyTo ( destination2 ) ;
234+ Assert . AreEqual ( 10 , destination2 . Length ) ;
235+ CollectionAssert . AreEqual ( initialSourceContent , destination2 . ToArray ( ) ) ;
236+ }
237+
179238 [ TestMethod ]
180239 public void ContentReadStream_GetProperty_ReturnOriginalStream ( )
181240 {
@@ -189,6 +248,20 @@ public void ContentReadStream_GetProperty_ReturnOriginalStream()
189248 Assert . NotSame ( source , stream ) ;
190249 }
191250
251+ [ TestMethod ]
252+ public void ContentReadStream_GetProperty_LoadIntoBuffer_ReturnOriginalStream ( )
253+ {
254+ var source = new MockStream ( new byte [ 10 ] ) ;
255+ var content = new StreamContent ( source ) ;
256+ content . LoadIntoBuffer ( ) ;
257+
258+ Stream stream = content . ReadAsStream ( ) ;
259+ Assert . IsFalse ( stream . CanWrite ) ;
260+ Assert . AreEqual ( source . Length , stream . Length ) ;
261+ Assert . AreEqual ( 0 , source . ReadCount ) ;
262+ Assert . AreNotSame ( source , stream ) ;
263+ }
264+
192265 [ TestMethod ]
193266 public void ContentReadStream_GetPropertyPartiallyConsumed_ReturnOriginalStream ( )
194267 {
@@ -220,7 +293,7 @@ public void ContentReadStream_CheckResultProperties_ValuesRepresentReadOnlyStrea
220293 var content = new StreamContent ( source ) ;
221294 Stream contentReadStream = content . ReadAsStream ( ) ;
222295
223- // The following checks verify that the stream returned passes all read-related properties to the
296+ // The following checks verify that the stream returned passes all read-related properties to the
224297 // underlying MockStream and throws when using write-related members.
225298
226299 Assert . False ( contentReadStream . CanWrite ) ;
0 commit comments