Fix tests on windows

With these 3 patches applied, all tests pass with 100% coverage.