Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a simple verify test
  • Loading branch information
jamescrosswell committed Jul 21, 2025
commit d52b2ade06222471ad563b64bc7f1c915b4ae90c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
FileName: Internals/SimpleStackTraceFactoryTests.cs,
Function: void SimpleStackTraceFactoryTests.GenericMethodThatThrows<T>(T value),
AbsolutePath: {ProjectDirectory}Internals/SimpleStackTraceFactoryTests.cs,
InApp: true,
AddressMode: rel:0
}
49 changes: 49 additions & 0 deletions test/Sentry.Tests/Internals/SimpleStackTraceFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Sentry.PlatformAbstractions;

// ReSharper disable once CheckNamespace
// Stack trace filters out Sentry frames by namespace
namespace Other.Tests.Internals;

// TODO: Create integration test to test this behaviour when publishing AOT apps
// See https://github.com/getsentry/sentry-dotnet/pull/2732#discussion_r1371006441
public class SimpleStackTraceFactoryTests
{
private class Fixture
{
public SentryOptions SentryOptions { get; } = new();
public SentryStackTraceFactory GetSut() => new(SentryOptions);
}

private readonly Fixture _fixture = new();

[Fact]
public Task MethodGeneric()
{
_fixture.SentryOptions.UseStackTraceFactory(new SimpleStackTraceFactory(_fixture.SentryOptions));

// Arrange
var i = 5;
var exception = Record.Exception(() => GenericMethodThatThrows(i));

_fixture.SentryOptions.AttachStacktrace = true;
var factory = _fixture.GetSut();

// Act
var stackTrace = factory.Create(exception);

// Assert;
var frame = stackTrace!.Frames.Single(x => x.Function!.Contains("GenericMethodThatThrows"));
return Verify(frame)
.IgnoreMembers<SentryStackFrame>(
x => x.Package,
x => x.LineNumber,
x => x.ColumnNumber,
x => x.InstructionAddress,
x => x.FunctionId)
.AddScrubber(x => x.Replace(@"\", @"/"));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void GenericMethodThatThrows<T>(T value) =>
throw new Exception();
}