Example #1
0
        public void AppliesHeadersFromMethod()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddMethodHeader("User-Agent", "RestEase");
            requestInfo.AddMethodHeader("X-API-Key", "Foo");

            var message = new HttpRequestMessage();
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("User-Agent: RestEase\r\nX-API-Key: Foo\r\n", message.Headers.ToString());
        }
Example #2
0
        public void AppliesHeadersFromMethod()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddMethodHeader("User-Agent", "RestEase");
            requestInfo.AddMethodHeader("X-API-Key", "Foo");

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("User-Agent: RestEase\r\nX-API-Key: Foo\r\n", message.Headers.ToString());
        }
Example #3
0
        public void MultipleHeadersAreAllowed()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddMethodHeader("User-Agent", "SomethingElse");
            requestInfo.AddMethodHeader("User-Agent", "RestEase");
            requestInfo.AddMethodHeader("X-API-Key", "Foo");

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("User-Agent: SomethingElse RestEase\r\nX-API-Key: Foo\r\n", message.Headers.ToString());
        }
Example #4
0
        public void DoesNotAttemptToApplyContentHeadersIfThereIsNoContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddMethodHeader("Content-Type", "text/html");

            var message = new HttpRequestMessage();

            Assert.Throws <ArgumentException>(() => this.requester.ApplyHeaders(requestInfo, message));
        }
Example #5
0
        public void HeadersFromMethodOverrideHeadersFromProperties()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddPropertyHeader("This-Will-Stay", "YesIWill", null);
            requestInfo.AddPropertyHeader("Something", "SomethingElse", null);
            requestInfo.AddPropertyHeader("User-Agent", "RestEase", null);
            requestInfo.AddPropertyHeader("X-API-Key", "Foo", null);

            requestInfo.AddMethodHeader("Something", null);       // Remove
            requestInfo.AddMethodHeader("User-Agent", "");        // Replace with null
            requestInfo.AddMethodHeader("X-API-Key", "Bar");      // Change value
            requestInfo.AddMethodHeader("This-Is-New", "YesIAM"); // New value

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("This-Will-Stay: YesIWill\r\nThis-Is-New: YesIAM\r\nUser-Agent: \r\nX-API-Key: Bar\r\n", message.Headers.ToString());
        }
Example #6
0
        public void AppliesContentHeadersToContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddMethodHeader("Content-Type", "text/html");

            var message = new HttpRequestMessage();

            message.Content = new StringContent("hello");
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("", message.Headers.ToString());
            Assert.Equal("Content-Type: text/html\r\n", message.Content.Headers.ToString());
        }
Example #7
0
        public void SendsBodyHeadersIfBodyIsNull()
        {
            var requestInfo = new RequestInfo(HttpMethod.Post, "foo");

            requestInfo.AddMethodHeader("Content-Type", "text/plain");
            requestInfo.SetBodyParameterInfo <object>(BodySerializationMethod.Default, null);

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.NotNull(message.Content);
            Assert.Equal("text/plain", message.Content.Headers.ContentType.MediaType);
        }
Example #8
0
        public void AddsContentIfContentHeaderAppliedToMethodButThereIsNoContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddMethodHeader("Content-Type", "text/html");

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.NotNull(message.Content);
            Assert.Equal(0, message.Content.Headers.ContentLength);
            Assert.Equal("text/html", message.Content.Headers.ContentType.ToString());
        }
Example #9
0
        public void HeadersFromParamsCombineWithHeadersFromMethod()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddMethodHeader("This-Will-Stay", "YesIWill");
            requestInfo.AddMethodHeader("Something", "SomethingElse");
            requestInfo.AddMethodHeader("User-Agent", "RestEase");
            requestInfo.AddMethodHeader("X-API-Key", "Foo");

            requestInfo.AddHeaderParameter <string>("Something", null);
            requestInfo.AddHeaderParameter("User-Agent", "");
            requestInfo.AddHeaderParameter("X-API-Key", "Bar");
            requestInfo.AddHeaderParameter("This-Is-New", "YesIAm");

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal(new[] { "YesIWill" }, message.Headers.GetValues("This-Will-Stay"));
            Assert.Equal(new[] { "SomethingElse" }, message.Headers.GetValues("Something"));
            Assert.Equal(new[] { "RestEase", "" }, message.Headers.GetValues("User-Agent"));
            Assert.Equal(new[] { "Foo", "Bar" }, message.Headers.GetValues("X-API-Key"));
            Assert.Equal(new[] { "YesIAm" }, message.Headers.GetValues("This-Is-New"));
        }
Example #10
0
        public void HeadersFromMethodOverrideHeadersFromProperties()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddPropertyHeader("This-Will-Stay", "YesIWill", null);
            requestInfo.AddPropertyHeader("Something", "SomethingElse", null);
            requestInfo.AddPropertyHeader("User-Agent", "RestEase", null);
            requestInfo.AddPropertyHeader("X-API-Key", "Foo", null);

            requestInfo.AddMethodHeader("Something", null); // Remove
            requestInfo.AddMethodHeader("User-Agent", ""); // Replace with null
            requestInfo.AddMethodHeader("X-API-Key", "Bar"); // Change value
            requestInfo.AddMethodHeader("This-Is-New", "YesIAM"); // New value

            var message = new HttpRequestMessage();
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("This-Will-Stay: YesIWill\r\nThis-Is-New: YesIAM\r\nUser-Agent: \r\nX-API-Key: Bar\r\n", message.Headers.ToString());
        }
Example #11
0
        public void DoesNotAttemptToApplyContentHeadersIfThereIsNoContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddMethodHeader("Content-Type", "text/html");

            var message = new HttpRequestMessage();
            Assert.Throws<ArgumentException>(() => this.requester.ApplyHeaders(requestInfo, message));
        }
Example #12
0
        public void AppliesContentHeadersToContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddMethodHeader("Content-Type", "text/html");

            var message = new HttpRequestMessage();
            message.Content = new StringContent("hello");
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("", message.Headers.ToString());
            Assert.Equal("Content-Type: text/html\r\n", message.Content.Headers.ToString());
        }
Example #13
0
        public void MultipleHeadersAreAllowed()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddMethodHeader("User-Agent", "SomethingElse");
            requestInfo.AddMethodHeader("User-Agent", "RestEase");
            requestInfo.AddMethodHeader("X-API-Key", "Foo");

            var message = new HttpRequestMessage();
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("User-Agent: SomethingElse RestEase\r\nX-API-Key: Foo\r\n", message.Headers.ToString());
        }
Example #14
0
        public void HeadersFromParamsCombineWithHeadersFromMethod()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddMethodHeader("This-Will-Stay", "YesIWill");
            requestInfo.AddMethodHeader("Something", "SomethingElse");
            requestInfo.AddMethodHeader("User-Agent", "RestEase");
            requestInfo.AddMethodHeader("X-API-Key", "Foo");

            requestInfo.AddHeaderParameter<string>("Something", null);
            requestInfo.AddHeaderParameter("User-Agent", "");
            requestInfo.AddHeaderParameter("X-API-Key", "Bar");
            requestInfo.AddHeaderParameter("This-Is-New", "YesIAm");

            var message = new HttpRequestMessage();
            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal(new[] { "YesIWill" }, message.Headers.GetValues("This-Will-Stay"));
            Assert.Equal(new[] { "SomethingElse" }, message.Headers.GetValues("Something"));
            Assert.Equal(new[] { "RestEase", "" }, message.Headers.GetValues("User-Agent"));
            Assert.Equal(new[] { "Foo", "Bar" }, message.Headers.GetValues("X-API-Key"));
            Assert.Equal(new[] { "YesIAm" }, message.Headers.GetValues("This-Is-New"));
        }