public void EncodeHeaders_WithHeadersEncodingPropertySet_ShouldEncodeWithProperEncoding()
{
//note: this is the WRONG code page to use for the unicode value supplied: we are not testing that
//here, we care about whether or not it is using the correct encoding value to encode as specified
//in the HeadersEncoding property.
Encoding encoding = Encoding.GetEncoding("utf-32");
_message.HeadersEncoding = encoding;
_headers.Add("X-Custom", CustomUnicodeHeaderValue);
_message.EncodeHeaders(_headers, false);
string encodedHeader = _headers.Get("X-Custom");
Assert.True(encodedHeader.StartsWith("="), "didn't start with =");
Assert.True(encodedHeader.EndsWith("="), "didn't end with =");
string[] splits = encodedHeader.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
Assert.Equal("utf-32", splits[1]);
Assert.Equal(encoding, _message.HeadersEncoding);
// Allow Unicode, ignore header encoding
_headers.Clear();
_headers.Add("X-Custom", CustomUnicodeHeaderValue);
_message.EncodeHeaders(_headers, true);
encodedHeader = _headers.Get("X-Custom");
Assert.False(encodedHeader.StartsWith("="));
Assert.False(encodedHeader.EndsWith("="));
Assert.True(ContainsNonAscii(encodedHeader), encodedHeader);
}