Пример #1
0
        public static void Assert(bool condition, string message, string detailMessage)
        {
            if (!condition)
            {
                StackTrace stack = new StackTrace(true);
                int        userStackFrameIndex = 0;
                string     stackTrace;

                try {
                    stackTrace = StackTraceToString(stack, userStackFrameIndex, stack.FrameCount - 1);
                } catch {
                    stackTrace = "";
                }

                WriteAssert(stackTrace, message, detailMessage);
                AssertWrapper.ShowAssert(stackTrace, stack.GetFrame(userStackFrameIndex), message, detailMessage);
            }
        }
        /// <devdoc>
        ///    <para>
        ///       Emits or displays messages and a stack trace for an assertion that
        ///       always fails.
        ///    </para>
        /// </devdoc>
        public override void Fail(string message, string detailMessage)
        {
            StackTrace stack = new StackTrace(true);
            int        userStackFrameIndex = 0;
            string     stackTrace;
            bool       uiPermission = UiPermission;

            try {
                stackTrace = stack.ToString();
            }
            catch {
                stackTrace = "";
            }

            WriteAssert(stackTrace, message, detailMessage);
            if (AssertUiEnabled && uiPermission)
            {
                AssertWrapper.ShowAssert(stackTrace, stack.GetFrame(userStackFrameIndex), message, detailMessage);
            }
        }
        public override void Fail(string message, string detailMessage)
        {
            string     str;
            StackTrace trace           = new StackTrace(true);
            int        startFrameIndex = 0;
            bool       uiPermission    = UiPermission;

            try
            {
                str = this.StackTraceToString(trace, startFrameIndex, trace.FrameCount - 1);
            }
            catch
            {
                str = "";
            }
            this.WriteAssert(str, message, detailMessage);
            if (this.AssertUiEnabled && uiPermission)
            {
                AssertWrapper.ShowAssert(str, trace.GetFrame(startFrameIndex), message, detailMessage);
            }
        }