我试试这个简单的测试与 FileSystemWatcher类,但不点火FileSystemWatcher的不与单元测试工作
[Test]
public void CanNotifyWhenFileChanged()
{
var watcher = new XMLWatcher(_path);
watcher.StartWatching();
AddXMLNodeTofile(_path);// change the file
bool c = watcher.IsFileChanged;
Assert.IsTrue(c);
}
的OnFileChanged事件工作,这是我的方法
public void StartWatching()
{
var watcher = new FileSystemWatcher
{
Path =
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
IncludeSubdirectories = false,
NotifyFilter = NotifyFilters.LastAccess |
NotifyFilters.LastWrite |
NotifyFilters.FileName |
NotifyFilters.DirectoryName,
Filter = FilePath
};
watcher.Changed += OnFileChanged;
watcher.EnableRaisingEvents = true;
}
你确定'_path'和'GetExecutingAssembly()。Location'的结尾足够相似,FSW应该调用一个事件吗? –
@Damien_The_Unbeliever非常感谢您这是问题 – tito11
@Damien_The_Unbeliever请将您的评论添加为答案:) – tito11