public void TestTryFixStackTrace() { bool success = false; try { CustomSerializableException fixedException = null; try { throw new CustomSerializableException(); } catch (CustomSerializableException ex) { success = ex.TryFixStackTrace(out fixedException); } if (fixedException != null) { throw new TargetInvocationException(fixedException); } } catch (TargetInvocationException ex) { Assert.IsInstanceOf <CustomSerializableException>(ex.InnerException, "Inner exception"); Assert.IsTrue(success, "Success of fix"); throw; } }
public void TestFixStackTraceCustomExceptionWithConstructor() { try { CustomSerializableException fixedException = null; try { throw new CustomSerializableException(); } catch (CustomSerializableException ex) { fixedException = ex.FixStackTrace(); } if (fixedException != null) { throw new TargetInvocationException(fixedException); } } catch (TargetInvocationException ex) { Assert.IsInstanceOf <CustomSerializableException>(ex.InnerException, "Inner exception"); throw; } }