コード例 #1
0
        public static bool EnsureOperationCanceledExceptionThrown(UntypedAction action, CancellationToken expectedCancellationTokenInException, string message)
        {
            OperationCanceledException exception = null;

            try
            {
                action();
            }
            catch (OperationCanceledException ex)
            {
                exception = ex;
            }

            if (exception == null)
            {
                TestHarness.TestLog("  > " + "OperationCanceledException was not thrown.  " + message);
                return(false);
            }

#if !PFX_LEGACY_3_5
            if (exception.CancellationToken != expectedCancellationTokenInException)
            {
                TestHarness.TestLog("  > " + "CancellationToken does not match.  " + message);
                return(false);
            }
#endif
            return(true);
        }
コード例 #2
0
        public static bool EnsureExceptionThrown(UntypedAction action, Type expectedExceptionType, string message)
        {
            Exception exception = null;

            try
            {
                action();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            if (exception == null || exception.GetType() != expectedExceptionType)
            {
                TestHarness.TestLog("  > " + message);
                return(false);
            }
            else
            {
                return(true);
            }
        }