我試試這個簡單的測試與 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