I have a little bit of logic at the boundary of my app dealing with creating directories. I would like to test that it actually creates directories as expected, but the DirectoryInfo.Exists property always returns false even when the directory actually exists.
See also this question - you need to set a breakpoint to see that the directory has actually been created because MSTest will delete it when the test ends.
Is there some setting that tells MSTest to allow "normal" filesystem IO during tests?
Assuming you create the DirectoryInfo instance somewhat earlier there is some internal caching of directory state involved - if you call DirectoryInfo.Refresh()
to force an update this should work:
var dir = new DirectoryInfo(@".\someDir");
//...other things here
dir.Refresh();
bool doesExist = dir.Exists;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With