public void SelectResponseCharacterEncoding_ThrowsOnNull()
        {
            MockContentNegotiator  negotiator = new MockContentNegotiator();
            HttpRequestMessage     request    = new HttpRequestMessage();
            MockMediaTypeFormatter formatter  = new MockMediaTypeFormatter();

            Assert.ThrowsArgumentNull(() => negotiator.SelectResponseCharacterEncoding(request: null, formatter: formatter), "request");
            Assert.ThrowsArgumentNull(() => negotiator.SelectResponseCharacterEncoding(request: request, formatter: null), "formatter");
        }
        public void SelectResponseCharacterEncoding_SelectsEncoding(string[] acceptCharsetHeaders, string requestEncoding, string[] supportedEncodings, string expectedEncoding)
        {
            // Arrange
            MockContentNegotiator negotiator = new MockContentNegotiator();

            HttpRequestMessage request = new HttpRequestMessage();

            foreach (string acceptCharsetHeader in acceptCharsetHeaders)
            {
                request.Headers.AcceptCharset.Add(StringWithQualityHeaderValue.Parse(acceptCharsetHeader));
            }

            if (requestEncoding != null)
            {
                Encoding      reqEncoding = Encoding.GetEncoding(requestEncoding);
                StringContent content     = new StringContent("", reqEncoding, "text/plain");
                request.Content = content;
            }

            MockMediaTypeFormatter formatter = new MockMediaTypeFormatter()
            {
                CallBase = true
            };

            foreach (string supportedEncoding in supportedEncodings)
            {
                formatter.SupportedEncodings.Add(Encoding.GetEncoding(supportedEncoding));
            }

            // Act
            Encoding actualEncoding = negotiator.SelectResponseCharacterEncoding(request, formatter);

            // Assert
            if (expectedEncoding == null)
            {
                Assert.Null(actualEncoding);
            }
            else
            {
                Assert.Equal(Encoding.GetEncoding(expectedEncoding), actualEncoding);
            }
        }