Add negative tests for WriteMessage.

This commit adds tests for the error paths when writing a message
to the wire.