Skip to content

Commit 917662e

Browse files
committed
Add testcase for issue #15
Add testcase that demonstrates the problem with AggregateException's inner exceptions. Also has some test cases for normal cases with inner exceptions
1 parent 1f92b3f commit 917662e

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

Source/Tests/Exceptionless.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<Compile Include="Storage\IsolatedStorageFileStorageTests.cs" />
141141
<Compile Include="Storage\PersistedDictionaryTests.cs" />
142142
<Compile Include="Submission\DefaultSubmissionClientTests.cs" />
143+
<Compile Include="ToErrorModel\ToErrorModelTests.cs" />
143144
<Compile Include="Utility\CountDownLatch.cs" />
144145
<Compile Include="Utility\InMemorySubmissionClient.cs" />
145146
<Compile Include="Utility\PasswordGenerator.cs" />
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Exceptionless.Extras;
7+
using Exceptionless.Logging;
8+
using Xunit;
9+
10+
namespace Exceptionless.Tests.ToErrorModel
11+
{
12+
public class ToErrorModelTests
13+
{
14+
[Fact]
15+
public void SimpleExceptionHasNoInner() {
16+
var e = new Exception("Test exception");
17+
var model = e.ToErrorModel(GetLog());
18+
19+
Assert.Equal(e.Message, model.Message);
20+
Assert.Null(model.Inner);
21+
}
22+
23+
[Fact]
24+
public void SimpleNestedExceptionWithInner()
25+
{
26+
var e = new Exception("Outer", new Exception("Inner"));
27+
var model = e.ToErrorModel(GetLog());
28+
29+
Assert.Equal("Outer", model.Message);
30+
Assert.Equal("Inner", model.Inner.Message);
31+
}
32+
33+
[Fact]
34+
public void AggregateExceptionWithOneInner() {
35+
var e = new AggregateException(new Exception("Exception 1"));
36+
37+
var model = e.ToErrorModel(GetLog());
38+
39+
Assert.Equal("Exception 1", model.Inner.Message);
40+
}
41+
42+
[Fact]
43+
public void AggregateExceptionWithMultipleInners() {
44+
var e = new AggregateException(new Exception("Exception 1"), new Exception("Exception 2"));
45+
46+
var model = e.ToErrorModel(GetLog());
47+
48+
Assert.Equal("Exception 1", model.Inner.Message);
49+
50+
// no way to get at "Exception 2"
51+
}
52+
53+
[Fact]
54+
public void AggregateExceptionWithInnerAggregateException() {
55+
var e = new AggregateException(new AggregateException(new Exception("Exception 1.1"), new Exception("Exception 1.2")), new Exception("Exception 2"));
56+
57+
var model = e.ToErrorModel(GetLog());
58+
59+
// now there's no way to find 1.1, 1.2 or 2 (Needs a .Flatten())
60+
Assert.Equal("Exception 1.1", model.Inner.Message);
61+
}
62+
63+
64+
IExceptionlessLog GetLog() {
65+
return new NullExceptionlessLog();
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)