Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs')
-rw-r--r--test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs b/test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs
new file mode 100644
index 00000000..f47e9b62
--- /dev/null
+++ b/test/Microsoft.TestCommon/PreserveSyncContextAttribute.cs
@@ -0,0 +1,24 @@
+using System.Threading;
+using Xunit;
+
+namespace Microsoft.TestCommon
+{
+ /// <summary>
+ /// Preserves the current <see cref="SynchronizationContext"/>. Use this attribute on
+ /// tests which modify the current <see cref="SynchronizationContext"/>.
+ /// </summary>
+ public class PreserveSyncContextAttribute : BeforeAfterTestAttribute
+ {
+ private SynchronizationContext _syncContext;
+
+ public override void Before(System.Reflection.MethodInfo methodUnderTest)
+ {
+ _syncContext = SynchronizationContext.Current;
+ }
+
+ public override void After(System.Reflection.MethodInfo methodUnderTest)
+ {
+ SynchronizationContext.SetSynchronizationContext(_syncContext);
+ }
+ }
+}