33using System . Linq ;
44using System . Linq . Expressions ;
55using System . Net ;
6+ using System . Text . RegularExpressions ;
67using System . Web . Mvc ;
78using NUnit . Framework ;
89using TestStack . FluentMVCTesting . Tests . TestControllers ;
@@ -31,6 +32,8 @@ class ControllerResultTestShould
3132 ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( ) ) ,
3233 ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] ) ) ,
3334 ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] , "" ) ) ,
35+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" ) ) ,
36+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" , "" ) ) ,
3437 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( "" ) ) ,
3538 ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( ) ) ,
3639 ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( "" ) ) ,
@@ -349,26 +352,26 @@ public void Check_for_file_content_result()
349352 [ Test ]
350353 public void Check_for_file_content_result_and_check_binary_content ( )
351354 {
352- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents ) ;
355+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents ) ;
353356 }
354357
355358 [ Test ]
356359 public void Check_for_file_content_result_and_check_invalid_binary_content ( )
357360 {
358361 byte [ ] contents = { 1 , 2 } ;
359362 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
360- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( contents ) ) ;
363+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( contents ) ) ;
361364
362365 Assert . True ( exception . Message . StartsWith ( "Expected file contents to be equal to [" ) ) ;
363366 Assert . True ( exception . Message . EndsWith ( "]." ) ) ;
364367 Assert . True ( string . Join ( ", " , contents ) . All ( exception . Message . Contains ) ) ;
365- Assert . True ( string . Join ( ", " , ControllerResultTestController . FileContents ) . All ( exception . Message . Contains ) ) ;
368+ Assert . True ( string . Join ( ", " , ControllerResultTestController . BinaryFileContents ) . All ( exception . Message . Contains ) ) ;
366369 }
367370
368371 [ Test ]
369372 public void Check_for_file_content_result_and_check_binary_content_and_check_content_type ( )
370373 {
371- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents , ControllerResultTestController . FileContentType ) ;
374+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents , ControllerResultTestController . FileContentType ) ;
372375 }
373376
374377 [ Test ]
@@ -377,7 +380,7 @@ public void Check_for_file_content_result_and_check_invalid_content_type()
377380 const string contentType = "application/dummy" ;
378381
379382 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
380- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents , contentType ) ) ;
383+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents , contentType ) ) ;
381384
382385 Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file to be of content type '{0}', but instead was given '{1}'." , contentType , ControllerResultTestController . FileContentType ) ) ) ;
383386 }
@@ -389,7 +392,54 @@ public void Check_for_file_content_result_and_check_invalid_binary_content_and_c
389392 const string contentType = "application/dummy" ;
390393
391394 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
392- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( contents , contentType ) ) ;
395+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( contents , contentType ) ) ;
396+
397+ // When supplied with both an invalid content type and invalid content, test the content type first.
398+ Assert . That ( exception . Message . Contains ( "content type" ) ) ;
399+ }
400+
401+ [ Test ]
402+ public void Check_for_file_content_result_and_check_textual_contents ( )
403+ {
404+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents ) ;
405+ }
406+
407+ [ Test ]
408+ public void Check_for_file_content_result_and_check_invalid_textual_contents ( )
409+ {
410+ const string contents = "dummy contents" ;
411+
412+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
413+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( contents ) ) ;
414+
415+ Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file contents to be \" {0}\" , but instead was \" {1}\" ." , contents , ControllerResultTestController . TextualFileContents ) ) ) ;
416+ }
417+
418+ [ Test ]
419+ public void Check_for_file_content_result_and_check_textual_content_and_check_content_result ( )
420+ {
421+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , ControllerResultTestController . FileContentType ) ;
422+ }
423+
424+ [ Test ]
425+ public void Check_for_file_content_result_and_check_textual_content_and_check_invalid_content_result ( )
426+ {
427+ const string contentType = "application/dummy" ;
428+
429+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
430+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , contentType ) ) ;
431+
432+ Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file to be of content type '{0}', but instead was given '{1}'." , contentType , ControllerResultTestController . FileContentType ) ) ) ;
433+ }
434+
435+ [ Test ]
436+ public void Check_for_file_content_result_and_check_invalid_textual_content_and_check_invalid_content_result ( )
437+ {
438+ const string contents = "dummy content" ;
439+ const string contentType = "application/dummy" ;
440+
441+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
442+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( contents , contentType ) ) ;
393443
394444 // When supplied with both an invalid content type and invalid content, test the content type first.
395445 Assert . That ( exception . Message . Contains ( "content type" ) ) ;
0 commit comments