6
6
using System . Web . Mvc ;
7
7
using NUnit . Framework ;
8
8
using TestStack . FluentMVCTesting . Tests . TestControllers ;
9
+ using System . Text ;
10
+
9
11
10
12
namespace TestStack . FluentMVCTesting . Tests
11
13
{
@@ -31,6 +33,9 @@ class ControllerResultTestShould
31
33
ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( ) ) ,
32
34
ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] ) ) ,
33
35
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 ) ) ,
34
39
ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( "" ) ) ,
35
40
ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( ) ) ,
36
41
ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( "" ) ) ,
@@ -349,26 +354,26 @@ public void Check_for_file_content_result()
349
354
[ Test ]
350
355
public void Check_for_file_content_result_and_check_binary_content ( )
351
356
{
352
- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents ) ;
357
+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents ) ;
353
358
}
354
359
355
360
[ Test ]
356
361
public void Check_for_file_content_result_and_check_invalid_binary_content ( )
357
362
{
358
363
byte [ ] contents = { 1 , 2 } ;
359
364
var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
360
- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( contents ) ) ;
365
+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( contents ) ) ;
361
366
362
367
Assert . True ( exception . Message . StartsWith ( "Expected file contents to be equal to [" ) ) ;
363
368
Assert . True ( exception . Message . EndsWith ( "]." ) ) ;
364
369
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 ) ) ;
366
371
}
367
372
368
373
[ Test ]
369
374
public void Check_for_file_content_result_and_check_binary_content_and_check_content_type ( )
370
375
{
371
- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents , ControllerResultTestController . FileContentType ) ;
376
+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents , ControllerResultTestController . FileContentType ) ;
372
377
}
373
378
374
379
[ Test ]
@@ -377,7 +382,7 @@ public void Check_for_file_content_result_and_check_invalid_content_type()
377
382
const string contentType = "application/dummy" ;
378
383
379
384
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 ) ) ;
381
386
382
387
Assert . That ( exception . Message , Is . EqualTo ( string . Format ( "Expected file to be of content type '{0}', but instead was given '{1}'." , contentType , ControllerResultTestController . FileContentType ) ) ) ;
383
388
}
@@ -389,12 +394,83 @@ public void Check_for_file_content_result_and_check_invalid_binary_content_and_c
389
394
const string contentType = "application/dummy" ;
390
395
391
396
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 ) ) ;
393
445
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 .
395
447
Assert . That ( exception . Message . Contains ( "content type" ) ) ;
396
448
}
397
449
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
+
398
474
[ Test ]
399
475
public void Check_for_file_result ( )
400
476
{
@@ -479,7 +555,7 @@ public void Check_for_file_path_result_and_check_invalid_file_name_and_check_inv
479
555
var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
480
556
_controller . WithCallTo ( c => c . EmptyFilePath ( ) ) . ShouldRenderFilePath ( name , contentType ) ) ;
481
557
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 .
483
559
Assert . That ( exception . Message . Contains ( "content type" ) ) ;
484
560
}
485
561
0 commit comments