|
| 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