Author: spouliot
Date: 2005-04-28 09:24:04 -0400 (Thu, 28 Apr 2005)
New Revision: 43719
Added:
trunk/mcs/class/corlib/Test/System.Threading/CompressedStackCas.cs
trunk/mcs/class/corlib/Test/System.Threading/CompressedStackTest.cs
trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextCas.cs
trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs
Modified:
trunk/mcs/class/corlib/Test/System.Threading/ChangeLog
Log:
2005-03-28 Sebastien Pouliot <[EMAIL PROTECTED]>
* CompressedStackCas.cs: New. CAS unit tests for CompressedStack.
* CompressedStackTest.cs: New. Unit tests for CompressedStack.
* ExecutionContextCas.cs: New. CAS unit tests for ExecutionContext.
* ExecutionContextTest.cs: New. Unit tests for ExecutionContext.
Modified: trunk/mcs/class/corlib/Test/System.Threading/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Threading/ChangeLog 2005-04-28
12:53:07 UTC (rev 43718)
+++ trunk/mcs/class/corlib/Test/System.Threading/ChangeLog 2005-04-28
13:24:04 UTC (rev 43719)
@@ -1,3 +1,10 @@
+2005-03-28 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * CompressedStackCas.cs: New. CAS unit tests for CompressedStack.
+ * CompressedStackTest.cs: New. Unit tests for CompressedStack.
+ * ExecutionContextCas.cs: New. CAS unit tests for ExecutionContext.
+ * ExecutionContextTest.cs: New. Unit tests for ExecutionContext.
+
2005-03-24 Sebastien Pouliot <[EMAIL PROTECTED]>
* MutexCas.cs: New. CAS unit tests for Mutex.
Added: trunk/mcs/class/corlib/Test/System.Threading/CompressedStackCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Threading/CompressedStackCas.cs
2005-04-28 12:53:07 UTC (rev 43718)
+++ trunk/mcs/class/corlib/Test/System.Threading/CompressedStackCas.cs
2005-04-28 13:24:04 UTC (rev 43719)
@@ -0,0 +1,109 @@
+//
+// CompressedStackCas.cs - CAS Unit Tests for CompressedStack
+//
+// Author:
+// Sebastien Pouliot ([EMAIL PROTECTED])
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+// Note: the class existed in 1.1 but the only thing we know about it is that
+// it has a finalizer ;-)
+#if NET_2_0
+
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+using NUnit.Framework;
+
+namespace MonoCasTests.System.Threading {
+
+ // NOTES
+ // The tests will fails on 2.0 beta 1 (and a few CTP afterwards)
because it relies
+ // on a LinkDemand for ECMA key (and identity permissions now support
unrestricted).
+
+ [TestFixture]
+ [Category ("CAS")]
+ public class CompressedStackCas {
+
+ static bool success;
+
+ static void Callback (object o)
+ {
+ new SecurityPermission
(SecurityPermissionFlag.UnmanagedCode).Demand ();
+ success = (bool)o;
+ }
+
+ [SetUp]
+ public void SetUp ()
+ {
+ if (!SecurityManager.SecurityEnabled)
+ Assert.Ignore ("SecurityManager isn't enabled");
+ success = false;
+ }
+
+ [Test]
+ public void Run_Empty ()
+ {
+ Assert.IsFalse (success, "pre-check");
+ CompressedStack.Run (CompressedStack.Capture (), new
ContextCallback (Callback), true);
+ Assert.IsTrue (success, "post-check");
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ private CompressedStack GetCompressedStackUnmanaged ()
+ {
+ return CompressedStack.Capture ();
+ // the Deny disappears with this stack frame but we got
a capture of it
+ }
+
+ private void Thread_Run_UnmanagedCode ()
+ {
+ bool result = false;
+ Assert.IsFalse (success, "pre-check");
+ try {
+ CompressedStack cs =
GetCompressedStackUnmanaged ();
+ // run with the captured security stack (i.e.
deny unmanaged)
+ CompressedStack.Run (cs, new ContextCallback
(Callback), true);
+ }
+ catch (SecurityException) {
+ result = true;
+ }
+ finally {
+ Assert.IsFalse (success, "post-check");
+ Assert.IsTrue (result, "Result");
+ }
+ }
+
+ [Test]
+ public void Run_UnmanagedCode ()
+ {
+ Thread t = new Thread (new ThreadStart
(Thread_Run_UnmanagedCode));
+ t.Start ();
+ t.Join ();
+ }
+ }
+}
+
+#endif
Added: trunk/mcs/class/corlib/Test/System.Threading/CompressedStackTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Threading/CompressedStackTest.cs
2005-04-28 12:53:07 UTC (rev 43718)
+++ trunk/mcs/class/corlib/Test/System.Threading/CompressedStackTest.cs
2005-04-28 13:24:04 UTC (rev 43719)
@@ -0,0 +1,145 @@
+//
+// CompressedStackTest.cs - NUnit Test Cases for CompressedStack
+//
+// Author:
+// Sebastien Pouliot ([EMAIL PROTECTED])
+//
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+// Note: the class existed in 1.1 but the only thing we know about it is that
+// it has a finalizer ;-)
+#if NET_2_0
+
+using System;
+using System.Runtime.Serialization;
+using System.Security;
+using System.Threading;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Threading {
+
+ // NOTES
+ // The tests will fails on 2.0 beta 1 (and a few CTP afterwards)
because it relies
+ // on a LinkDemand for ECMA key (and identity permissions now support
unrestricted).
+
+ [TestFixture]
+ public class CompressedStackTest {
+
+ static bool success;
+
+ static void Callback (object o)
+ {
+ success = (bool) o;
+ }
+
+ [SetUp]
+ public void SetUp ()
+ {
+ success = false;
+ Thread.CurrentThread.SetCompressedStack (null);
+ }
+
+ [Test]
+ public void Capture ()
+ {
+ CompressedStack cs1 = CompressedStack.Capture ();
+ Assert.IsNotNull (cs1, "Capture-1");
+
+ CompressedStack cs2 = CompressedStack.Capture ();
+ Assert.IsNotNull (cs2, "Capture-2");
+
+ Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
+ Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
+ Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode
(), "GetHashCode");
+ }
+
+ [Test]
+ public void CreateCopy ()
+ {
+ CompressedStack cs1 = CompressedStack.Capture ();
+ CompressedStack cs2 = cs1.CreateCopy ();
+ Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
+ Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
+ Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode
(), "GetHashCode");
+ Assert.IsFalse (Object.ReferenceEquals (cs1, cs2),
"ReferenceEquals");
+ }
+
+ [Test]
+ public void GetCompressedStack ()
+ {
+ CompressedStack cs1 =
CompressedStack.GetCompressedStack ();
+ Assert.IsNotNull (cs1, "GetCompressedStack");
+
+ CompressedStack cs2 = CompressedStack.Capture ();
+ Assert.IsNotNull (cs2, "Capture");
+
+ Assert.IsFalse (cs1.Equals (cs2), "cs1.Equals (cs2)");
+ Assert.IsFalse (cs2.Equals (cs1), "cs2.Equals (cs1)");
+ Assert.IsFalse (cs1.GetHashCode () == cs2.GetHashCode
(), "GetHashCode");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentNullException))]
+ public void GetObjectData_Null ()
+ {
+ StreamingContext sc = new StreamingContext ();
+ CompressedStack cs = CompressedStack.Capture ();
+ cs.GetObjectData (null, sc);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void Run_Null ()
+ {
+ CompressedStack.Run (null, new ContextCallback
(Callback), true);
+ }
+
+ [Test]
+ public void Run_Capture ()
+ {
+ Assert.IsFalse (success, "pre-check");
+ CompressedStack.Run (CompressedStack.Capture (), new
ContextCallback (Callback), true);
+ Assert.IsTrue (success, "post-check");
+ }
+
+ [Test]
+ public void Run_GetCompressedStack ()
+ {
+ Assert.IsFalse (success, "pre-check");
+ CompressedStack.Run (CompressedStack.GetCompressedStack
(), new ContextCallback (Callback), true);
+ Assert.IsTrue (success, "post-check");
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void Run_Thread ()
+ {
+ // this is because
Thread.CurrentThread.GetCompressedStack () returns null for an empty
+ // compressed stack while
CompressedStack.GetCompressedStack () return "something" empty ;-)
+ CompressedStack.Run
(Thread.CurrentThread.GetCompressedStack (), new ContextCallback (Callback),
true);
+ }
+ }
+}
+
+#endif
Added: trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextCas.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextCas.cs
2005-04-28 12:53:07 UTC (rev 43718)
+++ trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextCas.cs
2005-04-28 13:24:04 UTC (rev 43719)
@@ -0,0 +1,172 @@
+//
+// ExecutionContextCas.cs - CAS Unit Tests for ExecutionContext
+//
+// Author:
+// Sebastien Pouliot ([EMAIL PROTECTED])
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+using NUnit.Framework;
+
+namespace MonoCasTests.System.Threading {
+
+ [TestFixture]
+ [Category ("CAS")]
+ public class ExecutionContextCas {
+
+ static bool success;
+
+ static void Callback (object o)
+ {
+ new SecurityPermission
(SecurityPermissionFlag.UnmanagedCode).Demand ();
+ success = (bool)o;
+ }
+
+ [SetUp]
+ public void SetUp ()
+ {
+ if (!SecurityManager.SecurityEnabled)
+ Assert.Ignore ("SecurityManager isn't enabled");
+
+ success = false;
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ if (ExecutionContext.IsFlowSuppressed ())
+ ExecutionContext.RestoreFlow ();
+ }
+
+ private void Thread_Run_Empty ()
+ {
+ Assert.IsFalse (success, "pre-check");
+ ExecutionContext.Run (ExecutionContext.Capture (), new
ContextCallback (Callback), true);
+ Assert.IsTrue (success, "post-check");
+ }
+
+ [Test]
+ public void Run_Empty ()
+ {
+ Thread t = new Thread (new ThreadStart
(Thread_Run_Empty));
+ t.Start ();
+ t.Join ();
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+ private ExecutionContext GetExecutionContextUnmanaged ()
+ {
+ return ExecutionContext.Capture ();
+ // the Deny disappears with this stack frame but we got
a capture of it
+ }
+
+ private void Thread_Run_UnmanagedCode ()
+ {
+ bool result = false;
+ Assert.IsFalse (success, "pre-check");
+ try {
+ ExecutionContext ec =
GetExecutionContextUnmanaged ();
+ // run with the captured security stack (i.e.
deny unmanaged)
+ ExecutionContext.Run (ec, new ContextCallback
(Callback), true);
+ }
+ catch (SecurityException) {
+ result = true;
+ }
+ finally {
+ Assert.IsFalse (success, "post-check");
+ Assert.IsTrue (result, "Result");
+ }
+ }
+
+ [Test]
+ public void Run_UnmanagedCode ()
+ {
+ Thread t = new Thread (new ThreadStart
(Thread_Run_UnmanagedCode));
+ t.Start ();
+ t.Join ();
+ }
+
+ private void
Thread_Run_UnmanagedCode_SuppressFlow_BeforeCapture ()
+ {
+ bool result = false;
+ Assert.IsFalse (success, "pre-check");
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ try {
+ ExecutionContext ec =
GetExecutionContextUnmanaged ();
+ ExecutionContext.Run (ec, new ContextCallback
(Callback), true);
+ }
+ catch (InvalidOperationException) {
+ result = true;
+ }
+ finally {
+ Assert.IsFalse (success, "post-check");
+ afc.Undo ();
+ Assert.IsTrue (result, "Result");
+ }
+ }
+
+ [Test]
+ public void Run_UnmanagedCode_SuppressFlow_BeforeCapture ()
+ {
+ Thread t = new Thread (new ThreadStart
(Thread_Run_UnmanagedCode_SuppressFlow_BeforeCapture));
+ t.Start ();
+ t.Join ();
+ }
+
+ private void Thread_Run_UnmanagedCode_SuppressFlow_AfterCapture
()
+ {
+ bool result = false;
+ Assert.IsFalse (success, "pre-check");
+ ExecutionContext ec = GetExecutionContextUnmanaged ();
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ try {
+ ExecutionContext.Run (ec, new ContextCallback
(Callback), true);
+ }
+ catch (SecurityException) {
+ result = true;
+ }
+ finally {
+ Assert.IsFalse (success, "post-check");
+ afc.Undo ();
+ Assert.IsTrue (result, "Result");
+ }
+ }
+
+ [Test]
+ public void Run_UnmanagedCode_SuppressFlow_AfterCapture ()
+ {
+ Thread t = new Thread (new ThreadStart
(Thread_Run_UnmanagedCode_SuppressFlow_AfterCapture));
+ t.Start ();
+ t.Join ();
+ }
+ }
+}
+
+#endif
Added: trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs
2005-04-28 12:53:07 UTC (rev 43718)
+++ trunk/mcs/class/corlib/Test/System.Threading/ExecutionContextTest.cs
2005-04-28 13:24:04 UTC (rev 43719)
@@ -0,0 +1,192 @@
+//
+// ExecutionContextTest.cs - NUnit tests for ExecutionContext
+//
+// Author:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Security;
+using System.Threading;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Threading {
+
+ [TestFixture]
+ public class ExecutionContextTest {
+
+ static bool success;
+
+ static void Callback (object o)
+ {
+ success = (bool)o;
+ }
+
+ [SetUp]
+ public void SetUp ()
+ {
+ success = false;
+ }
+
+ [TearDown]
+ public void TearDown ()
+ {
+ if (ExecutionContext.IsFlowSuppressed ())
+ ExecutionContext.RestoreFlow ();
+ }
+
+ [Test]
+ public void Capture ()
+ {
+ ExecutionContext ec = ExecutionContext.Capture ();
+ Assert.IsNotNull (ec, "Capture");
+
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-1");
+ try {
+ ec = ExecutionContext.Capture ();
+ Assert.IsNull (ec, "Capture with SuppressFlow");
+ }
+ finally {
+ afc.Undo ();
+ }
+ }
+
+ [Test]
+ public void Copy ()
+ {
+ ExecutionContext ec = ExecutionContext.Capture ();
+ Assert.IsNotNull (ec, "Capture");
+
+ ExecutionContext copy = ec.CreateCopy ();
+ Assert.IsNotNull (copy, "Copy of Capture");
+
+ Assert.IsFalse (ec.Equals (copy));
+ Assert.IsFalse (copy.Equals (ec));
+ Assert.IsFalse (Object.ReferenceEquals (ec, copy));
+
+ ExecutionContext copy2nd = copy.CreateCopy ();
+ Assert.IsNotNull (copy2nd, "2nd level copy of Capture");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void Copy_FromThread ()
+ {
+ ExecutionContext ec =
Thread.CurrentThread.ExecutionContext;
+ Assert.IsNotNull (ec,
"Thread.CurrentThread.ExecutionContext");
+
+ ExecutionContext copy = ec.CreateCopy ();
+ }
+
+ [Test]
+ public void IsFlowSuppressed ()
+ {
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-1");
+
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-2");
+ afc.Undo ();
+
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-3");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void RestoreFlow_None ()
+ {
+ ExecutionContext.RestoreFlow ();
+ }
+
+ [Test]
+ public void RestoreFlow_SuppressFlow ()
+ {
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-1");
+ ExecutionContext.SuppressFlow ();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-2");
+ ExecutionContext.RestoreFlow ();
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-3");
+ }
+
+ [Test]
+ public void Run ()
+ {
+ Assert.IsFalse (success, "pre-check");
+ ExecutionContext.Run (ExecutionContext.Capture (), new
ContextCallback (Callback), true);
+ Assert.IsTrue (success, "post-check");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void Run_SuppressFlow ()
+ {
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed ());
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed ());
+ try {
+ ExecutionContext.Run (ExecutionContext.Capture
(), new ContextCallback (Callback), "Hello world.");
+ }
+ finally {
+ afc.Undo ();
+ }
+ }
+
+ [Test]
+ public void SuppressFlow ()
+ {
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-1");
+
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-3");
+ afc.Undo ();
+
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-4");
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void SuppressFlow_Two_Undo ()
+ {
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-1");
+
+ AsyncFlowControl afc = ExecutionContext.SuppressFlow ();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-2");
+
+ AsyncFlowControl afc2 = ExecutionContext.SuppressFlow
();
+ Assert.IsTrue (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-3");
+ afc2.Undo ();
+
+ // note: afc2 Undo return to the original (not the
previous) state
+ Assert.IsFalse (ExecutionContext.IsFlowSuppressed (),
"IsFlowSuppressed-4");
+
+ // we can't use the first AsyncFlowControl
+ afc.Undo ();
+ }
+ }
+}
+
+#endif
\ No newline at end of file
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches