示例#1
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());
        }
        public static HttpResponseMessage ToHttpResponseMessage(this IReadDocument document)
        {
            var response = new HttpResponseMessage();

            response.Content = document.ToObjectContent();
            return(response);
        }
        public void RetrievingAllIssuesAsCollectionJson(IReadDocument readDocument)
        {
            "Given an existing issues"
                .f(() => MockIssueStore.Setup(i => i.FindAsync())
                    .Returns(Task.FromResult(FakeIssues)));

            "When all issues are retrived 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(() =>
                   {
                       var collection = readDocument.Collection;

                       var href = collection.Href;
                       Console.WriteLine(href.AbsoluteUri);
                       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());
        }
 public ReadDocumentDecorator(IReadDocument innerReadDocument)
 {
     _innerReadDocument = innerReadDocument;
 }
 public ReadDocumentDecorator(IReadDocument innerReadDocument)
 {
     _innerReadDocument = innerReadDocument;
 }
 public static ObjectContent ToObjectContent(this IReadDocument document)
 {
     return(new ObjectContent <IReadDocument>(document, _formatter, "application/vnd.collection+json"));
 }