public void GivenAnAllowHintWithAMethodAddingItAgainDoesNotFail() { // Arrange var hint = new AllowHint(); hint.AddMethod(HttpMethod.Get); // Act hint.AddMethod(HttpMethod.Get); //Asset // No error occured }
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 }); }
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()); }
public void UseAllowHintToSetRequestMethodOnLink() { // Arrange var hint = new AllowHint(); hint.AddMethod(HttpMethod.Post); hint.ConfigureRequest = (h, r) => { // Really not sure if this is a good idea to allow hints to actually change the request. // Should they just validate the current request? // How do we know if someone has explicitly set link.method or if it is just a default Get. var allowHint = ((AllowHint)h); if (!allowHint.Methods.Contains(r.Method)) { r.Method = allowHint.Methods.First(); } return(r); }; var link = new Link(); link.AddHint(hint); // Act var request = link.CreateRequest(); //Asset Assert.Equal(HttpMethod.Post, request.Method); }