Esempio n. 1
0
 internal static Exception DecodeException(string encodedException)
 {
     using (var stream = new MemoryStream(Convert.FromBase64String(encodedException)))
         using (var reader = new BinaryReader(stream))
         {
             var actualException = AbstractEndPoint.ReadException(reader);
             return(actualException);
         }
 }
Esempio n. 2
0
        internal static string EncodeException(Exception exception)
        {
            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    AbstractEndPoint.WriteException(writer, exception);

                    var length           = (int)stream.Length;
                    var data             = stream.GetBuffer();
                    var encodedException = Convert.ToBase64String(data, 0, length);
                    return(encodedException);
                }
        }
Esempio n. 3
0
        public void TestEncodeException()
        {
            var    exception = new ArgumentNullException("whatever");
            string encoded   = null;

            new Action(() => encoded = OutOfProcessSiloServer.EncodeException(exception))
            .Should().NotThrow();

            encoded.Should().NotBeNull();
            encoded.Length.Should().BeGreaterThan(0);

            using (var stream = new MemoryStream(Convert.FromBase64String(encoded)))
                using (var reader = new BinaryReader(stream))
                {
                    var actualException = AbstractEndPoint.ReadException(reader);
                    actualException.Should().NotBeNull();
                    actualException.Should().BeOfType <ArgumentNullException>();
                    actualException.Message.Should().Be(exception.Message);
                }
        }
Esempio n. 4
0
        public void TestPreserveRemoteStacktrace()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
                {
                    try
                    {
                        throw new Exception();
                    }
                    catch (Exception e)
                    {
                        AbstractEndPoint.WriteException(writer, e);
                    }
                }

                stream.Position = 0;

                using (var reader = new BinaryReader(stream))
                {
                    try
                    {
                        throw AbstractEndPoint.ReadException(reader);
                    }
                    catch (Exception e)
                    {
                        var property         = e.GetType().GetProperty("RemoteStackTrace", BindingFlags.NonPublic | BindingFlags.Instance);
                        var remoteStackTrace = (string)property.GetValue(e);
                        remoteStackTrace.Should().NotBeEmpty("because the remote stacktrace of the exception should've been preserved");

                        var stacktrace = e.StackTrace;
                        stacktrace.Should().Contain(remoteStackTrace, "because the remote stacktrace should be part of the actual stacktrace to allow for easier debugging of distributed applications (I want to know where it crashed on the server)");
                    }
                }
            }
        }