Exemplo n.º 1
0
        public void RoundTripHomeDocumentWithHint()
        {
            var doc       = new HomeDocument();
            var aboutLink = new AboutLink()
            {
                Target = new Uri("about", UriKind.Relative)
            };
            var allowHint = new AllowHint();

            allowHint.AddMethod(HttpMethod.Get);
            aboutLink.AddHint(allowHint);
            aboutLink.AddHint(new FormatsHint());
            doc.AddResource(aboutLink);

            var ms = new MemoryStream();

            doc.Save(ms);
            ms.Position = 0;

            var outDoc = HomeDocument.Parse(ms);

            var link = outDoc.GetResource("about");

            Assert.IsType <AboutLink>(link);
            Assert.IsType <AllowHint>(link.GetHints().First());
            Assert.IsType <FormatsHint>(link.GetHints().Last());
        }
Exemplo n.º 2
0
        public void ParseEmptyHomeDoc()
        {
            // Doc needs to be at least an object
            var doc = HomeDocument.Parse("{}");

            Assert.NotNull(doc);
        }
Exemplo n.º 3
0
        public void ParseHomeDocWithNoResources()
        {
            // Doc needs to be at least an object
            var doc = HomeDocument.Parse("{ \"resources\" : {} }");

            Assert.NotNull(doc);
        }
Exemplo n.º 4
0
        public void CreateHomeDocumentWithFormatsHints()
        {
            var doc       = new HomeDocument();
            var aboutLink = new AboutLink()
            {
                Target = new Uri("about", UriKind.Relative)
            };

            aboutLink.AddHint <AllowHint>(h => h.AddMethod(HttpMethod.Get));
            aboutLink.AddHint <FormatsHint>(h => h.AddMediaType("application/json"));

            doc.AddResource(aboutLink);

            var ms = new MemoryStream();

            doc.Save(ms);
            ms.Position = 0;

            var outDoc = HomeDocument.Parse(ms);

            var link = outDoc.GetResource("about");

            Assert.IsType <AboutLink>(link);
            Assert.IsType <AllowHint>(link.GetHints().First());
            Assert.IsType <FormatsHint>(link.GetHints().Last());
            Assert.IsType <AboutLink>(outDoc.Resources.First());
        }
Exemplo n.º 5
0
        private async Task DiscoverResources()
        {
            var response = await _HttpClient.GetAsync("/");

            _homeDocument = HomeDocument.Parse(await response.Content.ReadAsStreamAsync());
            AllSpeakers   = _homeDocument.GetResource(LinkHelper.GetLinkRelationTypeName <SpeakersLink>()).Target.OriginalString;
            AllSessions   = _homeDocument.GetResource(LinkHelper.GetLinkRelationTypeName <SessionsLink>()).Target.OriginalString;
        }
Exemplo n.º 6
0
        private async Task DiscoverResources()
        {
            var response = await _HttpClient.GetAsync("/");

            _homeDocument = HomeDocument.Parse(await response.Content.ReadAsStreamAsync());
            SpeakersLink  = _homeDocument.GetResource <SpeakersLink>();
            SessionsLink  = _homeDocument.GetResource <SessionsLink>();
        }
Exemplo n.º 7
0
        public void ParseHomeDocWithOneResource()
        {
            // Doc needs to be at least an object
            var doc = HomeDocument.Parse("{ \"resources\" :{ \"http://example.org/rels/test\" : {\"href\" : \"/test\"}  }}");

            var resource = doc.GetResource("http://example.org/rels/test");

            Assert.NotNull(resource);
            Assert.Equal(resource.Target, new Uri("/test", UriKind.Relative));
        }
Exemplo n.º 8
0
        public void RoundTripHomeDocument()
        {
            var doc = new HomeDocument();

            doc.AddResource(new AboutLink()
            {
                Target = new Uri("about", UriKind.Relative)
            });

            var ms = new MemoryStream();

            doc.Save(ms);
            ms.Position = 0;

            var outDoc = HomeDocument.Parse(ms);

            Assert.NotNull(outDoc.GetResource("about"));
        }
Exemplo n.º 9
0
        public async Task <HomeDocument> ParseResponse(HttpResponseMessage response, LinkFactory linkFactory)
        {
            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(null);
            }
            if (response.Content == null)
            {
                return(null);
            }
            if (response.Content.Headers.ContentType == null || response.Content.Headers.ContentType.MediaType != "application/home+json")
            {
                return(null);
            }

            Stream stream = await response.Content.ReadAsStreamAsync();

            return(HomeDocument.Parse(stream, linkFactory));
        }
Exemplo n.º 10
0
 public void RetrievingHomeRepresentation(HomeDocument home)
 {
     "When it is retrieved".
     f(() =>
     {
         Request.RequestUri = _uriHome;
         Response           = Client.SendAsync(Request).Result;
         var stream         = Response.Content.ReadAsStreamAsync().Result;
         home = HomeDocument.Parse(stream);
     });
     "Then a '200 OK' status is returned".
     f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
     "And it is returned".
     f(() => home.ShouldNotBeNull());
     "And it should have an issueprocessor link".
     f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.IssueProcessor).ShouldNotBeNull());
     "And it should have an issue link".
     f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.Issue).ShouldNotBeNull());
     "And it should have an issues link".
     f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.Issues).ShouldNotBeNull());
     "And it should have an search link".
     f(() => home.Resources.FirstOrDefault(l => l.Relation == IssueLinkFactory.Rels.SearchQuery).ShouldNotBeNull());
 }