From 8ec50429607c26a3b22bdad881282e41da4cd45b Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Wed, 5 Apr 2023 08:51:20 -0700 Subject: [PATCH] Add some tests --- .../Internals/AgggregateExceptionTests.cs | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/Sentry.Tests/Internals/AgggregateExceptionTests.cs diff --git a/test/Sentry.Tests/Internals/AgggregateExceptionTests.cs b/test/Sentry.Tests/Internals/AgggregateExceptionTests.cs new file mode 100644 index 0000000000..49f9468d9f --- /dev/null +++ b/test/Sentry.Tests/Internals/AgggregateExceptionTests.cs @@ -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(() => + { + var t1 = Task.Run(() => throw new Exception("Test 1")); + var t2 = Task.Run(() => throw new Exception("Test 2")); + Task.WaitAll(t1, t2); + }); +}