66using System . Web . Mvc ;
77using NUnit . Framework ;
88using TestStack . FluentMVCTesting . Tests . TestControllers ;
9+ using System . Text ;
10+
911
1012namespace TestStack . FluentMVCTesting . Tests
1113{
@@ -31,6 +33,9 @@ class ControllerResultTestShould
3133 ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( ) ) ,
3234 ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] ) ) ,
3335 ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] , "" ) ) ,
36+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" ) ) ,
37+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" , "" ) ) ,
38+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" , "" , Encoding . UTF8 ) ) ,
3439 ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( "" ) ) ,
3540 ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( ) ) ,
3641 ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( "" ) ) ,
@@ -349,26 +354,26 @@ public void Check_for_file_content_result()
349354 [ Test ]
350355 public void Check_for_file_content_result_and_check_binary_content ( )
351356 {
352- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents ) ;
357+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents ) ;
353358 }
354359
355360 [ Test ]
356361 public void Check_for_file_content_result_and_check_invalid_binary_content ( )
357362 {
358363 byte [ ] contents = { 1 , 2 } ;
359364 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
360- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( contents ) ) ;
365+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( contents ) ) ;
361366
362367 Assert . True ( exception . Message . StartsWith ( "Expected file contents to be equal to [" ) ) ;
363368 Assert . True ( exception . Message . EndsWith ( "]." ) ) ;
364369 Assert . True ( string . Join ( ", " , contents ) . All ( exception . Message . Contains ) ) ;
365- Assert . True ( string . Join ( ", " , ControllerResultTestController . FileContents ) . All ( exception . Message . Contains ) ) ;
370+ Assert . True ( string . Join ( ", " , ControllerResultTestController . BinaryFileContents ) . All ( exception . Message . Contains ) ) ;
366371 }
367372
368373 [ Test ]
369374 public void Check_for_file_content_result_and_check_binary_content_and_check_content_type ( )
370375 {
371- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents , ControllerResultTestController . FileContentType ) ;
376+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents , ControllerResultTestController . FileContentType ) ;
372377 }
373378
374379 [ Test ]
@@ -377,7 +382,7 @@ public void Check_for_file_content_result_and_check_invalid_content_type()
377382 const string contentType = "application/dummy" ;
378383
379384 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
380- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents , contentType ) ) ;
385+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents , contentType ) ) ;
381386
382387 Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file to be of content type '{0}', but instead was given '{1}'." , contentType , ControllerResultTestController . FileContentType ) ) ) ;
383388 }
@@ -389,12 +394,83 @@ public void Check_for_file_content_result_and_check_invalid_binary_content_and_c
389394 const string contentType = "application/dummy" ;
390395
391396 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
392- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( contents , contentType ) ) ;
397+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( contents , contentType ) ) ;
398+
399+ // Assert that the content type validation occurs before that of the actual contents.
400+ Assert . That ( exception . Message . Contains ( "content type" ) ) ;
401+ }
402+
403+ [ Test ]
404+ public void Check_for_file_content_result_and_check_textual_contents ( )
405+ {
406+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents ) ;
407+ }
408+
409+ [ Test ]
410+ public void Check_for_file_content_result_and_check_invalid_textual_contents ( )
411+ {
412+ const string contents = "dummy contents" ;
413+
414+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
415+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( contents ) ) ;
416+
417+ Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file contents to be \" {0}\" , but instead was \" {1}\" ." , contents , ControllerResultTestController . TextualFileContents ) ) ) ;
418+ }
419+
420+ [ Test ]
421+ public void Check_for_file_content_result_and_check_textual_content_and_check_content_result ( )
422+ {
423+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , ControllerResultTestController . FileContentType ) ;
424+ }
425+
426+ [ Test ]
427+ public void Check_for_file_content_result_and_check_textual_content_and_check_invalid_content_typet ( )
428+ {
429+ const string contentType = "application/dummy" ;
430+
431+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
432+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , contentType ) ) ;
433+
434+ Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file to be of content type '{0}', but instead was given '{1}'." , contentType , ControllerResultTestController . FileContentType ) ) ) ;
435+ }
436+
437+ [ Test ]
438+ public void Check_for_file_content_result_and_check_invalid_textual_content_and_check_invalid_content_type ( )
439+ {
440+ const string contents = "dummy content" ;
441+ const string contentType = "application/dummy" ;
442+
443+ var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
444+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( contents , contentType ) ) ;
393445
394- // When supplied with both an invalid content type and invalid content, test the content type first .
446+ // Assert that the content type validation occurs before that of the actual contents .
395447 Assert . That ( exception . Message . Contains ( "content type" ) ) ;
396448 }
397449
450+ [ Test ]
451+ public void Check_for_file_content_result_and_check_textual_content_using_given_char_encoding ( )
452+ {
453+ var encoding = Encoding . BigEndianUnicode ;
454+
455+ _controller . WithCallTo ( c => c . TextualFile ( encoding ) )
456+ . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , encoding : encoding ) ;
457+ }
458+
459+ [ Test ]
460+ public void Check_for_file_content_result_and_check_textual_content_using_given_char_encoding_and_check_content_type ( )
461+ {
462+ var encoding = Encoding . BigEndianUnicode ;
463+
464+ _controller . WithCallTo ( c => c . TextualFile ( encoding ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , ControllerResultTestController . FileContentType , encoding ) ;
465+ }
466+
467+ [ Test ]
468+ public void Check_for_file_content_result_and_check_textual_content_using_invalid_given_char_encoding ( )
469+ {
470+ Assert . Throws < ActionResultAssertionException > ( ( ) =>
471+ _controller . WithCallTo ( c => c . TextualFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . TextualFileContents , ControllerResultTestController . FileContentType , Encoding . BigEndianUnicode ) ) ;
472+ }
473+
398474 [ Test ]
399475 public void Check_for_file_result ( )
400476 {
@@ -479,7 +555,7 @@ public void Check_for_file_path_result_and_check_invalid_file_name_and_check_inv
479555 var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
480556 _controller . WithCallTo ( c => c . EmptyFilePath ( ) ) . ShouldRenderFilePath ( name , contentType ) ) ;
481557
482- // When supplied with both an invalid content type and invalid file name, test the content type first .
558+ // Assert that the content type validation occurs before that of the file name .
483559 Assert . That ( exception . Message . Contains ( "content type" ) ) ;
484560 }
485561
0 commit comments