|
6 | 6 | using Exceptionless.Models;
|
7 | 7 | using Exceptionless.Serializer;
|
8 | 8 | using Xunit;
|
| 9 | +using System.Reflection; |
| 10 | +using Exceptionless.Submission; |
| 11 | +using Moq; |
| 12 | +using System.Linq; |
| 13 | +using Exceptionless.Models.Data; |
| 14 | +using Exceptionless.Dependency; |
9 | 15 |
|
10 | 16 | namespace Exceptionless.Tests.Serializer {
|
11 | 17 | public class SerializerTests {
|
@@ -98,6 +104,59 @@ public void WillDeserializeReferenceIds() {
|
98 | 104 | var ev = (Event)serializer.Deserialize(@"{""reference_id"": ""123"" }", typeof(Event));
|
99 | 105 | Assert.Equal("123", ev.ReferenceId);
|
100 | 106 | }
|
| 107 | + |
| 108 | + [Fact] |
| 109 | + public void WillSerializeDeepExceptionWithStackInformation() |
| 110 | + { |
| 111 | + try |
| 112 | + { |
| 113 | + try |
| 114 | + { |
| 115 | + try |
| 116 | + { |
| 117 | + throw new ArgumentException("This is the inner argument exception", "wrongArg"); |
| 118 | + } |
| 119 | + catch (Exception e1) |
| 120 | + { |
| 121 | + throw new TargetInvocationException("Target invocation exception. Blah blah blah blah.", e1); |
| 122 | + } |
| 123 | + } |
| 124 | + catch (Exception e2) |
| 125 | + { |
| 126 | + throw new TargetInvocationException("Outer Exception. This is some text of the outer exception.", e2); |
| 127 | + } |
| 128 | + } |
| 129 | + catch (Exception exception) |
| 130 | + { |
| 131 | + Event e = null; |
| 132 | + IJsonSerializer serializer = null; |
| 133 | + |
| 134 | + var submissionMock = new Mock<ISubmissionClient>(); |
| 135 | + submissionMock.Setup(c => c.PostEvents(It.IsAny<IEnumerable<Event>>(), It.IsAny<ExceptionlessConfiguration>(), It.IsAny<IJsonSerializer>())) |
| 136 | + .Returns((IEnumerable<Event> a, ExceptionlessConfiguration b, IJsonSerializer c) => { |
| 137 | + e = a.Single(); |
| 138 | + serializer = c; |
| 139 | + return new SubmissionResponse(200); |
| 140 | + }); |
| 141 | + |
| 142 | + ExceptionlessClient.Default.Configuration.Resolver.Register(submissionMock.Object); |
| 143 | + ExceptionlessClient.Default.Configuration.ApiKey = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 144 | + ExceptionlessExtensions.Register(ExceptionlessClient.Default); |
| 145 | + exception.ToExceptionless().Submit(); |
| 146 | + ExceptionlessClient.Default.ProcessQueue(); |
| 147 | + |
| 148 | + var innerLineNumber = e.Data.GetValue<Error>(Event.KnownDataKeys.Error) |
| 149 | + .Inner |
| 150 | + .Inner |
| 151 | + .StackTrace.Single() |
| 152 | + .LineNumber; |
| 153 | + |
| 154 | + var serialized = serializer.Serialize(e); |
| 155 | + var expected = string.Format("\"line_number\":{0}", innerLineNumber); |
| 156 | + |
| 157 | + Assert.Contains(expected, serialized); |
| 158 | + } |
| 159 | + } |
101 | 160 | }
|
102 | 161 |
|
103 | 162 | public class Blah {
|
|
0 commit comments