From the Encoding.GetString(Byte[]) MSDN documentation I find that it can throw an ArgumentException if:
The byte array contains invalid Unicode code points.
What test data can I throw at the method to cause such an exception?
I started trying a couple of inputs based on this other question about "invalid unicode characters", e.g.:
[Fact]
public void Checkit()
{
// Does not throw an ArgumentException :'(
var result = Encoding.UTF8.GetString(new byte[] { 0x80, 0x81 });
}
and
[Fact]
public void Checkit()
{
// Does not throw an ArgumentException :'(
var result = Encoding.UTF8.GetString(new byte[] { 0xc2, 0xc2 });
}
but neither Fact fails with an ArgumentException.
I also found a whole bunch of supposedly invalid byte sequences in the dotnet runtime repo tests which won't throw said ArgumentException (upon testing a couple).
The trigger for me asking is that I have code that uses GetString(Byte[]) and I want to see how it handles bad input by writing a unit test for it. But the reason for me asking is really curiosity (I can surely rewrite my unit test slightly to fix my immediate problem).
What "invalid Unicode code points" can I throw at Encoding.UTF8.GetString(Byte[]) to cause an ArgumentException?