public void RetrievingAClosedIssue(Issue fakeIssue, IssueState issue) { "Given an existing closed issue". f(() => { fakeIssue = FakeIssues.Single(i => i.Status == IssueStatus.Closed); MockIssueStore.Setup(i => i.FindAsync("2")) .Returns(Task.FromResult(fakeIssue)); }); "When it is retrieved". f(() => { Request.RequestUri = _uriIssue2; issue = Client.SendAsync(Request) .Result.Content.ReadAsAsync<IssueState>().Result; }); "Then it should have a 'open' action link". f(() => { var link = issue.Links.FirstOrDefault(l => l.Rel == IssueLinkFactory.Rels.IssueProcessor && l.Action == IssueLinkFactory.Actions.Open); link.ShouldNotBeNull(); link.Href.AbsoluteUri.ShouldEqual( "http://localhost/issueprocessor/2?action=open"); }); }
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("1",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; }); "Then a '200 OK' status is returned" .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then the issue is closed" .f(() => { issue.Status.ShouldEqual(IssueStatus.Closed); MockIssueStore.Verify(i => i.UpdateAsync("1",issue)); }); }
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("")); }); "When a DELETE request is made" .f(() => { 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" .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); }
public void RetrievingAnIssue(IssueState issue, Issue fakeIssue) { "Given an existing issue". f(() => { fakeIssue = FakeIssues.FirstOrDefault(); fakeIssue.LastModified = new DateTime(2013, 9, 4); MockIssueStore.Setup(i => i.FindAsync("1")) .Returns(Task.FromResult(fakeIssue)); }); "When it is retrieved". f(() => { Request.RequestUri = _uriIssue1; Response = Client.SendAsync(Request).Result; issue = Response.Content.ReadAsAsync<IssueState>().Result; }); "Then a lastModified header is returned" .f(() => Response.Content.Headers.LastModified .ShouldEqual(new DateTimeOffset(new DateTime(2013, 9, 4)))); "Then a CacheControl header is returned" .f(() => { Response.Headers.CacheControl.Public.ShouldBeTrue(); Response.Headers.CacheControl.MaxAge.ShouldEqual(TimeSpan.FromMinutes(5)); }); "Then a '200 OK' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then it is returned".f(() => issue.ShouldNotBeNull()); "Then it should have an id".f(() => issue.Id.ShouldEqual(fakeIssue.Id)); "Then it should have a title".f(() => issue.Title.ShouldEqual(fakeIssue.Title)); "Then it should have a description".f(() => issue.Description.ShouldEqual(fakeIssue.Description)); "Then it should have a state".f(() => issue.Status.ShouldEqual(Enum.GetName(typeof(IssueStatus), fakeIssue.Status))); "Then it should have a 'self' link".f(() => { var link = issue.Links.FirstOrDefault(l => l.Rel == LinkFactory.Rels.Self); link.ShouldNotBeNull(); link.Href.AbsoluteUri.ShouldEqual("http://localhost/issue/1"); }); "Then it should have a transition link". f(() => { var link = issue.Links.FirstOrDefault(l => l.Rel == IssueLinkFactory.Rels.IssueProcessor && l.Action == IssueLinkFactory.Actions.Transition); link.ShouldNotBeNull(); link.Href.AbsoluteUri.ShouldEqual("http://localhost/issueprocessor/1?action=transition"); }); }
public void UpdatingAnIssue(Issue fakeIssue, string title) { "Given an existing issue" .f(() => { fakeIssue = FakeIssues.FirstOrDefault(); title = fakeIssue.Title; Console.WriteLine(title); MockIssueStore.Setup(i => i.FindAsync("1")) .Returns(Task.FromResult(fakeIssue)); MockIssueStore.Setup(i => i.UpdateAsync("1", It.IsAny<Issue>())) .Callback<string, object>((a,x)=> fakeIssue = (Issue) x ) .Returns(Task.FromResult("")); }); "When a PATCH request is made" .f(() => { var issue = new Issue(); issue.Description = "Updated description"; issue.Title = title; Request.Method = new HttpMethod("PATCH"); Request.RequestUri = _uriIssue1; Request.Content = new ObjectContent<Issue>( issue, new JsonMediaTypeFormatter()); Response = Client.SendAsync(Request).Result; }); "Then a '200 OK' status is returned" .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then the issue should be updated" .f(() => MockIssueStore.Verify(i => i.UpdateAsync("1",It.IsAny<Issue>()))); "Then the description should be updated" .f(() => fakeIssue.Description.ShouldEqual("Updated description")); "Then the title should not change" .f(() => fakeIssue.Title.ShouldEqual(title)); }
public void UpdatingAnIssueWithNoConflict(Issue fakeIssue) { "Given an existing issue" .f(() => { fakeIssue = FakeIssues.FirstOrDefault(); MockIssueStore.Setup(i => i.FindAsync("1")) .Returns(Task.FromResult(fakeIssue)); MockIssueStore.Setup(i => i.UpdateAsync("1", It.IsAny<object>())) .Returns(Task.FromResult("")); }); "When a PATCH request is made with IfModifiedSince" .f(() => { var issue = new Issue(); issue.Title = "Updated title"; issue.Description = "Updated description"; Request.Method = new HttpMethod("PATCH"); Request.RequestUri = _uriIssue1; Request.Content = new ObjectContent<Issue>(issue, new JsonMediaTypeFormatter()); Request.Headers.IfModifiedSince = fakeIssue.LastModified; Response = Client.SendAsync(Request).Result; }); "Then a 200 OK status is returned" .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then the issue should be updated" .f(() => MockIssueStore.Verify(i => i.UpdateAsync("1", It.IsAny<Object>()))); }
public void RetrievingNonModifiedIssue(IssueState issue, Issue fakeIssue) { "Given an existing issue". f(() => { fakeIssue = FakeIssues.FirstOrDefault(); fakeIssue.LastModified = new DateTime(2013, 9, 4); MockIssueStore.Setup(i => i.FindAsync("1")) .Returns(Task.FromResult(fakeIssue)); }); "When it is retrieved with an IfModifiedSince header". f(() => { Request.RequestUri = _uriIssue1; Request.Headers.IfModifiedSince = fakeIssue.LastModified; Response = Client.SendAsync(Request).Result; // issue = Response.Content.ReadAsAsync<IssueState>().Result; }); //"Then a lastModified header is returned" // .f(() => Response.Content.Headers.LastModified // .ShouldEqual(new DateTimeOffset(new DateTime(2013, 9, 4)))); "Then a CacheControl header is returned" .f(() => { Response.Headers.CacheControl.Public.ShouldBeTrue(); Response.Headers.CacheControl.MaxAge.ShouldEqual(TimeSpan.FromMinutes(5)); }); "Then a '304 NOT MODIFIED' status is returened" .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotModified)); "Then it is not returned" .f(() => Assert.Null(Response.Content)); }
public void RetrievingModifiedIssue(IssueState issue, Issue fakeIssue) { "Given an existing issue". f(() => { fakeIssue = FakeIssues.FirstOrDefault(); fakeIssue.LastModified = new DateTime(2013, 9, 4); MockIssueStore.Setup(i => i.FindAsync("1")) .Returns(Task.FromResult(fakeIssue)); }); "When it is retrieved with an IfModifiedSince header". f(() => { Request.RequestUri = _uriIssue1; Request.Headers.IfModifiedSince = fakeIssue.LastModified .Subtract(TimeSpan.FromDays(1)); Response = Client.SendAsync(Request).Result; issue = Response.Content.ReadAsAsync<IssueState>().Result; }); "Then a lastModified header is returned" .f(() => Response.Content.Headers.LastModified .ShouldEqual(fakeIssue.LastModified)); "Then a CacheControl header is returned" .f(() => { Response.Headers.CacheControl.Public.ShouldBeTrue(); Response.Headers.CacheControl.MaxAge.ShouldEqual(TimeSpan.FromMinutes(5)); }); "Then a '200 OK' status is returened" .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK)); "Then it is not returned" .f(() => issue.ShouldNotBeNull()); }
public async Task<HttpResponseMessage> Post(dynamic newIssue) { var issue = new Issue { Title = newIssue.title, Description = newIssue.description }; await _store.CreateAsync(issue); var response = Request.CreateResponse(HttpStatusCode.Created); response.Headers.Location = _linkFactory.Self(issue.Id).Href; return response; }
public async Task<HttpResponseMessage> Patch(string id, Issue issueUpdate) { var issue = await _store.FindAsync(id); if (issue == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } //foreach (JProperty prop in issueUpdate) //{ // if (prop.Name == "title") // { // issue.Title = prop.Value.ToObject<string>(); // } // else if (prop.Name == "description") // { // issue.Description = prop.Value.ToObject<string>(); // } //} await _store.UpdateAsync(id,issueUpdate); return Request.CreateResponse(HttpStatusCode.OK); }
public void InvalidActionOnAnOpenIssue(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("1",issue)).Returns(Task.FromResult("")); }); "When a POST request is made to the issue processor AND the action is 'unknown'". f(() => { Request.RequestUri = new Uri(_uriProcessor + "action=unknown"); Request.Method = HttpMethod.Post; Response = Client.SendAsync(Request).Result; }); "Then a '400 Bad Request' status is returned". f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.BadRequest)); }
public Task CreateAsync(Issue issue) { throw new System.NotImplementedException(); }