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); }
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 ApiHomeController() { Document = new HomeDocument(); // Series var series = new Link() { Relation = Relations.SERIES_SINGLE, Target = new Uri("series/{id}", UriKind.Relative) }; series.SetParameter("id", "", Parameters.SERIES_ID); var allowedMethods = new AllowHint(); allowedMethods.AddMethod(HttpMethod.Get); allowedMethods.AddMethod(HttpMethod.Post); series.AddHint(allowedMethods); Document.AddResource(series); }
public void SpecifyHandlerForAllowhint() { var foo = false; var registry = new HintFactory(); registry.SetHandler<AllowHint>((h, r) => { foo = true; return r; }); var hint = registry.CreateHint<AllowHint>(); var link = new Link(); link.AddHint(hint); // Act var request = link.CreateRequest(); Assert.Equal(foo,true); }