DirectoryInfo.Exists总是MSTest的过程中返回false [英] DirectoryInfo.Exists always returns false during MSTest

查看:198
本文介绍了DirectoryInfo.Exists总是MSTest的过程中返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有逻辑,在我的应用程序处理创建目录的边界一点点。我想测试一下它实际创建的目录如预期,但的 DirectoryInfo.Exists 属性总是返回false。

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.

又见这个问题 - 你需要设置一个断点,看该目录实际上已经创建,因为测试结束时MSTest的将其删除。

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.

有一些设置,告诉MSTest的,让正常的文件系统IO测试期间?

Is there some setting that tells MSTest to allow "normal" filesystem IO during tests?

推荐答案

假设你创建DirectoryInfo的实例,有些较早出现的目录状态的一些内部缓存参与 - 如果你调用 DirectoryInfo.Refresh()来强制更新这应该工作:

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;

这篇关于DirectoryInfo.Exists总是MSTest的过程中返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆