Skip to content

Commit 93cd31e

Browse files
committed
Merge pull request #18 from TestStack/file-stream-result-support
Added support for checking for a file stream result
2 parents 9dc9d4d + 2799144 commit 93cd31e

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class ControllerResultTestShould
2525
ReturnType<PartialViewResult>(t => t.ShouldRenderPartialView("")),
2626
ReturnType<PartialViewResult>(t => t.ShouldRenderDefaultPartialView()),
2727
ReturnType<FileContentResult>(t => t.ShouldRenderFile()),
28+
ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream()),
2829
ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
2930
ReturnType<JsonResult>(t => t.ShouldReturnJson()),
3031
};
@@ -311,6 +312,18 @@ public void Check_for_file_result_and_check_content_type()
311312
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderFile(ControllerResultTestController.FileContentType);
312313
}
313314

315+
[Test]
316+
public void Check_for_file_stream_result()
317+
{
318+
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderFileStream();
319+
}
320+
321+
[Test]
322+
public void Check_for_file_stream_result_and_check_content_type()
323+
{
324+
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderFileStream(ControllerResultTestController.FileContentType);
325+
}
326+
314327
#endregion
315328

316329
#region HTTP Status tests

TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Web.Mvc;
1+
using System.IO;
2+
using System.Web.Mvc;
23

34
namespace TestStack.FluentMVCTesting.Tests.TestControllers
45
{
@@ -135,6 +136,12 @@ public ActionResult EmptyFile()
135136
return File(content, FileContentType);
136137
}
137138

139+
public ActionResult EmptyStream()
140+
{
141+
var content = new MemoryStream();
142+
return File(content, FileContentType);
143+
}
144+
138145
public ActionResult NamedView()
139146
{
140147
return View(ViewName);

TestStack.FluentMvcTesting/ControllerResultTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,20 @@ public FileContentResult ShouldRenderFile(string contentType = null)
224224
return fileResult;
225225
}
226226

227+
public FileStreamResult ShouldRenderFileStream(string contentType = null)
228+
{
229+
ValidateActionReturnType<FileStreamResult>();
230+
231+
var fileResult = (FileStreamResult)_actionResult;
232+
233+
if (contentType != null && fileResult.ContentType != contentType)
234+
{
235+
throw new ActionResultAssertionException(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, fileResult.ContentType));
236+
}
237+
238+
return fileResult;
239+
}
240+
227241
#endregion
228242

229243
#region Http Status

0 commit comments

Comments
 (0)