Fix failing unit tests on TC

This change makes the changes of commits d54a4c and 194897
conditional so that they only compile on Mono. Hopefully this will
fix the hanging tests on TC.

Having to do this smells pretty badly - having the tests hang on TC
suggests that there are real problems (similar to the problems on
Linux where the tests also hang), but currently I don't have the
time to do more investigations.