Beispiel #1
0
        public static void Can_Serialize_An_Exception()
        {
            var ex1 = new Exception("My Inner Exception 2");
            var ex2 = new Exception("My Exception 1", ex1);

            SerializableException originalException = new SerializableException(ex2);

            // Save the full ToString() value, including the exception message and stack trace.

            var rawBytes = originalException.SerializeException();
            SerializableException newException = rawBytes.DeSerializeException();

            string originalExceptionAsString = originalException.ToString();
            string newExceptionAsString      = newException.ToString();

            // Double-check that the exception message and stack trace (owned by the base Exception) are preserved
            Assert.AreEqual(originalExceptionAsString, newExceptionAsString);
        }
		public static void Can_Serialize_An_Exception()
		{
			var ex1 = new Exception("My Inner Exception 2");
			var ex2 = new Exception("My Exception 1", ex1);

			SerializableException originalException = new SerializableException(ex2);

			// Save the full ToString() value, including the exception message and stack trace.

			var rawBytes = originalException.SerializeException();
			SerializableException newException = rawBytes.DeSerializeException();

			string originalExceptionAsString = originalException.ToString();
			string newExceptionAsString = newException.ToString();

			// Double-check that the exception message and stack trace (owned by the base Exception) are preserved
			Assert.AreEqual(originalExceptionAsString, newExceptionAsString);
		}
        public static void Can_Serialize_An_Exception()
        {
            NUnitUtils.PrintTestName();

            Stopwatch sw = Stopwatch.StartNew();

            var ex1 = new Exception("My Inner Exception 2");
            var ex2 = new Exception("My Exception 1", ex1);

            var originalException = new SerializableException(ex2);

            // Save the full ToString() value, including the exception message and stack trace.

            var rawBytes     = originalException.SerializeException();
            var newException = rawBytes.DeSerializeException();

            var originalExceptionAsString = originalException.ToString();
            var newExceptionAsString      = newException.ToString();

            // Double-check that the exception message and stack trace (owned by the base Exception) are preserved
            Assert.AreEqual(originalExceptionAsString, newExceptionAsString);

            NUnitUtils.PrintElapsedTime(sw.Elapsed);
        }
Beispiel #4
0
        /// <summary>
        /// Returns a concatenated string of the exception details
        /// </summary>
        /// <param name="ex">The Exception</param>
        /// <param name="message">The message that's being added</param>
        /// <returns></returns>
        public static string FullExceptionMsg(this Exception ex, string message = null)
        {
            var serialException = new SerializableException(ex, message);

            return(serialException.SerializeException());
        }