Skip to content

Commit

Permalink
* aligned tabulation of step bodies
Browse files Browse the repository at this point in the history
* added readonly to fields
* converted step to "And..." where appropriate
* removed redundant usings
* removed redundant blank lines
* made abstract type constructors protected
* converted list creation to initializer
  • Loading branch information
adamralph committed Dec 5, 2014
1 parent 79cecbd commit a460ca3
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ namespace WebApiBook.IssueTrackerApp.AcceptanceTests.Features
{
public class CreatingIssues : IssuesFeature
{
private Uri _issues = new Uri("http://localhost/issue");
private readonly Uri _issues = new Uri("http://localhost/issue");

[Scenario]
public void CreatingANewIssue(dynamic newIssue)
{
"Given a new issue".
f(() =>
{
newIssue = new JObject();
newIssue.description = "A new issue";
newIssue.title = "NewIssue";
MockIssueStore.Setup(i => i.CreateAsync(It.IsAny<Issue>())).Returns<Issue>( issue=>
{
issue.Id = "1";
return Task.FromResult("");
});
});
{
newIssue = new JObject();
newIssue.description = "A new issue";
newIssue.title = "NewIssue";
MockIssueStore.Setup(i => i.CreateAsync(It.IsAny<Issue>())).Returns<Issue>( issue=>
{
issue.Id = "1";
return Task.FromResult("");
});
});
"When a POST request is made".
f(() =>
{
Request.Method = HttpMethod.Post;
Request.RequestUri = _issues;
Request.Content = new ObjectContent<dynamic>(newIssue, new JsonMediaTypeFormatter());
Response = Client.SendAsync(Request).Result;
});
{
Request.Method = HttpMethod.Post;
Request.RequestUri = _issues;
Request.Content = new ObjectContent<dynamic>(newIssue, new JsonMediaTypeFormatter());
Response = Client.SendAsync(Request).Result;
});
"Then the issue should be added".
f(() => MockIssueStore.Verify(i => i.CreateAsync(It.IsAny<Issue>())));
"Then a '201 Created' status is returned".
"And a '201 Created' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.Created));
"Then the response location header will be set to the resource location".
"And the response location header will be set to the resource location".
f(() => Response.Headers.Location.AbsoluteUri.ShouldEqual("http://localhost/issue/1"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ namespace WebApiBook.IssueTrackerApp.AcceptanceTests.Features
{
public class DeletingIssues : IssuesFeature
{
private Uri _uriIssue = new Uri("http://localhost/issue/1");
private readonly Uri _uriIssue = new Uri("http://localhost/issue/1");

[Scenario]
public void DeletingAnIssue(Issue fakeIssue)
{
"Given an existing issue".
f(() =>
{
fakeIssue = FakeIssues.FirstOrDefault();
MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult(fakeIssue));
MockIssueStore.Setup(i => i.DeleteAsync("1")).Returns(Task.FromResult(""));
});
{
fakeIssue = FakeIssues.FirstOrDefault();
MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult(fakeIssue));
MockIssueStore.Setup(i => i.DeleteAsync("1")).Returns(Task.FromResult(""));
});
"When a DELETE request is made".
f(() =>
{
Request.RequestUri = _uriIssue;
Request.Method = HttpMethod.Delete;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = _uriIssue;
Request.Method = HttpMethod.Delete;
Response = Client.SendAsync(Request).Result;
});
"Then the issue should be removed".
f(() => MockIssueStore.Verify(i => i.DeleteAsync("1")));
"Then a '200 OK status' is returned".
"And a '200 OK status' is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
}

Expand All @@ -43,11 +43,11 @@ public void DeletingAnIssueThatDoesNotExist()
f(() => MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult((Issue) null)));
"When a DELETE request is made".
f(() =>
{
Request.RequestUri = _uriIssue;
Request.Method = HttpMethod.Delete;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = _uriIssue;
Request.Method = HttpMethod.Delete;
Response = Client.SendAsync(Request).Result;
});
"Then a '404 Not Found' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Moq;
using Newtonsoft.Json.Linq;
using Should;
using WebApiBook.IssueTrackerApi.Models;
using Xbehave;
Expand All @@ -13,33 +11,33 @@ namespace WebApiBook.IssueTrackerApp.AcceptanceTests.Features
{
public class ProcessingIssues : IssuesFeature
{
private string _uriProcessor = "http://localhost/issueprocessor/1?";
private readonly string _uriProcessor = "http://localhost/issueprocessor/1?";

[Scenario]
public void ClosingAnOpenIssue(Issue issue)
{
"Given an existing open issue".
f(() =>
{
issue = FakeIssues.FirstOrDefault(i => i.Status == IssueStatus.Open);
MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult(issue));
MockIssueStore.Setup(i => i.UpdateAsync(issue)).Returns(Task.FromResult(""));
});
{
issue = FakeIssues.FirstOrDefault(i => i.Status == IssueStatus.Open);
MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult(issue));
MockIssueStore.Setup(i => i.UpdateAsync(issue)).Returns(Task.FromResult(""));
});
"When a POST request is made to the issue processor AND the action is 'close'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '200 OK' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
"Then the issue is closed".
"And the issue is closed".
f(() =>
{
issue.Status.ShouldEqual(IssueStatus.Closed);
MockIssueStore.Verify(i => i.UpdateAsync(issue));
});
{
issue.Status.ShouldEqual(IssueStatus.Closed);
MockIssueStore.Verify(i => i.UpdateAsync(issue));
});
}

[Scenario]
Expand All @@ -54,14 +52,14 @@ public void TransitioningAnOpenIssue(Issue issue)
});
"When a POST request is made to the issue processor AND the action is 'transition'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=transition");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=transition");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '200 OK' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
"Then the issue is closed".
"And the issue is closed".
f(() =>
{
issue.Status.ShouldEqual(IssueStatus.Closed);
Expand All @@ -81,35 +79,35 @@ public void ClosingAClosedIssue(Issue issue)
});
"When a POST request is made to the issue processor AND the action is 'close'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '200 OK' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.BadRequest));
}

[Scenario]
public void OpeningAClosedIssue(Issue issue)
{
"Given an existing closed issue".
f(() =>
"Given an existing closed issue".
f(() =>
{
issue = FakeIssues.FirstOrDefault(i => i.Status == IssueStatus.Closed);
MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult(issue));
MockIssueStore.Setup(i => i.UpdateAsync(issue)).Returns(Task.FromResult(""));
});
"When a POST request is made to the issue processor AND the action is 'open'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=open");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=open");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '200 OK' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
"Then the issue is closed".
"And the issue is closed".
f(() =>
{
issue.Status.ShouldEqual(IssueStatus.Open);
Expand All @@ -129,14 +127,14 @@ public void TransitioningAClosedIssue(Issue issue)
});
"When a POST request is made to the issue processor AND the action is 'open'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=open");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=open");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '200 OK' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
"Then the issue is closed".
"And the issue is closed".
f(() =>
{
issue.Status.ShouldEqual(IssueStatus.Open);
Expand All @@ -156,11 +154,11 @@ public void OpeningAnOpenIssue(Issue issue)
});
"When a POST request is made to the issue processor AND the action is 'open'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '400 Bad Request' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.BadRequest));
}
Expand All @@ -172,11 +170,11 @@ public void OpeningAnIssueThatDoesNotExist()
f(() => MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult((Issue)null)));
"When a POST request is made to the issue processor AND the action is 'open'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=open");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=open");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '404 Not Found' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));
}
Expand All @@ -188,11 +186,11 @@ public void ClosingAnIssueThatDoesNotExist()
f(() => MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult((Issue)null)));
"When a POST request is made to the issue processor AND the action is 'close'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=close");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '404 Not Found' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));
}
Expand All @@ -204,15 +202,13 @@ public void TransitioningAnIssueThatDoesNotExist()
f(() => MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult((Issue)null)));
"When a POST request is made to the issue processor AND the action is 'transition'".
f(() =>
{
Request.RequestUri = new Uri(_uriProcessor + "action=transition");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
{
Request.RequestUri = new Uri(_uriProcessor + "action=transition");
Request.Method = HttpMethod.Post;
Response = Client.SendAsync(Request).Result;
});
"Then a '404 Not Found' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));

}

}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Should;
using Tavis.Home;
using WebApiBook.IssueTrackerApi.Infrastructure;
using WebApiBook.IssueTrackerApi.Models;
using Xbehave;

namespace WebApiBook.IssueTrackerApp.AcceptanceTests.Features
{
public class RetreivingHome : HomeFeature
{
private Uri _uriHome = new Uri("http://localhost/");
private readonly Uri _uriHome = new Uri("http://localhost/");

[Scenario]
public void RetrievingHomeRepresentation(HomeDocument home)
{

"When it is retrieved".
f(() =>
{
Expand All @@ -31,17 +25,16 @@ public void RetrievingHomeRepresentation(HomeDocument home)
});
"Then a '200 OK' status is returned".
f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
"Then it is returned".
"And it is returned".
f(() => home.ShouldNotBeNull());
"Then it should have an issueprocessor link".
"And it should have an issueprocessor link".
f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.IssueProcessor).ShouldNotBeNull());
"Then it should have an issue link".
"And it should have an issue link".
f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.Issue).ShouldNotBeNull());
"Then it should have an issues link".
"And it should have an issues link".
f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.Issues).ShouldNotBeNull());
"Then it should have an search link".
"And it should have an search link".
f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.SearchQuery).ShouldNotBeNull());

}
}
}
Loading

0 comments on commit a460ca3

Please sign in to comment.