Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Made ShouldGiveHttpStatus return HttpStatusCodeResult.
Partial implementation of #46.
  • Loading branch information
AlexArchive committed Dec 1, 2014
commit 6eeb03c1f80ea3d1dd4d54d4b424bcd105929f7f
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net;
using System.Web.Mvc;
using NUnit.Framework;
using TestStack.FluentMVCTesting.Tests.TestControllers;

Expand Down Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/ee/e

{
HttpStatusCodeResult expected = _controller.StatusCode();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: The rest of the codebase uses var and Assert.That. Probably worth keeping it consistent.

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here :)

{
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public ActionResult NotFound()
{
return HttpNotFound();
}
public ActionResult StatusCode()
public HttpStatusCodeResult StatusCode()
{
return new HttpStatusCodeResult(Code);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@ namespace TestStack.FluentMVCTesting
{
public partial class ControllerResultTest<T>
{
public void ShouldGiveHttpStatus()
public HttpStatusCodeResult ShouldGiveHttpStatus()
{
ValidateActionReturnType<HttpStatusCodeResult>();
return (HttpStatusCodeResult) ActionResult;
}

public void ShouldGiveHttpStatus(int status)
public HttpStatusCodeResult ShouldGiveHttpStatus(int status)
{
ValidateActionReturnType<HttpStatusCodeResult>();

var statusCodeResult = (HttpStatusCodeResult)ActionResult;

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;
}
}
}