Example #1
0
        public void OpeningAClosedIssue()
        {
            var issue = FakeIssues.FirstOrDefault(i => i.Status == IssueStatus.Closed);

            "Given an existing closed issue".
            f(() =>
            {
                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 'open'".
            f(() =>
            {
                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".
            f(() =>
            {
                issue.Status.ShouldEqual(IssueStatus.Open);
                MockIssueStore.Verify(i => i.UpdateAsync("1", issue));
            });
        }
Example #2
0
        public void UpdatingAnIssue()
        {
            var fakeIssue = FakeIssues.FirstOrDefault();

            "Given an existing issue".
            f(() =>
            {
                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".
            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());
                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 <JObject>())));
        }
Example #3
0
 public void SearchingIssues(IssuesState issuesState)
 {
     "Given existing issues".
     f(() => MockIssueStore.Setup(i => i.FindAsyncQuery("another")).Returns(Task.FromResult(FakeIssues.Where(i => i.Id == "2"))));
     "When issues are searched".
     f(() =>
     {
         Request.RequestUri = new Uri(_uriIssues, "?searchtext=another");
         Response           = Client.SendAsync(Request).Result;
         issuesState        = Response.Content.ReadAsAsync <IssuesState>().Result;
     });
     "Then a '200 OK' status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
     "Then the collection should have a 'self' link".
     f(() =>
     {
         var link = issuesState.Links.FirstOrDefault(l => l.Rel == IssueLinkFactory.Rels.Self);
         link.ShouldNotBeNull();
         link.Href.AbsoluteUri.ShouldEqual("http://localhost/issue?searchtext=another");
     });
     "Then the matching issues are returned".
     f(() =>
     {
         var issue = issuesState.Issues.FirstOrDefault();
         issue.ShouldNotBeNull();
         issue.Id.ShouldEqual("2");
     });
 }
Example #4
0
 public void UpdatingAnIssue(Issue fakeIssue, string title)
 {
     "Given an existing issue".
     f(() =>
     {
         fakeIssue = FakeIssues.FirstOrDefault();
         title     = fakeIssue.Title;
         MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult(fakeIssue));
         MockIssueStore.Setup(i => i.UpdateAsync(It.IsAny <Issue>())).Returns(Task.FromResult(""));
     });
     "When a PATCH request is made".
     f(() =>
     {
         dynamic issue      = new JObject();
         issue.description  = "Updated description";
         Request.Method     = new HttpMethod("PATCH");
         Request.RequestUri = _uriIssue1;
         Request.Content    = new ObjectContent <dynamic>(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(It.IsAny <Issue>())));
     "Then the descripton should be updated".
     f(() => fakeIssue.Description.ShouldEqual("Updated description"));
     "Then the title should not change".
     f(() => fakeIssue.Title.ShouldEqual(title));
 }
Example #5
0
        public void RetrievingAllIssuesAsCollectionJson(IReadDocument readDocument)
        {
            "Given existing issues".
            f(() => MockIssueStore.Setup(i => i.FindAsync()).Returns(Task.FromResult(FakeIssues)));
            "When all issues are retrieved as Collection+Json".
            f(() =>
            {
                Request.RequestUri = _uriIssues;
                Request.Headers.Accept.Clear();
                Request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.collection+json"));
                Response     = Client.SendAsync(Request).Result;
                readDocument = Response.Content.ReadAsAsync <ReadDocument>(new[] { new CollectionJsonFormatter() }).Result;
            });
            "Then a '200 OK' status is returned".
            f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then Collection+Json is returned".
            f(() => readDocument.ShouldNotBeNull());
            "Then the href should be set".
            f(() => readDocument.Collection.Href.AbsoluteUri.ShouldEqual("http://localhost/issue"));
            "Then all issues are returned".
            f(() =>
            {
                readDocument.Collection.Items.FirstOrDefault(i => i.Href.AbsoluteUri == "http://localhost/issue/1").ShouldNotBeNull();
                readDocument.Collection.Items.FirstOrDefault(i => i.Href.AbsoluteUri == "http://localhost/issue/2").ShouldNotBeNull();
            });

            "Then the search query is returned".
            f(() => readDocument.Collection.Queries.SingleOrDefault(
                  q => q.Rel == IssueLinkFactory.Rels.SearchQuery).ShouldNotBeNull());
        }
Example #6
0
 public void RetrievingAllIssues(IssuesState issuesState)
 {
     "Given existing issues".
     f(() => MockIssueStore.Setup(i => i.FindAsync()).Returns(Task.FromResult(FakeIssues)));
     "When all issues are retrieved".
     f(() =>
     {
         Request.RequestUri = _uriIssues;
         Response           = Client.SendAsync(Request).Result;
         issuesState        = Response.Content.ReadAsAsync <IssuesState>().Result;
     });
     "Then a '200 OK' status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
     "Then they are returned".
     f(() =>
     {
         issuesState.Issues.FirstOrDefault(i => i.Id == "1").ShouldNotBeNull();
         issuesState.Issues.FirstOrDefault(i => i.Id == "2").ShouldNotBeNull();
     });
     "Then the collection should have a 'self' link".
     f(() =>
     {
         var link = issuesState.Links.FirstOrDefault(l => l.Rel == IssueLinkFactory.Rels.Self);
         link.ShouldNotBeNull();
         link.Href.AbsoluteUri.ShouldEqual("http://localhost/issue");
     });
 }
Example #7
0
 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(""));
         });
     });
     "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;
     });
     "Then the issue should be added".
     f(() => MockIssueStore.Verify(i => i.CreateAsync(It.IsAny <Issue>())));
     "And a '201 Created' status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.Created));
     "And the response location header will be set to the resource location".
     f(() => Response.Headers.Location.AbsoluteUri.ShouldEqual("http://localhost/issue/1"));
 }
Example #8
0
        public void CreatingANewIssue()
        {
            Issue issue = null;

            "Given a new issue".
            f(() =>
            {
                issue = new Issue {
                    Description = "A new issue", Title = "A new issue"
                };
                issue.Description = "A new issue";
                issue.Title       = "A new issue";
                var newIssue      = new Issue {
                    Id = "1"
                };
                MockIssueStore.Setup(i => i.CreateAsync(issue)).Returns(Task.FromResult(newIssue));
            });
            "When a POST request is made".
            f(() =>
            {
                Request.Method     = HttpMethod.Post;
                Request.RequestUri = _issues;
                Request.Content    = new ObjectContent <Issue>(issue, new JsonMediaTypeFormatter());
                Response           = Client.SendAsync(Request).Result;
            });
            "Then a '201 Created' status is returned".
            f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.Created));
            "Then the issue should be added".
            f(() => MockIssueStore.Verify(i => i.CreateAsync(issue)));
            "Then the response location header will be set to the resource location".
            f(() => Response.Headers.Location.AbsoluteUri.ShouldEqual("http://localhost/issue/1"));
        }
Example #9
0
 public void RetrievingAnIssueThatDoesNotExist()
 {
     "Given an issue does not exist".
     f(() => MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult((Issue)null)));
     "When it is retrieved".
     f(() =>
     {
         Request.RequestUri = _uriIssue1;
         Response           = Client.SendAsync(Request).Result;
     });
     "Then a '404 Not Found' status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));
 }
Example #10
0
 public void TransitioningAnIssueThatDoesNotExist()
 {
     "Given an issue does not exist".
     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;
     });
     "Then a '404 Not Found' status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));
 }
Example #11
0
 public void UpdatingAnIssueThatDoesNotExist()
 {
     "Given an issue does not exist".
     f(() => MockIssueStore.Setup(i => i.FindAsync("1")).Returns(Task.FromResult((Issue)null)));
     "When a PATCH request is made".
     f(() =>
     {
         Request.Method     = new HttpMethod("PATCH");
         Request.RequestUri = _uriIssue1;
         Request.Content    = new ObjectContent <dynamic>(new JObject(), new JsonMediaTypeFormatter());
         Response           = Client.SendAsync(Request).Result;
     });
     "Then a 404 Not Found status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.NotFound));
 }
Example #12
0
 public void RetrievingAnIssue(IssueState issue, Issue fakeIssue)
 {
     "Given an existing issue".
     f(() =>
     {
         fakeIssue = FakeIssues.FirstOrDefault();
         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 '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 == IssueLinkFactory.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");
     });
 }
Example #13
0
 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")));
     "And a '200 OK status' is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
 }
Example #14
0
 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");
     });
 }
Example #15
0
 void GivenExistingIssues()
 {
     MockIssueStore.Setup(i => i.FindAsync()).Returns(Task.FromResult(FakeIssues));
 }
Example #16
0
 void GivenAnExistingIssue(string issueId)
 {
     MockIssueStore.Setup(i => i.FindAsync(issueId)).Returns(Task.FromResult(_fakeIssue));
 }