From: Cody Russell Date: Tue, 24 Jun 2014 16:28:18 +0000 (-0500) Subject: Add a test for Creation event on FileSystemWatcher. X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=66416d2655bda555f52e7fb73f97d3984cf2fbde Add a test for Creation event on FileSystemWatcher. --- diff --git a/mcs/class/System/Test/System.IO/FileSystemWatcherTest.cs b/mcs/class/System/Test/System.IO/FileSystemWatcherTest.cs index 4ad27e1a8be..5d3f0fd1e57 100644 --- a/mcs/class/System/Test/System.IO/FileSystemWatcherTest.cs +++ b/mcs/class/System/Test/System.IO/FileSystemWatcherTest.cs @@ -11,12 +11,40 @@ using NUnit.Framework; using System; using System.IO; +using System.Threading; namespace MonoTests.System.IO { [TestFixture] public class FileSystemWatcherTest { + string base_path; + string path_a; + + FileSystemWatcher SetupWatcher () + { + var fsw = new FileSystemWatcher (); + fsw.Path = base_path; + fsw.IncludeSubdirectories = true; + fsw.EnableRaisingEvents = true; + + return fsw; + } + + [SetUp] + public void Setup () + { + base_path = Path.GetTempPath (); + path_a = Path.Combine (base_path, "a.txt"); + } + + [TearDown] + public void TearDown () + { + if (File.Exists (path_a)) + File.Delete (path_a); + } + [Test] public void CheckDefaults () { @@ -83,7 +111,26 @@ namespace MonoTests.System.IO FileSystemWatcher fw = new FileSystemWatcher (Path.GetTempPath (), "*"); fw.Path = "*"; } + + [Test] + public void TestWatchPathForFileCreation () + { + bool created = false; + var fsw = SetupWatcher (); + + fsw.Created += (object sender, FileSystemEventArgs e) => { + created = true; + }; + + Assert.IsFalse (created); + + File.WriteAllText (path_a, "this should create the file"); + + Thread.Sleep (20); + + Assert.IsTrue (created); + } } } -#endif \ No newline at end of file +#endif