public void EncoderAndDecoder_WithQEncodedString_AndNoUnicode_AndShortHeader_ShouldEncodeAndDecode( string testHeader, int expectedFoldedCount) { string result = MimeBasePart.EncodeHeaderValue(testHeader, Encoding.UTF8, false); string[] foldedHeaders = result.Split(new string[] { "\r\n " }, StringSplitOptions.RemoveEmptyEntries); Assert.Equal(expectedFoldedCount, foldedHeaders.Length); foreach (string foldedHeader in foldedHeaders) { Assert.InRange(foldedHeader.Length, 0, 76); } Assert.Equal(testHeader, MimeBasePart.DecodeHeaderValue(result)); }
public void EncodeHeader_WithNoUnicode_ShouldNotEncode(string testHeader) { string result = MimeBasePart.EncodeHeaderValue(testHeader, Encoding.UTF8, true); Assert.StartsWith("some test", result, StringComparison.Ordinal); Assert.EndsWith("header", result, StringComparison.Ordinal); foreach (char c in result) { Assert.InRange((byte)c, 0, 128); } Assert.Equal(testHeader, MimeBasePart.DecodeHeaderValue(result)); }
public void EncoderAndDecoder_ShouldEncodeAndDecode(string testHeader, int expectedFoldedCount) { string result = MimeBasePart.EncodeHeaderValue(testHeader, Encoding.UTF8, true); Assert.StartsWith("=?utf-8?B?", result, StringComparison.Ordinal); Assert.EndsWith("?=", result, StringComparison.Ordinal); string[] foldedHeaders = result.Split('\r'); Assert.Equal(expectedFoldedCount, foldedHeaders.Length); foreach (string foldedHeader in foldedHeaders) { Assert.InRange(foldedHeader.Length, 0, 76); } Assert.Equal(testHeader, MimeBasePart.DecodeHeaderValue(result)); }