Esempio 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());
        }
Esempio n. 2
0
        public void CreateResourceWithPathParameterAndRelWithDots()
        {
            var doc = new HomeDocument();

            doc.AddResource <Link>(l =>
            {
                l.Relation = "vnd.foo.about";
                l.Target   = new Uri("http://example.org:1001/about/{id}");
            });

            doc.AddResource <HelpLink>(l =>
            {
                l.Target = new Uri("http://example.org:1001/help/{id}");
            });

            var ms = new MemoryStream();

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

            var st = new StreamReader(ms);
            var s  = st.ReadToEnd();

            Assert.True(s.Contains("href-template"));
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
        public HttpResponseMessage Get(HttpRequestMessage requestMessage)
        {
            var homeDocument = new HomeDocument();


            var fooLink = new Link()
            {
                Relation = "http://example.org/rels/foo",
                Target   = new Uri("foo", UriKind.Relative)
            };
            var allowHint = new AllowHint();

            allowHint.AddMethod(HttpMethod.Get);
            allowHint.AddMethod(HttpMethod.Post);
            fooLink.AddHint(allowHint);
            homeDocument.AddResource(fooLink);


            var barLink = new Link()
            {
                Relation = "http://example.org/rels/bar",
                Target   = new Uri("bar", UriKind.Relative)
            };
            var allowHint2 = new AllowHint();

            allowHint2.AddMethod(HttpMethod.Get);
            barLink.AddHint(allowHint2);
            homeDocument.AddResource(barLink);


            var bar2Link = new Link()
            {
                Relation = "http://example.org/rels/bar2",
                Target   = new Uri("bar/{id}", UriKind.Relative)
            };

            //   bar2Link.SetParameter("id","",new Uri("template/params/id", UriKind.Relative));
            homeDocument.AddResource(bar2Link);


            var ms = new MemoryStream();

            homeDocument.Save(ms);
            ms.Position = 0;
            var streamContent = new StreamContent(ms);

            return(new HttpResponseMessage()
            {
                Content = streamContent
            });
        }
Esempio n. 5
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"));
        }
Esempio n. 6
0
        public void CreateResource_with_extension_rel_and_template()
        {
            var doc = new HomeDocument();

            doc.AddResource <Link>(l =>
            {
                l.Relation = "http://webapibook.net/rels#issue-processor";
                l.Target   = new Uri("/issueprocessor/{id}{?action}", UriKind.Relative);
            });


            var ms = new MemoryStream();

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

            var st = new StreamReader(ms);
            var s  = st.ReadToEnd();

            Assert.True(s.Contains("href-template"));
        }
Esempio n. 7
0
        public void CreateResourceWithMultipleQueryParameters()
        {
            var doc = new HomeDocument();

            doc.AddResource <Link>(l =>
            {
                l.Relation = "vnd.foo.about";
                l.Template = new UriTemplate("http://example.org:1001/about{?id,name}");
            });


            var ms = new MemoryStream();

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

            var st = new StreamReader(ms);
            var s  = st.ReadToEnd();

            Assert.True(s.Contains("href-template"));
        }
Esempio n. 8
0
        public void CreateHomeDocumentWithLotsOfHints()
        {
            var doc = new HomeDocument();

            doc.AddResource <AboutLink>(l =>
            {
                l.Target = new Uri("about", UriKind.Relative);
                l.AddHint <AllowHint>(h => h.AddMethod(HttpMethod.Get));
                l.AddHint <FormatsHint>(h => h.AddMediaType("application/json"));
                l.AddHint <AcceptPostHint>(h => h.AddMediaType("application/vnd.tavis.foo+json"));
                l.AddHint <AcceptPreferHint>(h => h.AddPreference("handling"));
            });

            var ms = new MemoryStream();

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

            var st = new StreamReader(ms);
            var s  = st.ReadToEnd();

            Assert.NotNull(s);
        }