Created
April 17, 2013 22:13
-
-
Save jamiegs/5408193 to your computer and use it in GitHub Desktop.
Nancy Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Tests that a 200 is returned when visiting a page that doesn't exist. | |
/// </summary> | |
[TestMethod] | |
public void ReturnsOkStatusCodeWhenExists() | |
{ | |
var bs = new TestBootStrapper(); | |
var browser = new Browser(bs); | |
var result = browser.Get("/users/", with => with.HttpRequest()); | |
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); | |
} | |
/// <summary> | |
/// Tests that a 404 is returned when visiting a page that doesn't exist. | |
/// </summary> | |
[TestMethod] | |
public void Returns404StatusCodeWhenDoesntExists() | |
{ | |
var bs = new TestBootStrapper(); | |
var browser = new Browser(bs); | |
var result = browser.Get("/usersa/", with => with.HttpRequest()); | |
Assert.AreEqual(HttpStatusCode.NotFound, result.StatusCode); | |
} | |
/// <summary> | |
/// Tests that Json is returned when accepting Json. | |
/// </summary> | |
[TestMethod] | |
public void ReturnsJson() | |
{ | |
var bs = new TestBootStrapper(); | |
var browser = new Browser(bs); | |
var result = browser.Get("/users/1/", with => | |
{ | |
with.HttpRequest(); | |
with.Accept(new MediaRange { Subtype = "json", Type = "application" }); | |
}); | |
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); | |
Assert.AreEqual("application/json", result.Context.Response.ContentType); | |
Debug.WriteLine(result.Body.AsString()); | |
} | |
/// <summary> | |
/// Tests that Bob is returned when requesting users. | |
/// </summary> | |
[TestMethod] | |
public void ReturnsBob() | |
{ | |
var bs = new TestBootStrapper(); | |
var browser = new Browser(bs); | |
var result = browser.Get("/users", with => with.HttpRequest()); | |
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode); | |
Debug.WriteLine(result.Body.AsString()); | |
result.Body["body ul li:first a"].ShouldExist().And.ShouldContain("Bob"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment