/// <summary> /// Get entry name from stack frame, which is either the namespace name where the main method /// is located or if we are started from a test, the name of the test method. /// </summary> public static string GetEntryName() { StackFrame[] frames = new StackTrace().GetFrames(); Debug.Assert(frames != null); foreach (StackFrame frame in frames.Where(frame => frame.GetMethod().Name == "Main")) return GetNamespaceName(frame); return GetTestMethodName(frames); }
/// <summary> /// Get entry name from stack frame, which is either the namespace name where the main method /// is located or if we are started from a test, the name of the test method. /// </summary> public static string GetEntryName() { StackFrame[] frames = new StackTrace().GetFrames(); Debug.Assert(frames != null); var testName = GetTestMethodName(frames); if (testName != "") return testName; foreach (StackFrame frame in frames.Where(frame => frame.GetMethod().Name == "Main")) return GetNamespaceName(frame); return "Delta Engine"; //ncrunch: no coverage }
public static string GetExecutingAssemblyName() { StackFrame[] frames = new StackTrace().GetFrames(); if (!String.IsNullOrEmpty(unitTestClassFullName)) return GetNamespaceNameFromClassName(unitTestClassFullName); //ncrunch: no coverage start (these lines can only be reached from production code) foreach (StackFrame frame in frames.Where(frame => frame.GetMethod().Name == "Main")) return GetNamespaceName(frame); foreach (StackFrame frame in frames.Where(IsTestOrTestSetupMethod)) return frame.GetMethod().DeclaringType.Assembly.GetName().Name; if (IsRunningAsWindowsService(frames)) return GetNamespaceNameForWindowsService(frames.ToList()); throw new ExecutingAssemblyOrNamespaceNotFound(); }