Example #1
0
 private object RunAsyncTestMethod(TestExecutionContext context)
 {
     TLogger.Write("##### RunAsyncTestMethod in TTestMethodCommand class #####");
     #region tronghieu.d - invoke async test method in application thread. This thread is blocked for waiting result.
     using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(testMethod.Method.MethodInfo))
     {
         TAsyncThreadMgr asyncThreadMgr = TAsyncThreadMgr.GetInstance();
         asyncThreadMgr.SetData(this, testMethod, arguments, context, true);
         asyncThreadMgr.GetMethodExecutionResetEvent().Set(); // release main thread to invoke method
         _testMethodRunComplete.WaitOne();                    // wait for result in current thread
         if (asyncThreadMgr.GetNonAsyncMethodException() != null)
         {
             throw asyncThreadMgr.GetNonAsyncMethodException();
         }
         try
         {
             if (asyncThreadMgr.GetResult() == null)
             {
                 return(asyncThreadMgr.GetResult());
             }
             return(region.WaitForPendingOperationsToComplete(asyncThreadMgr.GetResult()));
         }
         catch (Exception e)
         {
             throw new NUnitException("Rethrown", e);
         }
     }
     #endregion
 }
Example #2
0
        private static object InvokeDelegate <T>(ActualValueDelegate <T> del)
        {
            if (AsyncInvocationRegion.IsAsyncOperation(del))
            {
                using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(del))
                    return(region.WaitForPendingOperationsToComplete(del()));
            }

            return(del());
        }
Example #3
0
        private static object InvokeDelegate <T>(ActualValueDelegate <T> del)
        {
#if NET_4_0 || NET_4_5 || NETSTANDARD1_3 || NETSTANDARD1_6
            if (AsyncInvocationRegion.IsAsyncOperation(del))
            {
                using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(del))
                    return(region.WaitForPendingOperationsToComplete(del()));
            }
#endif

            return(del());
        }
Example #4
0
        private object RunAsyncTestMethod(TestExecutionContext context)
        {
            using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(testMethod.Method.MethodInfo))
            {
                object result = Reflect.InvokeMethod(testMethod.Method.MethodInfo, context.TestObject, arguments);

                try
                {
                    return(region.WaitForPendingOperationsToComplete(result));
                }
                catch (Exception e)
                {
                    throw new NUnitException("Rethrown", e);
                }
            }
        }
Example #5
0
        internal static Exception Intercept(object invocation)
        {
            IInvocationDescriptor invocationDescriptor = GetInvocationDescriptor(invocation);

#if NET_4_5
            if (AsyncInvocationRegion.IsAsyncOperation(invocationDescriptor.Delegate))
            {
                using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(invocationDescriptor.Delegate))
                {
                    object result = invocationDescriptor.Invoke();

                    try
                    {
                        region.WaitForPendingOperationsToComplete(result);
                        return(null);
                    }
                    catch (Exception ex)
                    {
                        return(ex);
                    }
                }
            }
            else
#endif
            {
                try
                {
                    invocationDescriptor.Invoke();
                    return(null);
                }
                catch (Exception ex)
                {
                    return(ex);
                }
            }
        }
Example #6
0
 private void RunAsyncMethod(MethodInfo method, TestExecutionContext context)
 {
     using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(method))
         region.WaitForPendingOperationsToComplete(RunNonAsyncMethod(method, context));
 }