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
Refactored custom event binders into separate test classes
  • Loading branch information
jamescrosswell committed Jun 6, 2025
commit ad5a8d5de551b80fcf93c1f86f50e84cf55b9876
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Sentry.Maui.Tests;

public partial class MauiEventsBinderTests
public class MauiButtonEventsBinderTests
{
private readonly MauiEventsBinderFixture _fixture = new(new MauiButtonEventsBinder());

[Theory]
[InlineData(nameof(Button.Clicked))]
[InlineData(nameof(Button.Pressed))]
Expand Down
37 changes: 37 additions & 0 deletions test/Sentry.Maui.Tests/MauiEventsBinderFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Sentry.Maui.Internal;

namespace Sentry.Maui.Tests;

internal class MauiEventsBinderFixture
{
public IHub Hub { get; }

public MauiEventsBinder Binder { get; }

public Scope Scope { get; } = new();

public SentryMauiOptions Options { get; } = new();

public MauiEventsBinderFixture(params IEnumerable<IMauiElementEventBinder> elementEventBinders)
{
Hub = Substitute.For<IHub>();
Hub.When(h => h.ConfigureScope(Arg.Any<Action<Scope>>()))
.Do(c =>
{
c.Arg<Action<Scope>>()(Scope);
});

Scope.Transaction = Substitute.For<ITransactionTracer>();

Options.Debug = true;
var logger = Substitute.For<IDiagnosticLogger>();
logger.IsEnabled(Arg.Any<SentryLevel>()).Returns(true);
Options.DiagnosticLogger = logger;
var options = Microsoft.Extensions.Options.Options.Create(Options);
Binder = new MauiEventsBinder(
Hub,
options,
elementEventBinders
);
}
}
42 changes: 2 additions & 40 deletions test/Sentry.Maui.Tests/MauiEventsBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,9 @@ namespace Sentry.Maui.Tests;

public partial class MauiEventsBinderTests
{
private class Fixture
{
public IHub Hub { get; }

public MauiEventsBinder Binder { get; }

public Scope Scope { get; } = new();

public SentryMauiOptions Options { get; } = new();

public Fixture()
{
Hub = Substitute.For<IHub>();
Hub.When(h => h.ConfigureScope(Arg.Any<Action<Scope>>()))
.Do(c =>
{
c.Arg<Action<Scope>>()(Scope);
});

Scope.Transaction = Substitute.For<ITransactionTracer>();

Options.Debug = true;
var logger = Substitute.For<IDiagnosticLogger>();
logger.IsEnabled(Arg.Any<SentryLevel>()).Returns(true);
Options.DiagnosticLogger = logger;
var options = Microsoft.Extensions.Options.Options.Create(Options);
Binder = new MauiEventsBinder(
Hub,
options,
[
new MauiButtonEventsBinder(),
new MauiImageButtonEventsBinder(),
new MauiGestureRecognizerEventsBinder()
]
);
}
}

private readonly Fixture _fixture = new();
private readonly MauiEventsBinderFixture _fixture = new();

// Tests are in partial class files for better organization
// Most of the tests for this class are in separate partial class files for better organisation

[Fact]
public void OnBreadcrumbCreateCallback_CreatesBreadcrumb()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Sentry.Maui.Tests;

public partial class MauiEventsBinderTests
public class MauiGestureRecognizerEventsBinderTests
{
private readonly MauiEventsBinderFixture _fixture = new(new MauiGestureRecognizerEventsBinder());

[SkippableFact]
public void TapGestureRecognizer_LifecycleEvents_AddsBreadcrumb()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Sentry.Maui.Tests;

public partial class MauiEventsBinderTests
public class MauiImageButtonEventsBinderTests
{
private readonly MauiEventsBinderFixture _fixture = new(new MauiImageButtonEventsBinder());

[Theory]
[InlineData(nameof(ImageButton.Clicked))]
[InlineData(nameof(ImageButton.Pressed))]
Expand Down
Loading