public void DefaultLinkShouldCreateAGetRequest() { var link = new Link() { Target = new Uri("Http://localhost") }; var request = link.CreateRequest(); Assert.Equal(HttpMethod.Get,request.Method); }
public void UseLinkToMakeRequest() { var link = new Link { Target = new Uri("Http://localhost") }; var client = new HttpClient(new FakeMessageHandler()); var response = client.SendAsync(link.CreateRequest()).Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public void SettingContentShouldBePassedToTheRequest() { var link = new Link { Target = new Uri("Http://localhost"), Method = HttpMethod.Post, Content = new StringContent("Hello World") }; var request = link.CreateRequest(); Assert.Equal(request.Content.ReadAsStringAsync().Result, "Hello World"); }
public async Task Test() { var link = new Link(){Target = new Uri("http://localhost")}; var notFoundHandler = new NotFoundHandler(new OkHandler(null)); var machine = new HttpResponseMachine(); machine.When(HttpStatusCode.NotFound) .Then(async (l, r) => { notFoundHandler.HandleResponseAsync(l, r); }); var client = new HttpClient(new FakeHandler() {Response = new HttpResponseMessage() {StatusCode = HttpStatusCode.NotFound}}); await client.FollowLinkAsync(link,machine); Assert.True(notFoundHandler.NotFound); }
public async Task FollowAndApplyInDistinctSteps() { var link = new Link() {Target = new Uri("http://example.org/")}; var client = new HttpClient(new FakeHandler() { Response = new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound } }); var clientState = new ClientApplicationState(); await client.FollowLinkAsync(link) .ApplyRepresentationToAsync(clientState); Assert.Equal(HttpStatusCode.NotFound, clientState.StatusCode); }
private static Dictionary<string, ParameterInfo> GetBindingProperties(Link link) { var props = link.GetType() .GetTypeInfo() .DeclaredProperties .Select(p => new ParameterInfo() { PropertyInfo = p, Attribute = p.GetCustomAttributes<LinkParameterAttribute>() .FirstOrDefault() }) .ToDictionary(pi => { return pi.Attribute == null ? pi.PropertyInfo.Name.ToLowerInvariant() : pi.Attribute.Name; }, pr => pr); return props; }
public void SettingAnAcceptHeaderShouldBePassedToTheRequest() { var link = new Link { Target = new Uri("Http://localhost"), }; link.AddRequestBuilder(new InlineRequestBuilder((r) => { r.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.hal")); r.Headers.UserAgent.Add(new ProductInfoHeaderValue("foo", "1.1")); return r; })); var request = link.CreateRequest(); Assert.True(request.Headers.Accept.Any(h => h.MediaType == "application/vnd.hal")); }
public void CreateLinkHeaderWithMediaTypeAndLanguages() { var link = new Link() { Target = new Uri("http://localhost/{?foo}"), Type = "application/foo" }; link.HrefLang.Add(new CultureInfo("en-GB")); link.HrefLang.Add(new CultureInfo("en-CA")); Assert.Equal("<http://localhost/{?foo}>;rel=\"related\";hreflang=en-GB;hreflang=en-CA;type=\"application/foo\"", link.AsLinkHeader()); }
public void CreateLinkHeaderWithRelation() { var link = new Link() { Target = new Uri("http://localhost/{?foo}"), Relation = "related", Title = "foo" }; Assert.Equal("<http://localhost/{?foo}>;rel=\"related\";title=\"foo\"", link.AsLinkHeader()); }
public void UnsetParameterInLink() { var link = new Link() { Template = new UriTemplate("http://localhost/{?foo}") }; var request = link.CreateRequest(); Assert.Equal("http://localhost/", request.RequestUri.AbsoluteUri); }
public void IdentifyParametersInTemplate() { var link = new Link() { Template = new UriTemplate("http://localhost/api/{dataset}/customer{?foo,bar,baz}") }; var parameters = link.Template.GetParameterNames(); Assert.Equal(4, parameters.Count()); Assert.True(parameters.Contains("dataset")); Assert.True(parameters.Contains("foo")); Assert.True(parameters.Contains("bar")); Assert.True(parameters.Contains("baz")); }
public void AddMultipleParametersToLink() { var link = new Link() { Template = new UriTemplate("http://localhost/api/{dataset}/customer{?foo,bar,baz}") }; link.Template.ApplyParametersToTemplate(new Dictionary<string, object> { {"foo", "bar"}, {"baz", "99"}, {"dataset", "bob"} }); var request = link.CreateRequest(); Assert.Equal("http://localhost/api/bob/customer?foo=bar&baz=99", request.RequestUri.AbsoluteUri); }
public void AddParameterToLink() { var link = new Link(){ Template = new UriTemplate("http://localhost/{?foo}")}; var client = new HttpClient(new FakeMessageHandler()); link.Template.AddParameter("foo", "bar"); var response = client.SendAsync(link.CreateRequest()).Result; Assert.Equal("http://localhost/?foo=bar", response.RequestMessage.RequestUri.AbsoluteUri); }
public async Task FollowLink() { var link = new Link { Target = new Uri("Http://localhost") }; var client = new HttpClient(new FakeMessageHandler()); var uri = string.Empty; var machine = new HttpResponseMachine(); machine.When(HttpStatusCode.OK) .Then(async (rel,r) => {uri = r.RequestMessage.RequestUri.AbsoluteUri; }); await client.FollowLinkAsync(link,machine); Assert.Equal("http://localhost/", uri); }
public void UseURITemplateAsLinkSource() { var link = new Link { Target = new Uri("Http://localhost") }; var client = new HttpClient(new FakeMessageHandler()); var response = client.SendAsync(link.CreateRequest()).Result; Assert.Equal("http://localhost/", response.RequestMessage.RequestUri.AbsoluteUri); }
public void RelativeLinkTemplate() { var link = new Link { Template = new UriTemplate("/foo/{bar}") }; link.Template.AddParameter("bar", "baz"); var req = link.CreateRequest(); Assert.Equal("/foo/baz", req.RequestUri.OriginalString); }
public void CreateLinkHeader() { var link = new Link() { Target = new Uri("http://localhost/{?foo}") }; Assert.Equal("<http://localhost/{?foo}>;rel=\"related\"", link.AsLinkHeader()); }