diff --git a/NextVersion.txt b/NextVersion.txt index ccbccc3..276cbf9 100644 --- a/NextVersion.txt +++ b/NextVersion.txt @@ -1 +1 @@ -2.2.0 +2.3.0 diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs index 78a4a4f..be8f9f9 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs @@ -26,5 +26,35 @@ public void Check_for_invalid_http_status() ); Assert.That(exception.Message, Is.EqualTo(string.Format("Expected HTTP status code to be '{0}', but instead received a '{1}'.", ControllerResultTestController.Code + 1, ControllerResultTestController.Code))); } + + [Test] + public void Return_the_http_status_result() + { + var expected = _controller.StatusCode(); + var actual = _controller.WithCallTo(c => c.StatusCode()) + .ShouldGiveHttpStatus(); + Assert.That(actual.StatusCode,Is.EqualTo(expected.StatusCode)); + Assert.That(actual.StatusDescription, Is.EqualTo(expected.StatusDescription)); + } + + [Test] + public void Return_the_http_status_result_when_the_assertion_against_integer_is_true() + { + var expected = _controller.StatusCode(); + var actual = _controller.WithCallTo(c => c.StatusCode()) + .ShouldGiveHttpStatus(ControllerResultTestController.Code); + Assert.That(actual.StatusCode, Is.EqualTo(expected.StatusCode)); + Assert.That(actual.StatusDescription, Is.EqualTo(expected.StatusDescription)); + } + + [Test] + public void Return_the_http_status_result_when_the_assertion_against_status_code_enum_is_true() + { + var expected = _controller.StatusCode(); + var actual = _controller.WithCallTo(c => c.StatusCode()) + .ShouldGiveHttpStatus((HttpStatusCode) ControllerResultTestController.Code); + Assert.That(actual.StatusCode, Is.EqualTo(expected.StatusCode)); + Assert.That(actual.StatusDescription, Is.EqualTo(expected.StatusDescription)); + } } } \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs index d4e2dca..d637b7d 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using System.Web.Mvc; using System.Text; using TestStack.FluentMVCTesting.Tests.TestControllers; @@ -80,5 +81,16 @@ public void Emit_readable_error_message_when_the_actual_content_encoding_has_not Assert.That(exception.Message, Is.EqualTo(string.Format("Expected encoding to be equal to {0}, but instead was null.", ControllerResultTestController.TextualContentEncoding.EncodingName))); } + + [Test] + public void Return_the_content_result() + { + var expected = (ContentResult)_controller.Content(); + var actual = _controller.WithCallTo(c => c.Content()) + .ShouldReturnContent(ControllerResultTestController.TextualContent); + Assert.That(actual.Content,Is.EqualTo(expected.Content)); + Assert.That(actual.ContentType, Is.EqualTo(expected.ContentType)); + Assert.That(actual.ContentEncoding, Is.EqualTo(expected.ContentEncoding)); + } } } \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs index 8990602..39024cd 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs @@ -9,5 +9,13 @@ public void Check_for_empty_result() { _controller.WithCallTo(c => c.EmptyResult()).ShouldReturnEmptyResult(); } + + [Test] + public void Return_the_empty_result() + { + var actual = _controller.WithCallTo(c => c.EmptyResult()) + .ShouldReturnEmptyResult(); + Assert.NotNull(actual); + } } } \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs index fdf420d..a83e3be 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs @@ -8,7 +8,27 @@ partial class ControllerResultTestShould [Test] public void Allow_the_object_that_is_returned_to_be_checked() { - _controller.WithCallTo(c => c.Json()).ShouldReturnJson(d => Assert.That(d, Is.EqualTo(ControllerResultTestController.JsonValue))); + _controller.WithCallTo(c => c.Json()) + .ShouldReturnJson(d => Assert.That(d, Is.EqualTo(ControllerResultTestController.JsonValue))); + } + + [Test] + public void Return_the_json_result() + { + var expected = _controller.Json(); + var actual = _controller.WithCallTo(c => c.Json()).ShouldReturnJson(); + Assert.That(actual.Data, Is.EqualTo(expected.Data)); + Assert.That(actual.JsonRequestBehavior, Is.EqualTo(expected.JsonRequestBehavior)); + } + + [Test] + public void Return_the_json_result_when_the_assertion_is_true() + { + var expected = _controller.Json(); + var actual =_controller.WithCallTo(c => c.Json()) + .ShouldReturnJson(d => Assert.That(d, Is.EqualTo(ControllerResultTestController.JsonValue))); + Assert.That(actual.Data, Is.EqualTo(expected.Data)); + Assert.That(actual.JsonRequestBehavior, Is.EqualTo(expected.JsonRequestBehavior)); } } } \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs b/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs index 8d7aa0f..0046460 100644 --- a/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs +++ b/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs @@ -27,7 +27,7 @@ class ControllerResultTestController : Controller #endregion #region Empty, Null and Random Results - public ActionResult EmptyResult() + public EmptyResult EmptyResult() { return new EmptyResult(); } @@ -217,14 +217,14 @@ public ActionResult NotFound() { return HttpNotFound(); } - public ActionResult StatusCode() + public HttpStatusCodeResult StatusCode() { return new HttpStatusCodeResult(Code); } #endregion #region JSON - public ActionResult Json() + public JsonResult Json() { return Json(JsonValue); } diff --git a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldGiveHttpStatus.cs b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldGiveHttpStatus.cs index bf0c37f..92e0f9b 100644 --- a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldGiveHttpStatus.cs +++ b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldGiveHttpStatus.cs @@ -5,12 +5,13 @@ namespace TestStack.FluentMVCTesting { public partial class ControllerResultTest { - public void ShouldGiveHttpStatus() + public HttpStatusCodeResult ShouldGiveHttpStatus() { ValidateActionReturnType(); + return (HttpStatusCodeResult) ActionResult; } - public void ShouldGiveHttpStatus(int status) + public HttpStatusCodeResult ShouldGiveHttpStatus(int status) { ValidateActionReturnType(); @@ -18,11 +19,13 @@ public void ShouldGiveHttpStatus(int status) if (statusCodeResult.StatusCode != status) throw new ActionResultAssertionException(string.Format("Expected HTTP status code to be '{0}', but instead received a '{1}'.", status, statusCodeResult.StatusCode)); + return (HttpStatusCodeResult) ActionResult; } - public void ShouldGiveHttpStatus(HttpStatusCode status) + public HttpStatusCodeResult ShouldGiveHttpStatus(HttpStatusCode status) { ShouldGiveHttpStatus((int)status); + return (HttpStatusCodeResult)ActionResult; } } } \ No newline at end of file diff --git a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnEmptyResult.cs b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnEmptyResult.cs index 0df9206..5b8ec33 100644 --- a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnEmptyResult.cs +++ b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnEmptyResult.cs @@ -4,9 +4,10 @@ namespace TestStack.FluentMVCTesting { public partial class ControllerResultTest { - public void ShouldReturnEmptyResult() + public EmptyResult ShouldReturnEmptyResult() { ValidateActionReturnType(); + return (EmptyResult) ActionResult; } } } \ No newline at end of file diff --git a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnJson.cs b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnJson.cs index 67dcb6d..25ccb0c 100644 --- a/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnJson.cs +++ b/TestStack.FluentMvcTesting/ControllerResultTest/ShouldReturnJson.cs @@ -5,16 +5,18 @@ namespace TestStack.FluentMVCTesting { public partial class ControllerResultTest { - public void ShouldReturnJson() + public JsonResult ShouldReturnJson() { ValidateActionReturnType(); + return (JsonResult) ActionResult; } - public void ShouldReturnJson(Action assertion) + public JsonResult ShouldReturnJson(Action assertion) { ValidateActionReturnType(); var jsonResult = (JsonResult)ActionResult; assertion(jsonResult.Data); + return (JsonResult)ActionResult; } } } \ No newline at end of file