Example #1
0
        public void AddCustomRequestHeaders_AddsHeaders()
        {
            HttpClient     httpClient     = new HttpClient();
            HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object);

            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpClientBase.CustomRequestHeaders = new Dictionary <string, IEnumerable <string> > {
                { "x-custom-header", new List <string> {
                      "value"
                  } }
            };

            httpClientBase.AddCustomRequestHeaders(httpRequest);

            httpRequest.Headers
            .Should()
            .NotBeEmpty();

            httpRequest.Headers
            .First()
            .As <KeyValuePair <string, IEnumerable <string> > >()
            .Key
            .Should().Be("x-custom-header");
        }
Example #2
0
        public void AddCustomRequestHeaders_DoesNotAddHeadersWithoutValues()
        {
            HttpClient     httpClient     = new HttpClient();
            HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object);

            HttpRequestMessage httpRequest = new HttpRequestMessage();

            httpClientBase.CustomRequestHeaders = new Dictionary <string, IEnumerable <string> > {
                { "x-custom-header", new List <string>() }
            };

            httpClientBase.AddCustomRequestHeaders(httpRequest);

            httpRequest.Headers.Should().BeEmpty();

            httpRequest = new HttpRequestMessage();
            httpClientBase.CustomRequestHeaders = new Dictionary <string, IEnumerable <string> > {
                { "x-custom-header", null }
            };

            httpClientBase.AddCustomRequestHeaders(httpRequest);

            httpRequest.Headers.Should().BeEmpty();
        }