Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint committed Apr 5, 2023
1 parent 84761c7 commit 8ec5042
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/Sentry.Tests/Internals/AgggregateExceptionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Sentry.PlatformAbstractions;

namespace Sentry.Tests.Internals;

public class AgggregateExceptionTests
{
private static readonly string DefaultAggregateExceptionMessage = new AggregateException().Message;

[Fact]
public void AggregateException_GetRawMessage_Empty()
{
var exception = new AggregateException();

var rawMessage = exception.GetRawMessage();

Assert.Equal(DefaultAggregateExceptionMessage, rawMessage);
}

[Fact]
public void AggregateException_GetRawMessage_WithInnerExceptions()
{
var exception = GetTestAggregateException();

var rawMessage = exception.GetRawMessage();

Assert.Equal(DefaultAggregateExceptionMessage, rawMessage);
}

[SkippableFact]
public void AggregateException_GetRawMessage_DiffersFromMessage()
{
// Sanity check: The message should be different than the raw message, except on full .NET Framework.
// .NET, .NET Core, and Mono all override the Message property to append messages from the inner exceptions.
// .NET Framework does not.

Skip.If(RuntimeInfo.GetRuntime().IsNetFx());

var exception = GetTestAggregateException();

var rawMessage = exception.GetRawMessage();

Assert.NotEqual(exception.Message, rawMessage);
}

private static AggregateException GetTestAggregateException() =>
Assert.Throws<AggregateException>(() =>
{
var t1 = Task.Run(() => throw new Exception("Test 1"));
var t2 = Task.Run(() => throw new Exception("Test 2"));
Task.WaitAll(t1, t2);
});
}

0 comments on commit 8ec5042

Please sign in to comment.