3
3
using System . Linq ;
4
4
using System . Linq . Expressions ;
5
5
using System . Net ;
6
+ using System . Text . RegularExpressions ;
6
7
using System . Web . Mvc ;
7
8
using NUnit . Framework ;
8
9
using TestStack . FluentMVCTesting . Tests . TestControllers ;
@@ -31,6 +32,8 @@ class ControllerResultTestShould
31
32
ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( ) ) ,
32
33
ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] ) ) ,
33
34
ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( new byte [ 0 ] , "" ) ) ,
35
+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" ) ) ,
36
+ ReturnType < FileContentResult > ( t => t . ShouldRenderFileContents ( "" , "" ) ) ,
34
37
ReturnType < FileStreamResult > ( t => t . ShouldRenderFileStream ( "" ) ) ,
35
38
ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( ) ) ,
36
39
ReturnType < FilePathResult > ( t => t . ShouldRenderFilePath ( "" ) ) ,
@@ -349,26 +352,26 @@ public void Check_for_file_content_result()
349
352
[ Test ]
350
353
public void Check_for_file_content_result_and_check_binary_content ( )
351
354
{
352
- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents ) ;
355
+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents ) ;
353
356
}
354
357
355
358
[ Test ]
356
359
public void Check_for_file_content_result_and_check_invalid_binary_content ( )
357
360
{
358
361
byte [ ] contents = { 1 , 2 } ;
359
362
var exception = Assert . Throws < ActionResultAssertionException > ( ( ) =>
360
- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( contents ) ) ;
363
+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( contents ) ) ;
361
364
362
365
Assert . True ( exception . Message . StartsWith ( "Expected file contents to be equal to [" ) ) ;
363
366
Assert . True ( exception . Message . EndsWith ( "]." ) ) ;
364
367
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 ) ) ;
366
369
}
367
370
368
371
[ Test ]
369
372
public void Check_for_file_content_result_and_check_binary_content_and_check_content_type ( )
370
373
{
371
- _controller . WithCallTo ( c => c . File ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . FileContents , ControllerResultTestController . FileContentType ) ;
374
+ _controller . WithCallTo ( c => c . BinaryFile ( ) ) . ShouldRenderFileContents ( ControllerResultTestController . BinaryFileContents , ControllerResultTestController . FileContentType ) ;
372
375
}
373
376
374
377
[ Test ]
@@ -377,7 +380,7 @@ public void Check_for_file_content_result_and_check_invalid_content_type()
377
380
const string contentType = "application/dummy" ;
378
381
379
382
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 ) ) ;
381
384
382
385
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
386
}
@@ -389,7 +392,54 @@ public void Check_for_file_content_result_and_check_invalid_binary_content_and_c
389
392
const string contentType = "application/dummy" ;
390
393
391
394
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 ) ) ;
393
443
394
444
// When supplied with both an invalid content type and invalid content, test the content type first.
395
445
Assert . That ( exception . Message . Contains ( "content type" ) ) ;
0 commit comments