예제 #1
0
        public void RetrievingAllIssues(IssuesState issueState)
        {
            "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;
                       issueState = Response.Content
                           .ReadAsAsync<IssuesState>().Result;
                   });

            "Then a '200 OK' status is returned"
                .f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));

            "Then they are returned"
                .f(() =>
                   {
                       issueState.Issues.FirstOrDefault(i => i.Id == "1").ShouldNotBeNull();
                       issueState.Issues.FirstOrDefault(i => i.Id == "2").ShouldNotBeNull();
                   });

            "Then the collection should have a 'self' link"
                .f(() =>
                   {
                       var link = issueState.Links.FirstOrDefault(
                           l => l.Rel == IssueLinkFactory.Rels.Self);
                       link.ShouldNotBeNull();
                       link.Href.AbsoluteUri.ShouldEqual("http://localhost/issue");
                   });
        }
예제 #2
0
 public async Task<HttpResponseMessage> GetSearch(string searchText)
 {
     var issue = await _store.FindAsyncQuery(searchText);
     var issuesState = new IssuesState();
     issuesState.Issues = issue.Select(i => _stateFactory.Create(i));
     issuesState.Links.Add(new Link
                           {
                               Href = Request.RequestUri,
                               Rel =  LinkFactory.Rels.Self
                           });
     return Request.CreateResponse(HttpStatusCode.OK, issuesState);
 }
예제 #3
0
 public async Task<HttpResponseMessage> Get()
 {
     var issues = await _store.FindAsync();
     var issuesState = new IssuesState();
     issuesState.Issues = issues.Select(i => _stateFactory.Create(i));
     issuesState.Links.Add(new Link
                           {
                               Href = Request.RequestUri,
                               Rel = LinkFactory.Rels.Self
                           });
     
     var response = Request.CreateResponse(HttpStatusCode.OK, issuesState);
     response.Headers.CacheControl = new CacheControlHeaderValue();
     response.Headers.CacheControl.Public = true;
     response.Headers.CacheControl.MaxAge = TimeSpan.FromMinutes(5);
     return response;
 }
예제 #4
0
        public void SearchingIssues(IssuesState issuesState)
        {
            "Given exisiting 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 issue = issuesState.Issues.FirstOrDefault();
                       issue.ShouldNotBeNull();
                       issue.Id.ShouldEqual("2");
                   });
        }