Ejemplo n.º 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));
            });
        }
Ejemplo n.º 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>())));
        }
Ejemplo n.º 3
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));
 }
Ejemplo n.º 4
0
 public void RetrievingAnIssue()
 {
     _fakeIssue = FakeIssues.FirstOrDefault();
     this.Given(x => x.GivenAnExistingIssue("1"), false)
     .When(x => x.WhenItIsRetrieved(_uriIssue1), false)
     .Then(x => x.ThenHttpStatusCodeIs(HttpStatusCode.OK), "Then a '200 OK' status is returned")
     .And(x => x.AndIssueStateIsReturned())
     .And(x => x.WithAnId())
     .And(x => x.AndATitle())
     .And(x => x.AndADescription())
     .And(x => x.AndTheCorrectState())
     .And(x => x.AndASelfLink())
     .And(x => x.AndATransitionLink())
     .BDDfy();
 }
Ejemplo n.º 5
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");
     });
 }
Ejemplo n.º 6
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));
 }