コード例 #1
0
ファイル: HeadersTests.cs プロジェクト: modulexcite/RestEase
        public void HeadersFromPropertiesCombineWithHeadersFromClass()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.ClassHeaders = new List<KeyValuePair<string, string>>()
            {
                new KeyValuePair<string, string>("This-Will-Stay", "YesIWill"),
                new KeyValuePair<string, string>("Something", "SomethingElse"),
                new KeyValuePair<string, string>("User-Agent", "RestEase"),
                new KeyValuePair<string, string>("X-API-Key", "Foo"),
            };

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

            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"));
        }
コード例 #2
0
        public void HeadersFromPropertiesCombineWithHeadersFromClass()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.ClassHeaders = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("This-Will-Stay", "YesIWill"),
                new KeyValuePair <string, string>("Something", "SomethingElse"),
                new KeyValuePair <string, string>("User-Agent", "RestEase"),
                new KeyValuePair <string, string>("X-API-Key", "Foo"),
            };

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

            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"));
        }
コード例 #3
0
ファイル: HeadersTests.cs プロジェクト: modulexcite/RestEase
        public void AppliesHeadersFromProperties()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");
            requestInfo.AddPropertyHeader("User-Agent", "RestEase", null);
            requestInfo.AddPropertyHeader("X-API-Key", "Foo", null);

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

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

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

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);

            Assert.Equal("User-Agent: RestEase\r\nX-API-Key: Foo\r\n", message.Headers.ToString());
        }
コード例 #5
0
ファイル: HeadersTests.cs プロジェクト: xgame92/RestEase
        public void DoesNotThrowIfContentHeaderAppliedToClassButThereIsNoContent()
        {
            var requestInfo = new RequestInfo(HttpMethod.Get, "foo");

            requestInfo.AddPropertyHeader("Content-Type", "text/html", String.Empty);

            var message = new HttpRequestMessage();

            this.requester.ApplyHeaders(requestInfo, message);
        }
コード例 #6
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());
        }
コード例 #7
0
ファイル: HeadersTests.cs プロジェクト: modulexcite/RestEase
        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());
        }