[System] Test that Process.WaitForExit triggers the event Exited.
authorMarcos Henrich <marcos.henrich@xamarin.com>
Wed, 8 Apr 2015 13:42:03 +0000 (14:42 +0100)
committerMarcos Henrich <marcos.henrich@xamarin.com>
Wed, 8 Apr 2015 13:42:03 +0000 (14:42 +0100)
mcs/class/System/Test/System.Diagnostics/ProcessTest.cs

index 9124b0886f2c9ff91a7d3d13cf07929e4d460bcd..3a82c4258faa17a4adf9cc27e5a6e89c3799402d 100644 (file)
@@ -768,6 +768,65 @@ namespace MonoTests.System.Diagnostics
 
                        Assert.AreEqual (true, r, "Null Argument Events Raised");
                }
+
+               [Test]
+               [NUnit.Framework.Category ("MobileNotWorking")]
+               public void TestEnableEventsAfterExitedEvent ()
+               {
+                       Process p = new Process ();
+                       
+                       p.StartInfo = GetCrossPlatformStartInfo ();
+                       p.StartInfo.UseShellExecute = false;
+                       p.StartInfo.RedirectStandardOutput = true;
+                       p.StartInfo.RedirectStandardError = true;
+
+                       var exitedCalledCounter = 0;
+                       p.Exited += (object sender, EventArgs e) => {
+                               exitedCalledCounter++;
+                               Assert.IsTrue (p.HasExited);
+                       };
+
+                       p.EnableRaisingEvents = true;
+
+                       p.Start ();
+                       p.BeginErrorReadLine ();
+                       p.BeginOutputReadLine ();
+                       p.WaitForExit ();
+
+                       Assert.AreEqual (1, exitedCalledCounter);
+                       Thread.Sleep (50);
+                       Assert.AreEqual (1, exitedCalledCounter);
+               }
+
+               [Test]
+               [NUnit.Framework.Category ("MobileNotWorking")]
+               public void TestEnableEventsBeforeExitedEvent ()
+               {
+                       Process p = new Process ();
+                       
+                       p.StartInfo = GetCrossPlatformStartInfo ();
+                       p.StartInfo.UseShellExecute = false;
+                       p.StartInfo.RedirectStandardOutput = true;
+                       p.StartInfo.RedirectStandardError = true;
+
+                       p.EnableRaisingEvents = true;
+
+                       var exitedCalledCounter = 0;
+                       p.Exited += (object sender, EventArgs e) => {
+                               exitedCalledCounter++;
+                               Assert.IsTrue (p.HasExited);
+                       };
+
+                       p.Start ();
+                       p.BeginErrorReadLine ();
+                       p.BeginOutputReadLine ();
+                       p.WaitForExit ();
+
+                       Assert.AreEqual (1, exitedCalledCounter);
+                       Thread.Sleep (50);
+                       Assert.AreEqual (1, exitedCalledCounter);
+               }
+
                
                private ProcessStartInfo GetCrossPlatformStartInfo ()
                {