CreateRequest() public method

public CreateRequest ( ) : HttpRequestMessage
return System.Net.Http.HttpRequestMessage
示例#1
0
        public void DefaultLinkShouldCreateAGetRequest()
        {
            var link = new Link() { Target = new Uri("Http://localhost") };

            var request = link.CreateRequest();

            Assert.Equal(HttpMethod.Get,request.Method);
        }
示例#2
0
        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);
        }
示例#3
0
        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");
        }
示例#4
0
        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"));
        }
示例#5
0
        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);
            
        }
示例#6
0
        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);
        }
示例#7
0
        public void UnsetParameterInLink()
        {
            var link = new Link() { Template = new UriTemplate("http://localhost/{?foo}") };

            var request = link.CreateRequest();

            Assert.Equal("http://localhost/", request.RequestUri.AbsoluteUri);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }