From 3d8d4970cab647324033e4ae16ed52a0dce4879b Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 1 Dec 2014 11:58:49 +0000 Subject: [PATCH 1/6] Added forgotten test. --- .../ShouldReturnContentTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs index d4e2dca..3516a61 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() + { + ContentResult expected = (ContentResult)_controller.Content(); + ContentResult actual = _controller.WithCallTo(c => c.Content()) + .ShouldReturnContent(ControllerResultTestController.TextualContent); + Assert.AreEqual(expected.Content, actual.Content); + Assert.AreEqual(expected.ContentType, actual.ContentType); + Assert.AreEqual(expected.ContentEncoding, actual.ContentEncoding); + } } } \ No newline at end of file From 21c8637d0da4df6788854dddde8dd26382c045e7 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 1 Dec 2014 12:10:32 +0000 Subject: [PATCH 2/6] Made ShouldRenderJson return JsonResult. Partial implementation of #46. --- .../ShouldReturnJsonTests.cs | 25 +++++++++++++++++-- .../ControllerResultTestController.cs | 2 +- .../ControllerResultTest/ShouldReturnJson.cs | 6 +++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs index fdf420d..712e938 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using System.Web.Mvc; +using NUnit.Framework; using TestStack.FluentMVCTesting.Tests.TestControllers; namespace TestStack.FluentMVCTesting.Tests @@ -8,7 +9,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() + { + JsonResult expected = _controller.Json(); + JsonResult actual = _controller.WithCallTo(c => c.Json()).ShouldReturnJson(); + Assert.AreEqual(expected.Data, actual.Data); + Assert.AreEqual(expected.JsonRequestBehavior, actual.JsonRequestBehavior); + } + + [Test] + public void Return_the_json_result_when_the_assertion_is_true() + { + JsonResult expected = _controller.Json(); + JsonResult actual =_controller.WithCallTo(c => c.Json()) + .ShouldReturnJson(d => Assert.That(d, Is.EqualTo(ControllerResultTestController.JsonValue))); + Assert.AreEqual(expected.Data, actual.Data); + Assert.AreEqual(expected.JsonRequestBehavior, actual.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..7e54be5 100644 --- a/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs +++ b/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs @@ -224,7 +224,7 @@ public ActionResult StatusCode() #endregion #region JSON - public ActionResult Json() + public JsonResult Json() { return Json(JsonValue); } 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 From 0ea4632dae79bc898493da1ba5f585331452179e Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 1 Dec 2014 12:14:32 +0000 Subject: [PATCH 3/6] Made ShouldReturnEmptyResult return EmptyResult. Partial implementation of #46. --- .../ShouldReturnEmptyResultTests.cs | 11 ++++++++++- .../TestControllers/ControllerResultTestController.cs | 2 +- .../ControllerResultTest/ShouldReturnEmptyResult.cs | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs index 8990602..8754b28 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using System.Web.Mvc; +using NUnit.Framework; namespace TestStack.FluentMVCTesting.Tests { @@ -9,5 +10,13 @@ public void Check_for_empty_result() { _controller.WithCallTo(c => c.EmptyResult()).ShouldReturnEmptyResult(); } + + [Test] + public void Return_the_empty_result() + { + EmptyResult actual = _controller.WithCallTo(c => c.EmptyResult()) + .ShouldReturnEmptyResult(); + Assert.NotNull(actual); + } } } \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs b/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs index 7e54be5..4f01461 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(); } 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 From 6eeb03c1f80ea3d1dd4d54d4b424bcd105929f7f Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 1 Dec 2014 12:22:21 +0000 Subject: [PATCH 4/6] Made ShouldGiveHttpStatus return HttpStatusCodeResult. Partial implementation of #46. --- .../ShouldGiveHttpStatusTests.cs | 31 +++++++++++++++++++ .../ControllerResultTestController.cs | 2 +- .../ShouldGiveHttpStatus.cs | 9 ++++-- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs index 78a4a4f..c11c62b 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs @@ -1,4 +1,5 @@ using System.Net; +using System.Web.Mvc; using NUnit.Framework; using TestStack.FluentMVCTesting.Tests.TestControllers; @@ -26,5 +27,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() + { + HttpStatusCodeResult expected = _controller.StatusCode(); + HttpStatusCodeResult actual = _controller.WithCallTo(c => c.StatusCode()) + .ShouldGiveHttpStatus(); + Assert.AreEqual(expected.StatusCode, actual.StatusCode); + Assert.AreEqual(expected.StatusDescription, actual.StatusDescription); + } + + [Test] + public void Reeturn_the_http_status_result_when_the_assertion_against_integer_is_true() + { + HttpStatusCodeResult expected = _controller.StatusCode(); + HttpStatusCodeResult actual = _controller.WithCallTo(c => c.StatusCode()) + .ShouldGiveHttpStatus(ControllerResultTestController.Code); + Assert.AreEqual(expected.StatusCode, actual.StatusCode); + Assert.AreEqual(expected.StatusDescription, actual.StatusDescription); + } + + [Test] + public void Reeturn_the_http_status_result_when_the_assertion_against_status_code_enum_is_true() + { + HttpStatusCodeResult expected = _controller.StatusCode(); + HttpStatusCodeResult actual = _controller.WithCallTo(c => c.StatusCode()) + .ShouldGiveHttpStatus((HttpStatusCode) ControllerResultTestController.Code); + Assert.AreEqual(expected.StatusCode, actual.StatusCode); + Assert.AreEqual(expected.StatusDescription, actual.StatusDescription); + } } } \ No newline at end of file diff --git a/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs b/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs index 4f01461..0046460 100644 --- a/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs +++ b/TestStack.FluentMVCTesting.Tests/TestControllers/ControllerResultTestController.cs @@ -217,7 +217,7 @@ public ActionResult NotFound() { return HttpNotFound(); } - public ActionResult StatusCode() + public HttpStatusCodeResult StatusCode() { return new HttpStatusCodeResult(Code); } 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 From aaeaeec037c16f52e689c42e4bd4c7bd83fb80da Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 1 Dec 2014 15:40:52 +0000 Subject: [PATCH 5/6] Minor tweaks. --- .../ShouldGiveHttpStatusTests.cs | 29 +++++++++---------- .../ShouldReturnContentTests.cs | 10 +++---- .../ShouldReturnEmptyResultTests.cs | 5 ++-- .../ShouldReturnJsonTests.cs | 19 ++++++------ 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs index c11c62b..be8f9f9 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldGiveHttpStatusTests.cs @@ -1,5 +1,4 @@ using System.Net; -using System.Web.Mvc; using NUnit.Framework; using TestStack.FluentMVCTesting.Tests.TestControllers; @@ -31,31 +30,31 @@ public void Check_for_invalid_http_status() [Test] public void Return_the_http_status_result() { - HttpStatusCodeResult expected = _controller.StatusCode(); - HttpStatusCodeResult actual = _controller.WithCallTo(c => c.StatusCode()) + var expected = _controller.StatusCode(); + var actual = _controller.WithCallTo(c => c.StatusCode()) .ShouldGiveHttpStatus(); - Assert.AreEqual(expected.StatusCode, actual.StatusCode); - Assert.AreEqual(expected.StatusDescription, actual.StatusDescription); + Assert.That(actual.StatusCode,Is.EqualTo(expected.StatusCode)); + Assert.That(actual.StatusDescription, Is.EqualTo(expected.StatusDescription)); } [Test] - public void Reeturn_the_http_status_result_when_the_assertion_against_integer_is_true() + public void Return_the_http_status_result_when_the_assertion_against_integer_is_true() { - HttpStatusCodeResult expected = _controller.StatusCode(); - HttpStatusCodeResult actual = _controller.WithCallTo(c => c.StatusCode()) + var expected = _controller.StatusCode(); + var actual = _controller.WithCallTo(c => c.StatusCode()) .ShouldGiveHttpStatus(ControllerResultTestController.Code); - Assert.AreEqual(expected.StatusCode, actual.StatusCode); - Assert.AreEqual(expected.StatusDescription, actual.StatusDescription); + Assert.That(actual.StatusCode, Is.EqualTo(expected.StatusCode)); + Assert.That(actual.StatusDescription, Is.EqualTo(expected.StatusDescription)); } [Test] - public void Reeturn_the_http_status_result_when_the_assertion_against_status_code_enum_is_true() + public void Return_the_http_status_result_when_the_assertion_against_status_code_enum_is_true() { - HttpStatusCodeResult expected = _controller.StatusCode(); - HttpStatusCodeResult actual = _controller.WithCallTo(c => c.StatusCode()) + var expected = _controller.StatusCode(); + var actual = _controller.WithCallTo(c => c.StatusCode()) .ShouldGiveHttpStatus((HttpStatusCode) ControllerResultTestController.Code); - Assert.AreEqual(expected.StatusCode, actual.StatusCode); - Assert.AreEqual(expected.StatusDescription, actual.StatusDescription); + 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 3516a61..d637b7d 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnContentTests.cs @@ -85,12 +85,12 @@ public void Emit_readable_error_message_when_the_actual_content_encoding_has_not [Test] public void Return_the_content_result() { - ContentResult expected = (ContentResult)_controller.Content(); - ContentResult actual = _controller.WithCallTo(c => c.Content()) + var expected = (ContentResult)_controller.Content(); + var actual = _controller.WithCallTo(c => c.Content()) .ShouldReturnContent(ControllerResultTestController.TextualContent); - Assert.AreEqual(expected.Content, actual.Content); - Assert.AreEqual(expected.ContentType, actual.ContentType); - Assert.AreEqual(expected.ContentEncoding, actual.ContentEncoding); + 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 8754b28..39024cd 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnEmptyResultTests.cs @@ -1,5 +1,4 @@ -using System.Web.Mvc; -using NUnit.Framework; +using NUnit.Framework; namespace TestStack.FluentMVCTesting.Tests { @@ -14,7 +13,7 @@ public void Check_for_empty_result() [Test] public void Return_the_empty_result() { - EmptyResult actual = _controller.WithCallTo(c => c.EmptyResult()) + var actual = _controller.WithCallTo(c => c.EmptyResult()) .ShouldReturnEmptyResult(); Assert.NotNull(actual); } diff --git a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs index 712e938..a83e3be 100644 --- a/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs +++ b/TestStack.FluentMVCTesting.Tests/ControllerResultTestTests/ShouldReturnJsonTests.cs @@ -1,5 +1,4 @@ -using System.Web.Mvc; -using NUnit.Framework; +using NUnit.Framework; using TestStack.FluentMVCTesting.Tests.TestControllers; namespace TestStack.FluentMVCTesting.Tests @@ -16,20 +15,20 @@ public void Allow_the_object_that_is_returned_to_be_checked() [Test] public void Return_the_json_result() { - JsonResult expected = _controller.Json(); - JsonResult actual = _controller.WithCallTo(c => c.Json()).ShouldReturnJson(); - Assert.AreEqual(expected.Data, actual.Data); - Assert.AreEqual(expected.JsonRequestBehavior, actual.JsonRequestBehavior); + 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() { - JsonResult expected = _controller.Json(); - JsonResult actual =_controller.WithCallTo(c => c.Json()) + var expected = _controller.Json(); + var actual =_controller.WithCallTo(c => c.Json()) .ShouldReturnJson(d => Assert.That(d, Is.EqualTo(ControllerResultTestController.JsonValue))); - Assert.AreEqual(expected.Data, actual.Data); - Assert.AreEqual(expected.JsonRequestBehavior, actual.JsonRequestBehavior); + Assert.That(actual.Data, Is.EqualTo(expected.Data)); + Assert.That(actual.JsonRequestBehavior, Is.EqualTo(expected.JsonRequestBehavior)); } } } \ No newline at end of file From fb7d8f5b70840267d022f3b6d6058919d4883d02 Mon Sep 17 00:00:00 2001 From: ByteBlast Date: Mon, 1 Dec 2014 15:41:27 +0000 Subject: [PATCH 6/6] Bumped minor version. --- NextVersion.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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