Skip to content

Commit a77895c

Browse files
committed
Merge pull request #20 from ByteBlast/master
Added support for checking for a file path results' file name and content type.
2 parents 89f03a4 + 0f0dd57 commit a77895c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,18 @@ public void Check_for_file_path_result()
331331
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath();
332332
}
333333

334+
[Test]
335+
public void Check_for_file_path_result_and_check_file_name()
336+
{
337+
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName);
338+
}
339+
340+
[Test]
341+
public void Check_for_file_path_result_and_check_file_name_and_check_content_type()
342+
{
343+
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName, ControllerResultTestController.FileContentType);
344+
}
345+
334346
#endregion
335347

336348
#region HTTP Status tests

TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class ControllerResultTestController : Controller
1414
public const string RandomViewName = "Random";
1515
public const int Code = 403;
1616
public const string JsonValue = "json";
17+
public const string FileName = "NamedFile";
1718
#endregion
1819

1920
#region Empty, Null and Random Results
@@ -144,7 +145,7 @@ public ActionResult EmptyStream()
144145

145146
public ActionResult EmptyFilePath()
146147
{
147-
return File("dummy", FileContentType);
148+
return File(FileName, FileContentType);
148149
}
149150

150151
public ActionResult NamedView()

TestStack.FluentMvcTesting/ControllerResultTest.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,23 @@ public FileStreamResult ShouldRenderFileStream(string contentType = null)
238238
return fileResult;
239239
}
240240

241-
public FilePathResult ShouldRenderFilePath()
241+
public FilePathResult ShouldRenderFilePath(string fileName = null, string contentType = null)
242242
{
243243
ValidateActionReturnType<FilePathResult>();
244-
return (FilePathResult)_actionResult;
244+
245+
var fileResult = (FilePathResult) _actionResult;
246+
247+
if (fileName != null && fileName != fileResult.FileName)
248+
{
249+
throw new ActionResultAssertionException(string.Format("Expected file name to be '{0}', but instead was given '{1}'.", fileName, fileResult.FileName));
250+
}
251+
252+
if (contentType != null && fileResult.ContentType != contentType)
253+
{
254+
throw new ActionResultAssertionException(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, fileResult.ContentType));
255+
}
256+
257+
return fileResult;
245258
}
246259

247260
#endregion

0 commit comments

Comments
 (0)