Exemplo n.º 1
0
        public override void Execute()
        {
            try
            {
                Exception exception = null;
                var       @event    = new ManualResetEvent(false);

                ThreadPool.QueueUserWorkItem(o =>
                {
                    var oldSyncContext = SynchronizationContext.Current;
                    using (var syncContext = new AsyncTestSyncContext())
                    {
                        SynchronizationContext.SetSynchronizationContext(syncContext);

                        try
                        {
                            this.body.Invoke();
                            exception = syncContext.WaitForCompletion();
                        }
                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                        finally
                        {
                            SynchronizationContext.SetSynchronizationContext(oldSyncContext);
                            @event.Set();
                        }
                    }
                });

                // NOTE: we do not call the WaitOne(int) overload because it wasn't introduced until .NET 3.5 SP1 and we want to support pre-SP1
                if ([email protected](this.MillisecondsTimeout, false))
                {
                    throw new Xunit.Sdk.TimeoutException(this.MillisecondsTimeout);
                }

                if (exception != null)
                {
                    ExceptionUtility.RethrowWithNoStackTraceLoss(exception);
                }
            }
            finally
            {
                foreach (var disposable in this.ExtractDisposables)
                {
                    CurrentScenario.AddTeardown(() => disposable.Dispose());
                }

                foreach (var teardown in this.Teardowns)
                {
                    CurrentScenario.AddTeardown(teardown);
                }
            }
        }
Exemplo n.º 2
0
        public static void Run(Func <object> performStep)
        {
            var oldSyncContext = SynchronizationContext.Current;

            try
            {
                var asyncSyncContext = new AsyncTestSyncContext();
                SetSynchronizationContext(asyncSyncContext);
                var result = performStep();
                var task   = result as Task;
                if (task != null)
                {
                    try
                    {
                        task.Wait();
                    }
                    catch (AggregateException ae)
                    {
                        var innerException = ae.InnerException;
                        ExceptionProcessor.PreserveStackTrace(innerException);
                        throw innerException;
                    }
                }
                else
                {
                    var ex = asyncSyncContext.WaitForCompletion();
                    if (ex != null)
                    {
                        ExceptionProcessor.PreserveStackTrace(ex);
                        throw ex;
                    }
                }
            }
            finally
            {
                SetSynchronizationContext(oldSyncContext);
            }
        }
Exemplo n.º 3
0
 public static void Run(Func<object> performStep)
 {
     var oldSyncContext = SynchronizationContext.Current;
     try
     {
         var asyncSyncContext = new AsyncTestSyncContext();
         SetSynchronizationContext(asyncSyncContext);
         var result = performStep();
         var task = result as Task;
         if (task != null)
         {
             try
             {
                 task.Wait();
             }
             catch (AggregateException ae)
             {
                 var innerException = ae.InnerException;
                 ExceptionProcessor.PreserveStackTrace(innerException);
                 throw innerException;
             }
         }
         else
         {
             var ex = asyncSyncContext.WaitForCompletion();
             if (ex != null)
             {
                 ExceptionProcessor.PreserveStackTrace(ex);
                 throw ex;
             }
         }
     }
     finally
     {
         SetSynchronizationContext(oldSyncContext);
     }
 }
Exemplo n.º 4
0
        public static void Run(Func <object> performStep)
        {
            var oldSyncContext = SynchronizationContext.Current;

            try
            {
                var asyncSyncContext = new AsyncTestSyncContext();
                SetSynchronizationContext(asyncSyncContext);
                performStep();

                {
                    var ex = asyncSyncContext.WaitForCompletion();
                    if (ex != null)
                    {
                        ExceptionProcessor.PreserveStackTrace(ex);
                        throw ex;
                    }
                }
            }
            finally
            {
                SetSynchronizationContext(oldSyncContext);
            }
        }