public void ShortExceptionMessageTest() { var miShortenStackTrace = typeof(TelemetryTools).GetMethod("ShortExceptionMessage", BindingFlags.Static | BindingFlags.NonPublic) ?? throw new MethodAccessException("Could not find method through reflection."); try { ExceptionSimulator.ThrowOwnException(); } catch (Exception ex) { var result = (string)miShortenStackTrace.Invoke(null, new object[] { ex }); Console.WriteLine("Short own exception message: \n" + result); Assert.AreEqual("ApplicationE at ExceptionSimulator.ThrowOwnException in ExceptionSimulator.cs:14 -> This exception was thrown for testing.", result); } try { ExceptionSimulator.ThrowSystemException(); } catch (Exception ex) { var result = (string)miShortenStackTrace.Invoke(null, new object[] { ex }); Console.WriteLine("Short system exception message: \n" + result); // system exception message is localized so we don't really know the message and ignore it for this checks Assert.IsTrue(result.StartsWith("KeyNotFoundE at ThrowHelper.ThrowKeyNotFoundException at ExceptionSimulator.ThrowSystemException in ExceptionSimulator.cs:20")); } }
public static void SpecificExceptions(ExceptionSimulator es) { if (es == ExceptionSimulator.OverflowException) { checked { int result = int.MaxValue + int.Parse("1"); Console.WriteLine(result); } } if (es == ExceptionSimulator.FormatException) { int input = int.Parse(Console.ReadLine()); Console.WriteLine(input); } if (es == ExceptionSimulator.CustomException) { throw new ViktorException("Viktor exception custom message", "Viktor service"); } if (es == ExceptionSimulator.Exception) { throw new Exception("This is the exception message!"); } }
public void TestBasics() { _rollbarCommunicationEventsCount = 0; IExceptionHandler exceptionHandler = null; const int totalExceptionStackFrames = 10; int expectedCount = 0; exceptionHandler = new RollbarExceptionHandler(RollbarUnitTestSettings.AccessToken, RollbarUnitTestSettings.Environment, null); exceptionHandler.HandleException( ExceptionSimulator.GetExceptionWith(totalExceptionStackFrames, "RollbarExceptionHandlerFixture: TestBasics non-blocking..."), Guid.NewGuid() ); expectedCount++; exceptionHandler = new RollbarExceptionHandler(RollbarUnitTestSettings.AccessToken, RollbarUnitTestSettings.Environment, TimeSpan.FromSeconds(5)); exceptionHandler.HandleException( ExceptionSimulator.GetExceptionWith(totalExceptionStackFrames, "RollbarExceptionHandlerFixture: TestBasics blocking..."), Guid.NewGuid() ); expectedCount++; Assert.AreEqual(expectedCount, _rollbarCommunicationEventsCount); }
public void BasicTest() { var exception = ExceptionSimulator.GetExceptionWith(10, "SimulatedException"); var localVars = ExceptionUtility.SnapLocalVariables(exception); }