@@ -42,6 +42,8 @@ class ControllerResultTestShould
4242 ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( "" , "" ) ) ,
4343 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( ) ) ,
4444 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new MemoryStream ( ) ) ) ,
45+ ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( contentType : "" ) ) ,
46+ ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( new MemoryStream ( ) , "" ) ) ,
4547 ReturnType < FileResult > ( t => t . ShouldRenderAnyFile ( ) ) ,
4648 ReturnType < HttpStatusCodeResult > ( t => t . ShouldGiveHttpStatus ( ) ) ,
4749 ReturnType < JsonResult > ( t => t . ShouldReturnJson ( ) ) ,
@@ -366,12 +368,53 @@ public void Check_for_file_stream_result_with_populated_file_and_check_invalid_s
366368 ) ;
367369
368370 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 ) ) ;
370372 var message = string . Format ( "Expected stream contents to be equal to {0}, but instead was given {1}." , expected , actual ) ;
371373
372374 Assert . That ( exception . Message , Is . EqualTo ( message ) ) ;
373375 }
374376
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+
375418 #region File tests
376419
377420 [ Test ]
0 commit comments