diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs index faa5d70..05bd8ba 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests.cs @@ -25,8 +25,12 @@ class ControllerResultTestShould ReturnType(t => t.ShouldRenderPartialView("")), ReturnType(t => t.ShouldRenderDefaultPartialView()), ReturnType(t => t.ShouldRenderFile()), + ReturnType(t => t.ShouldRenderFile("")), ReturnType(t => t.ShouldRenderFileStream()), - ReturnType(t=> t.ShouldRenderFilePath()), + ReturnType(t => t.ShouldRenderFileStream("")), + ReturnType(t => t.ShouldRenderFilePath()), + ReturnType(t => t.ShouldRenderFilePath("")), + ReturnType(t => t.ShouldRenderFilePath("", "")), ReturnType(t => t.ShouldRenderAnyFile()), ReturnType(t => t.ShouldGiveHttpStatus()), ReturnType(t => t.ShouldReturnJson()), @@ -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(() => + _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] @@ -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(() => + _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() { @@ -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(() => + _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(() => + _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