开发者

Unit-test FileSystemWatcher.Error Event

开发者 https://www.devze.com 2022-12-24 22:45 出处:网络
I\'m trying to unit test a private method that I have attached to my FileSystemWatcher\'s Error event.MSDN says that this event \"occurs when the internal buffer overflows.\"I\'ve tried to cause a buf

I'm trying to unit test a private method that I have attached to my FileSystemWatcher's Error event. MSDN says that this event "occurs when the internal buffer overflows." I've tried to cause a buffer overflow but have not been successful so far. The FileSystemWatcher's various properties are:

fileWatcher.IncludeSubdirectories = false;
fileWatcher.Filter = "*";
fileWatcher.NotifyFilter = (NotifyFilters开发者_开发百科.FileName | NotifyFilters.LastAccess | NotifyFilters.Size);

What is the best way of raising this event for the purpose of unit-testing?


I doubt you will be able to reliably cause a buffer overflow. It will be system and configuration dependent. (It may even be load dependent). I would suggest that instead you mock the FileSystemWatcher class and trigger the mocked event yourself to test your handler.

See Wikipedia: Mock Object and this List of Mocking frameworks for some more details if you're new to the idea of mocking.


Just added a handler for the Error event to an existing code :). I was testing the processing of the files and with 112 files (as I have from the bug i'm working on) this gets triggered each time I copy the files to the watched folder. Each file is about 72k and I copy them using TotalCommander which I suppose does a plain iterative copy.

Unfortunately for you it all depends on the sys config & load (as simon pointed out).

Sure you can try to flush after each written byte with eventually a number of writers, but nothing can guaranty it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号