Skip to content

Commit 44dd387

Browse files
committed
Added support for checking for *any* file result.
Partial implementation of #3
1 parent b85136c commit 44dd387

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ControllerResultTestShould
2727
ReturnType<FileContentResult>(t => t.ShouldRenderFile()),
2828
ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream()),
2929
ReturnType<FilePathResult>(t=> t.ShouldRenderFilePath()),
30+
ReturnType<FileResult>(t => t.ShouldRenderAnyFile()),
3031
ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
3132
ReturnType<JsonResult>(t => t.ShouldReturnJson()),
3233
};
@@ -303,6 +304,19 @@ public void Check_for_invalid_partial_name()
303304
#endregion
304305

305306
#region File tests
307+
308+
[Test]
309+
public void Check_for_any_file_result()
310+
{
311+
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile();
312+
}
313+
314+
[Test]
315+
public void Check_for_any_file_result_and_check_content_type()
316+
{
317+
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
318+
}
319+
306320
[Test]
307321
public void Check_for_file_result()
308322
{

TestStack.FluentMvcTesting/ControllerResultTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ public ViewResultTest ShouldRenderDefaultPartialView()
214214

215215
#region File Results
216216

217+
public FileResult ShouldRenderAnyFile(string contentType = null)
218+
{
219+
ValidateActionReturnType<FileResult>();
220+
221+
var fileResult = (FileResult)_actionResult;
222+
223+
if (contentType != null && fileResult.ContentType != contentType)
224+
{
225+
throw new ActionResultAssertionException(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, fileResult.ContentType));
226+
}
227+
228+
return fileResult;
229+
}
230+
217231
public FileContentResult ShouldRenderFile(string contentType = null)
218232
{
219233
ValidateActionReturnType<FileContentResult>();

0 commit comments

Comments
 (0)