示例#1
0
        public static void TestToString()
        {
            StackFrame frame = new StackFrame("dude", 6, 6);
            string     str   = StackTraces.ToString(frame);

            Assert.AreEqual("NewRelic.Agent.Core.Utils.StackTracesTest.TestToString(dude:6)", str);
        }
示例#2
0
        public static void TestMethodToStringNoParameters()
        {
            MethodInfo method = typeof(StackTrace).GetMethod("GetFrames");
            string     str    = StackTraces.MethodToString(method);

            Assert.AreEqual("System.Diagnostics.StackTrace.GetFrames()", str);
        }
示例#3
0
        public static void TestScrubBadString()
        {
            ICollection <string> frames = StackTraces.ScrubAndTruncate(
                string.Join(System.Environment.NewLine, new string[] { "", "", null, "" }), 300);

            Assert.AreEqual(4, frames.Count);
        }
示例#4
0
        public static void TestScrub()
        {
            StackFrame[]             stackTraces = GetStackTrace().GetFrames();
            ICollection <StackFrame> frames      = StackTraces.ScrubAndTruncate(stackTraces, 300);

            Assert.AreNotEqual(stackTraces.Length, frames.Count);
        }
示例#5
0
        public static void TestTruncateWithZeroMax()
        {
            StackFrame[]             stackTraces = GetStackTrace().GetFrames();
            ICollection <StackFrame> frames      = StackTraces.ScrubAndTruncate(stackTraces, 0);

            Assert.AreEqual(0, frames.Count);
        }
示例#6
0
        public static void TestMethodToStringTwoParameters()
        {
            MethodBase method = typeof(StackTrace).GetConstructor(new Type[] { typeof(Exception), typeof(int) });
            string     str    = StackTraces.MethodToString(method);

            Assert.AreEqual("System.Diagnostics.StackTrace..ctor(System.Exception e,System.Int32 skipFrames)", str);
        }
示例#7
0
        public static void TestMethodToStringsOneParameter()
        {
            MethodInfo method = typeof(StackTrace).GetMethod("GetFrame");
            string     str    = StackTraces.MethodToString(method);

            Assert.AreEqual("System.Diagnostics.StackTrace.GetFrame(System.Int32 index)", str);
        }
示例#8
0
        public static void TestListToString()
        {
            StackFrame           frame   = new StackFrame("dude", 6, 6);
            ICollection <string> strings = StackTraces.ToStringList(new StackFrame[] { frame });

            Assert.AreEqual(1, strings.Count);
            IEnumerator <string> en = strings.GetEnumerator();

            Assert.That(en.MoveNext());
            Assert.AreEqual(StackTraces.ToString(frame), en.Current);
        }
示例#9
0
        public static void TestParseStackTrace()
        {
            ICollection <string> stack = StackTraces.ParseStackTrace(string.Join(System.Environment.NewLine,
                                                                                 new string[] {
                "  at Microsoft.ServiceModel.Samples.CalculatorService.Add(Double n1, Double n2)",
                "  at SyncInvokeAdd(Object , Object[] , Object[] )",
                "  at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)",
                "  at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)",
                "  at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)"
            }));

            Assert.AreEqual(5, stack.Count);
        }
示例#10
0
 public static void TestScrubException()
 {
     try
     {
         Test.Test.TestThrow();
         Assert.Fail();
     }
     catch (Exception ex)
     {
         ICollection <string> frames = StackTraces.ScrubAndTruncate(ex, 300);
         Console.WriteLine("Here's the pretty stack :\n " + ex.StackTrace);
         foreach (string frame in frames)
         {
             Console.WriteLine(frame);
         }
         Assert.AreEqual(10, frames.Count, ex.StackTrace);
     }
 }
示例#11
0
        public static void TestScrubNullString()
        {
            ICollection <string> frames = StackTraces.ScrubAndTruncate((string)null, 300);

            Assert.AreEqual(0, frames.Count);
        }