Skip to content

Instantly share code, notes, and snippets.

View jharmn's full-sized avatar

Jason Harmon jharmn

View GitHub Profile
[When(@"I retrieve the results")]
public void WhenRetrieveTheResults()
{
try
{
this.content = wc.DownloadString(url);
this.httpStatus = HttpStatusCode.OK;
}
catch (WebException we)
{
[Then(@"the status code should be (.*)")]
public void ThenTheStatusCodeShouldBe(int statusCode)
{
Assert.AreEqual(statusCode, (int)this.httpStatus);
}
[Then(@"it should have the field ""(.*)"" containing the value ""(.*)""")]
public void ThenItShouldContainTheFieldContainingTheValue(string field, string value)
{
if (response != null)
{
JValue val = (JValue)this.response.GetValue(field);
string valStr = val.Value().Trim();
Assert.IsNotNull(valStr);
Assert.AreEqual(valStr, value.Trim());
}
[Binding]
public class RestTestSteps
{
private string url;
private string content;
private WebClient wc = new WebClient();
JObject response;
HttpStatusCode httpStatus;
[Given(@"I access the resource url ""(.*)""")]
@Positive @Get @User
Scenario: Show twitter user
Given I access the resource url "/1/users/show.json?screen_name=jasonh_n_austin&include_entities=true"
When I retrieve the results
Then the status code should be 200
And it should have the field "name" containing the value "Jason Harmon"
And it should have the field "id" containing the value "57005215"
Given(~"I access the resource url \"([^\"]*)\"") { String url ->
resp = null
status = null
uri = new URIBuilder(host)
path = url
}
Given(~"I provide parameter \"([^\"]*)\" as \"([^\"]*)\"") { String name, String value ->
uri.addQueryParam name, value
@jharmn
jharmn / gist:4582935
Created January 21, 2013 01:11
Cucumber example
@Positive @Get @User
Scenario: Show twitter user
Given I access the resource url "/1/users/show.json"
And I provide parameter "screen_name" as "jasonh_n_austin"
And I provide parameter "include_entities" as "true"
When I retrieve the results
Then the status code should be 200
And it should have the field "name" containing the value "Jason Harmon"
And it should have the field "id" containing the value "57005215"
@jharmn
jharmn / gist:4582955
Created January 21, 2013 01:18
Groovy cucumber example of JSON parsing
Then(~"it should have the field \"(.*)\" containing the value \"(.*)\"") { String field, String value ->
assert parsed."${field}".toString().equals(value)
}
@jharmn
jharmn / gist:5031772
Last active December 14, 2015 04:59
Slides and retros from #apistrat NYC 2012
Content:
Level 3 REST Makes Your API Browsable - Matt Bishop, Elastic Path
http://www.slideshare.net/matt_bishop5/l3-rest
Platforms are Social – Tyler Singletary, Klout
http://www.slideshare.net/harmophone/api-strategy-harmophone
Adopt a Successful API Product Mindset – Chris Haddad, WS02
http://www.slideshare.net/sa/f9a452c1cddc4cb8ad2c54661f801858
@jharmn
jharmn / gist:5097281
Last active December 14, 2015 13:58
Sample response for PragmaticAPI.com post on Hypermedia for permissions
GET /widget/5
{
"id": 5,
"code": "abc123",
"name": "Widget I know of"
}