Skip to content

Commit

Permalink
Improved test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexArchive committed Aug 20, 2014
1 parent 39ecef2 commit 224bcb4
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ class ControllerResultTestShould
ReturnType<PartialViewResult>(t => t.ShouldRenderPartialView("")),
ReturnType<PartialViewResult>(t => t.ShouldRenderDefaultPartialView()),
ReturnType<FileContentResult>(t => t.ShouldRenderFile()),
ReturnType<FileContentResult>(t => t.ShouldRenderFile("")),
ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream()),
ReturnType<FilePathResult>(t=> t.ShouldRenderFilePath()),
ReturnType<FileStreamResult>(t => t.ShouldRenderFileStream("")),
ReturnType<FilePathResult>(t => t.ShouldRenderFilePath()),
ReturnType<FilePathResult>(t => t.ShouldRenderFilePath("")),
ReturnType<FilePathResult>(t => t.ShouldRenderFilePath("", "")),
ReturnType<FileResult>(t => t.ShouldRenderAnyFile()),
ReturnType<HttpStatusCodeResult>(t => t.ShouldGiveHttpStatus()),
ReturnType<JsonResult>(t => t.ShouldReturnJson()),
Expand Down Expand Up @@ -309,12 +313,27 @@ public void Check_for_invalid_partial_name()
public void Check_for_any_file_result()
{
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile();
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderAnyFile();
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderAnyFile();
}

[Test]
public void Check_for_any_file_result_and_check_content_type()
{
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
_controller.WithCallTo(c => c.EmptyStream()).ShouldRenderAnyFile(ControllerResultTestController.FileContentType);
}

[Test]
public void Check_for_any_file_result_and_check_invalid_content_type()
{
const string contentType = "application/dummy";

var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(contentType));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, ControllerResultTestController.FileContentType)));
}

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

[Test]
public void Check_for_file_stream_result_and_check_invalid_content_type()
{
const string contentType = "application/dummy";

var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.EmptyFile()).ShouldRenderAnyFile(contentType));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, ControllerResultTestController.FileContentType)));
}

[Test]
public void Check_for_file_path_result()
{
Expand All @@ -353,11 +383,34 @@ public void Check_for_file_path_result_and_check_file_name()
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName);
}

[Test]
public void Check_for_file_path_result_and_check_invalid_file_name()
{
const string name = "dummy";

var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(name));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file name to be '{0}', but instead was given '{1}'.", name, ControllerResultTestController.FileName)));
}

[Test]
public void Check_for_file_path_result_and_check_file_name_and_check_content_type()
{
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName, ControllerResultTestController.FileContentType);
}

[Test]
public void Check_for_file_path_result_and_check_file_name_and_check_invalid_content_type()
{
const string contentType = "application/dummy";

var exception = Assert.Throws<ActionResultAssertionException>(() =>
_controller.WithCallTo(c => c.EmptyFilePath()).ShouldRenderFilePath(ControllerResultTestController.FileName, contentType));

Assert.That(exception.Message, Is.EqualTo(string.Format("Expected file to be of content type '{0}', but instead was given '{1}'.", contentType, ControllerResultTestController.FileContentType)));
}

#endregion

#region HTTP Status tests
Expand Down

0 comments on commit 224bcb4

Please sign in to comment.