Skip to content

Commit 3ad50c9

Browse files
committed
Added support for checking for a file path results' file name.
Partial implementation of #3
1 parent 89f03a4 commit 3ad50c9

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ 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+
334340
#endregion
335341

336342
#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: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,18 @@ public FileStreamResult ShouldRenderFileStream(string contentType = null)
238238
return fileResult;
239239
}
240240

241-
public FilePathResult ShouldRenderFilePath()
241+
public FilePathResult ShouldRenderFilePath(string fileName = 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+
return fileResult;
245253
}
246254

247255
#endregion

0 commit comments

Comments
 (0)