Skip to content

Commit 9154051

Browse files
committed
Merge pull request #22 from ByteBlast/master
Improved test coverage.
2 parents 39ecef2 + 224bcb4 commit 9154051

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ class ControllerResultTestShould
2525
ReturnType<PartialViewResult>(t => t.ShouldRenderPartialView("")),
2626
ReturnType<PartialViewResult>(t => t.ShouldRenderDefaultPartialView()),
2727
ReturnType<FileContentResult>(t => t.ShouldRenderFile()),
28+
ReturnType<FileContentResult>(t => t.ShouldRenderFile("")),
2829
ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream()),
29-
ReturnType<FilePathResult>(t=> t.ShouldRenderFilePath()),
30+
ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream("")),
31+
ReturnType<FilePathResult>(t => t.ShouldRenderFilePath()),
32+
ReturnType<FilePathResult>(t => t.ShouldRenderFilePath("")),
33+
ReturnType<FilePathResult>(t => t.ShouldRenderFilePath("", "")),
3034
ReturnType<FileResult>(t => t.ShouldRenderAnyFile()),
3135
ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
3236
ReturnType<JsonResult>(t => t.ShouldReturnJson()),
@@ -309,12 +313,27 @@ public void Check_for_invalid_partial_name()
309313
public void Check_for_any_file_result()
310314
{
311315
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile();
316+
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderAnyFile();
317+
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderAnyFile();
312318
}
313319

314320
[Test]
315321
public void Check_for_any_file_result_and_check_content_type()
316322
{
317323
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
324+
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
325+
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
326+
}
327+
328+
[Test]
329+
public void Check_for_any_file_result_and_check_invalid_content_type()
330+
{
331+
const string contentType = "application/dummy";
332+
333+
var exception = Assert.Throws<ActionResultAssertionException>(() =>
334+
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(contentType));
335+
336+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, ControllerResultTestController.FileContentType)));
318337
}
319338

320339
[Test]
@@ -341,6 +360,17 @@ public void Check_for_file_stream_result_and_check_content_type()
341360
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderFileStream(ControllerResultTestController.FileContentType);
342361
}
343362

363+
[Test]
364+
public void Check_for_file_stream_result_and_check_invalid_content_type()
365+
{
366+
const string contentType = "application/dummy";
367+
368+
var exception = Assert.Throws<ActionResultAssertionException>(() =>
369+
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(contentType));
370+
371+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, ControllerResultTestController.FileContentType)));
372+
}
373+
344374
[Test]
345375
public void Check_for_file_path_result()
346376
{
@@ -353,11 +383,34 @@ public void Check_for_file_path_result_and_check_file_name()
353383
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName);
354384
}
355385

386+
[Test]
387+
public void Check_for_file_path_result_and_check_invalid_file_name()
388+
{
389+
const string name = "dummy";
390+
391+
var exception = Assert.Throws<ActionResultAssertionException>(() =>
392+
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(name));
393+
394+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file name to be '{0}', but instead was given '{1}'.", name, ControllerResultTestController.FileName)));
395+
}
396+
356397
[Test]
357398
public void Check_for_file_path_result_and_check_file_name_and_check_content_type()
358399
{
359400
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName, ControllerResultTestController.FileContentType);
360401
}
402+
403+
[Test]
404+
public void Check_for_file_path_result_and_check_file_name_and_check_invalid_content_type()
405+
{
406+
const string contentType = "application/dummy";
407+
408+
var exception = Assert.Throws<ActionResultAssertionException>(() =>
409+
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName, contentType));
410+
411+
Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, ControllerResultTestController.FileContentType)));
412+
}
413+
361414
#endregion
362415

363416
#region HTTP Status tests

0 commit comments

Comments
 (0)