@@ -44,6 +44,8 @@ class ControllerResultTestShould
4444 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new MemoryStream ( ) ) ) ,
4545 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( contentType : "" ) ) ,
4646 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new MemoryStream ( ) , "" ) ) ,
47+ ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new byte [ 0 ] ) ) ,
48+ ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new byte [ 0 ] , "" ) ) ,
4749 ReturnType < FileResult > ( t => t . ShouldRenderAnyFile ( ) ) ,
4850 ReturnType < HttpStatusCodeResult > ( t => t . ShouldGiveHttpStatus ( ) ) ,
4951 ReturnType < JsonResult > ( t => t . ShouldReturnJson ( ) ) ,
@@ -415,6 +417,77 @@ public void Check_for_file_stream_result_and_check_invalid_stream_data_and_check
415417 Assert . That ( exception . Message . Contains ( "content type" ) ) ;
416418 }
417419
420+ [ Test ]
421+ public void Check_for_file_stream_result_and_check_binary_contents ( )
422+ {
423+ _controller
424+ . WithCallTo ( c => c . PopulatedStream ( ) )
425+ . ShouldRenderFileStream ( ControllerResultTestController . PopulatedStreamBuffer ) ;
426+ }
427+
428+ [ Test ]
429+ public void Check_for_file_stream_result_and_check_invalid_binary_contents ( )
430+ {
431+ var contents = new byte [ ] { 1 , 2 } ;
432+
433+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
434+ _controller
435+ . WithCallTo ( c => c . PopulatedStream ( ) )
436+ . ShouldRenderFileStream ( contents )
437+ ) ;
438+
439+ var expected = string . Format ( "[{0}]" , string . Join ( ", " , contents ) ) ;
440+ var actual = string . Format ( "[{0}]" , string . Join ( ", " , ControllerResultTestController . PopulatedStreamBuffer ) ) ;
441+ var message = string . Format ( "Expected stream contents to be equal to {0}, but instead was given {1}." , expected , actual ) ;
442+
443+ Assert . That ( exception . Message , Is . EqualTo ( message ) ) ;
444+ }
445+
446+ [ Test ]
447+ public void Check_for_file_stream_result_and_check_binary_contents_and_check_content_type ( )
448+ {
449+ _controller
450+ . WithCallTo ( c => c . PopulatedStream ( ) )
451+ . ShouldRenderFileStream (
452+ ControllerResultTestController . PopulatedStreamBuffer ,
453+ ControllerResultTestController . FileContentType ) ;
454+ }
455+
456+ [ Test ]
457+ public void Check_for_file_stream_result_and_check_binary_contents_and_check_invalid_content_type ( )
458+ {
459+ const string contentType = "application/dummy" ;
460+
461+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
462+ _controller
463+ . WithCallTo ( c => c . EmptyStream ( ) )
464+ . ShouldRenderFileStream (
465+ ControllerResultTestController . PopulatedStreamBuffer ,
466+ contentType )
467+ ) ;
468+
469+ var message =
470+ string . Format ( "Expected stream to be of content type '{0}', but instead was given '{1}'." ,
471+ contentType , ControllerResultTestController . FileContentType ) ;
472+
473+ Assert . That ( exception . Message , Is . EqualTo ( message ) ) ;
474+ }
475+
476+ [ Test ]
477+ public void Check_for_file_stream_result_and_check_invalid_binary_contents_and_check_invalid_content_type ( )
478+ {
479+ var contents = new byte [ ] { 1 , 2 } ;
480+ const string contentType = "application/dummy" ;
481+
482+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
483+ _controller
484+ . WithCallTo ( c => c . EmptyStream ( ) )
485+ . ShouldRenderFileStream ( contents , contentType ) ) ;
486+
487+ // Assert that the content type validation occurs before that of the actual contents.
488+ Assert . That ( exception . Message . Contains ( "content type" ) ) ;
489+ }
490+
418491 #region File tests
419492
420493 [ Test ]
0 commit comments