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 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 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 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 UnsetParameterInLink() { var link = new Link() { Template = new UriTemplate("http://localhost/{?foo}") }; var request = link.CreateRequest(); Assert.Equal("http://localhost/", request.RequestUri.AbsoluteUri); }
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); }