|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.IO; |
3 | 4 | using System.Linq;
|
4 | 5 | using System.Linq.Expressions;
|
5 | 6 | using System.Net;
|
| 7 | +using System.Security.Permissions; |
6 | 8 | using System.Web.Mvc;
|
7 | 9 | using NUnit.Framework;
|
8 | 10 | using TestStack.FluentMVCTesting.Tests.TestControllers;
|
@@ -39,6 +41,7 @@ class ControllerResultTestShould
|
39 | 41 | ReturnType<FilePathResult>(t => t.ShouldRenderFilePath("")),
|
40 | 42 | ReturnType<FilePathResult>(t => t.ShouldRenderFilePath("", "")),
|
41 | 43 | ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream()),
|
| 44 | + ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream(new MemoryStream())), |
42 | 45 | ReturnType<FileResult>(t => t.ShouldRenderAnyFile()),
|
43 | 46 | ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
|
44 | 47 | ReturnType<JsonResult>(t => t.ShouldReturnJson()),
|
@@ -323,6 +326,52 @@ public void Check_for_file_stream_result()
|
323 | 326 | .ShouldRenderFileStream();
|
324 | 327 | }
|
325 | 328 |
|
| 329 | + [Test] |
| 330 | + public void Check_for_file_stream_result_and_check_stream_data() |
| 331 | + { |
| 332 | + _controller |
| 333 | + .WithCallTo(c => c.EmptyStream()) |
| 334 | + .ShouldRenderFileStream(ControllerResultTestController.EmptyStreamContents); |
| 335 | + } |
| 336 | + |
| 337 | + [Test] |
| 338 | + public void Check_for_file_stream_result_and_check_invalid_stream_data() |
| 339 | + { |
| 340 | + var buffer = new byte[] { 1, 2 }; |
| 341 | + var expectedStream = new MemoryStream(buffer); |
| 342 | + |
| 343 | + var exception = Assert.Throws<ActionResultAssertionException>(() => |
| 344 | + _controller |
| 345 | + .WithCallTo(c => c.EmptyStream()) |
| 346 | + .ShouldRenderFileStream(expectedStream) |
| 347 | + ); |
| 348 | + |
| 349 | + var expected = string.Format("[{0}]", string.Join(", ", buffer)); |
| 350 | + var actual = string.Format("[{0}]", string.Join(", ", ControllerResultTestController.EmptyStreamBuffer)); |
| 351 | + var message = string.Format("Expected stream contents to be equal to {0}, but instead was given {1}.", expected, actual); |
| 352 | + |
| 353 | + Assert.That(exception.Message, Is.EqualTo(message)); |
| 354 | + } |
| 355 | + |
| 356 | + [Test] |
| 357 | + public void Check_for_file_stream_result_with_populated_file_and_check_invalid_stream_data() |
| 358 | + { |
| 359 | + var buffer = new byte[] { 1, 2 }; |
| 360 | + var expectedStream = new MemoryStream(buffer); |
| 361 | + |
| 362 | + var exception = Assert.Throws<ActionResultAssertionException>(() => |
| 363 | + _controller |
| 364 | + .WithCallTo(c => c.PopulatedStream()) |
| 365 | + .ShouldRenderFileStream(expectedStream) |
| 366 | + ); |
| 367 | + |
| 368 | + var expected = string.Format("[{0}]", string.Join(", ", buffer)); |
| 369 | + var actual = string.Format("[{0}]", string.Join(", ", ControllerResultTestController.EmptyStreamBuffer)); |
| 370 | + var message = string.Format("Expected stream contents to be equal to {0}, but instead was given {1}.", expected, actual); |
| 371 | + |
| 372 | + Assert.That(exception.Message, Is.EqualTo(message)); |
| 373 | + } |
| 374 | + |
326 | 375 | #region File tests
|
327 | 376 |
|
328 | 377 | [Test]
|
@@ -400,7 +449,7 @@ public void Check_for_file_content_result_and_check_invalid_binary_content_and_c
|
400 | 449 | byte[] contents = { 1, 2 };
|
401 | 450 | const string contentType = "application/dummy";
|
402 | 451 |
|
403 |
| - var exception = Assert.Throws<ActionResultAssertionException>(() => |
| 452 | + var exception = Assert.Throws<ActionResultAssertionException>(() => |
404 | 453 | _controller.WithCallTo(c => c.BinaryFile()).ShouldRenderFileContents(contents, contentType));
|
405 | 454 |
|
406 | 455 | // Assert that the content type validation occurs before that of the actual contents.
|
|
0 commit comments