@@ -42,6 +42,8 @@ class ControllerResultTestShould
42
42
ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( "" , "" ) ) ,
43
43
ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( ) ) ,
44
44
ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new MemoryStream ( ) ) ) ,
45
+ ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( contentType : "" ) ) ,
46
+ ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new MemoryStream ( ) , "" ) ) ,
45
47
ReturnType < FileResult > ( t => t . ShouldRenderAnyFile ( ) ) ,
46
48
ReturnType < HttpStatusCodeResult > ( t => t . ShouldGiveHttpStatus ( ) ) ,
47
49
ReturnType < JsonResult > ( t => t . ShouldReturnJson ( ) ) ,
@@ -366,12 +368,53 @@ public void Check_for_file_stream_result_with_populated_file_and_check_invalid_s
366
368
) ;
367
369
368
370
var expected = string . Format ( "[{0}]" , string . Join ( ", " , buffer ) ) ;
369
- var actual = string . Format ( "[{0}]" , string . Join ( ", " , ControllerResultTestController . EmptyStreamBuffer ) ) ;
371
+ var actual = string . Format ( "[{0}]" , string . Join ( ", " , ControllerResultTestController . PopulatedStreamBuffer ) ) ;
370
372
var message = string . Format ( "Expected stream contents to be equal to {0}, but instead was given {1}." , expected , actual ) ;
371
373
372
374
Assert . That ( exception . Message , Is . EqualTo ( message ) ) ;
373
375
}
374
376
377
+ [ Test ]
378
+ public void Check_for_file_stream_result_and_check_content_type ( )
379
+ {
380
+ _controller
381
+ . WithCallTo ( c => c . EmptyStream ( ) )
382
+ . ShouldRenderFileStream ( ControllerResultTestController . EmptyStreamContents ,
383
+ ControllerResultTestController . FileContentType ) ;
384
+ }
385
+
386
+ [ Test ]
387
+ public void Check_for_file_stream_result_and_check_invalid_content_type ( )
388
+ {
389
+ const string contentType = "application/dummy" ;
390
+
391
+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
392
+ _controller
393
+ . WithCallTo ( c => c . EmptyStream ( ) )
394
+ . ShouldRenderFileStream ( ControllerResultTestController . EmptyStreamContents , contentType ) ) ;
395
+
396
+ var message = string . Format (
397
+ "Expected stream to be of content type '{0}', but instead was given '{1}'." , contentType , ControllerResultTestController . FileContentType ) ;
398
+
399
+ Assert . That ( exception . Message , Is . EqualTo ( message ) ) ;
400
+ }
401
+
402
+ [ Test ]
403
+ public void Check_for_file_stream_result_and_check_invalid_stream_data_and_check_invalid_content_type ( )
404
+ {
405
+ var buffer = new byte [ ] { 1 , 2 } ;
406
+ var expectedStream = new MemoryStream ( buffer ) ;
407
+ const string contentType = "application/dummy" ;
408
+
409
+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
410
+ _controller
411
+ . WithCallTo ( c => c . EmptyStream ( ) )
412
+ . ShouldRenderFileStream ( expectedStream , contentType ) ) ;
413
+
414
+ // Assert that the content type validation occurs before that of the actual contents.
415
+ Assert . That ( exception . Message . Contains ( "content type" ) ) ;
416
+ }
417
+
375
418
#region File tests
376
419
377
420
[ Test ]
0 commit comments