public static void EncodeDecodeTest() { var str = Yielder.Repeat(() => (char)DefaultRNG.I32.Next(32, 0xd800)).Take(1048576).ToList().Join(); var encoded = new UTF8Encoding(false).GetBytes(str); Assert.Equal(encoded, str.Encode()); Assert.Equal(encoded, str.Encode(new UTF8Encoding(false))); Assert.Equal(encoded, str.Encode("utf-8")); Assert.Equal(str, encoded.Decode()); Assert.Equal(str, encoded.Decode(Encoding.UTF8)); Assert.Equal(str, encoded.Decode("utf-8")); }