|
| 1 | +using Backtrace.Interfaces; |
| 2 | +using Backtrace.Model; |
| 3 | +using Backtrace.Types; |
| 4 | +using Moq; |
| 5 | +using NUnit.Framework; |
| 6 | +using System; |
| 7 | +using System.Collections.Generic; |
| 8 | + |
| 9 | +namespace Backtrace.Tests.ClientTests |
| 10 | +{ |
| 11 | + [TestFixture( |
| 12 | + Author = "Konrad Dysput", |
| 13 | + Category = "Client.AggreagateException", |
| 14 | + Description = "Test client bahaviour for handling aggreagate exceptions")] |
| 15 | + public class AggregateExceptionTests |
| 16 | + { |
| 17 | + protected BacktraceClient _backtraceClient; |
| 18 | + |
| 19 | + [SetUp] |
| 20 | + public virtual void Setup() |
| 21 | + { |
| 22 | + var api = new Mock<IBacktraceApi>(); |
| 23 | + api.Setup(n => n.Send(It.IsAny<BacktraceData>())) |
| 24 | + .Returns(new BacktraceResult() { Status = BacktraceResultStatus.Ok }); |
| 25 | + |
| 26 | + api.Setup(n => n.SendAsync(It.IsAny<BacktraceData>())) |
| 27 | + .ReturnsAsync(() => new BacktraceResult() { Status = BacktraceResultStatus.Ok }); |
| 28 | + |
| 29 | + var credentials = new BacktraceCredentials(@"https://validurl.com/", "validToken"); |
| 30 | + _backtraceClient = new BacktraceClient(credentials) |
| 31 | + { |
| 32 | + BacktraceApi = api.Object, |
| 33 | + UnpackAggregateExcetpion = true |
| 34 | + }; |
| 35 | + } |
| 36 | + |
| 37 | + [Test(Description = "Test empty aggregate exception")] |
| 38 | + public void TestEmptyAggreagateException() |
| 39 | + { |
| 40 | + var aggregateException = new AggregateException("test exception"); |
| 41 | + var result = _backtraceClient.Send(aggregateException); |
| 42 | + Assert.IsNotNull(result); |
| 43 | + Assert.AreEqual(result.Status, BacktraceResultStatus.Empty); |
| 44 | + } |
| 45 | + |
| 46 | + [Test(Description = "Test default scenario for aggregate exception")] |
| 47 | + public void TestAggreagateException() |
| 48 | + { |
| 49 | + var aggregateException = new AggregateException("test exception", |
| 50 | + new List<Exception>() { |
| 51 | + new ArgumentException("argument exception"), |
| 52 | + new InvalidOperationException("invalid operation exception"), |
| 53 | + new FormatException("format exception"), |
| 54 | + }); |
| 55 | + var result = _backtraceClient.Send(aggregateException); |
| 56 | + |
| 57 | + Assert.IsNotNull(result); |
| 58 | + Assert.AreEqual(result.Status, BacktraceResultStatus.Ok); |
| 59 | + |
| 60 | + int totalReports = 0; |
| 61 | + while (result != null) |
| 62 | + { |
| 63 | + totalReports++; |
| 64 | + result = result.InnerExceptionResult; |
| 65 | + } |
| 66 | + Assert.AreEqual(3, totalReports); |
| 67 | + |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments