private void TestExpectedSwiffotronError( string inputXML, SwiffotronError error, string errorSentinel, SWFModellerError?innerError = null, string innerSentinel = null) { /* Why not use expected exception attributes from MSTest? Well because we want to inspect not * only the extra error information that our fabulous custom exceptions provide, but we want to * inspect inner exceptions too. We're that thorough. */ MockStore store; MockCache cache; Swiffotron swiffotron = CreateMockSwiffotron(out store, out cache); StringBuilder writeLog = new StringBuilder(); StringBuilder abcWriteLog = new StringBuilder(); try { swiffotron.Process(ResourceAsStream(inputXML), null, null, null, null, null); Assert.Fail("An exception of type " + error + " was expected. No exception was thrown."); } catch (SwiffotronException se) { Assert.AreEqual(error, se.Error, "Error mismatch: " + se.Message); Assert.AreEqual(errorSentinel, se.Sentinel, "Error sentinel mismatch: " + se.Message); if (innerError != null) { Assert.IsTrue(se.InnerException is SWFModellerException, "Expected an inner exception of type SWFModellerException"); Assert.AreEqual(innerError, (se.InnerException as SWFModellerException).Error, "Error mismatch: " + se.InnerException.Message); Assert.AreEqual(innerSentinel, (se.InnerException as SWFModellerException).Sentinel, "Error sentinel mismatch: " + se.InnerException.Message); } } /* And as a parting shot: */ Assert.AreNotEqual(error, SwiffotronError.Internal, "Can't test for Internal errors. This test is clearly not written properly."); }
/// <summary> /// Initializes a new instance of an exception without an error message /// </summary> /// <param name="error">The error code.</param> /// <param name="ctx">A context object that describes what was being done when the exception occured.</param> public SwiffotronException(SwiffotronError error, SwiffotronContext ctx) : base(error.ToString() + "; " + ctx.ToString()) { this.Error = error; this.Sentinel = ctx.SentinelString; }
/// <summary> /// Initializes a new instance of an exception with an error message /// </summary> /// <param name="error">The error code.</param> /// <param name="ctx">A context object that describes what was being done when the exception occured.</param> /// <param name="msg">The error message</param> /// <param name="inner">The inner exception</param> public SwiffotronException(SwiffotronError error, SwiffotronContext ctx, string msg, Exception inner) : base(error.ToString() + "; " + msg + "; " + ctx.ToString(), inner) { this.Error = error; this.Sentinel = ctx.SentinelString; }