Skip to content

Commit d518620

Browse files
Some unit tests
1 parent 3460c28 commit d518620

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/Sentry.Maui/Internal/MauiEventsBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ private void OnElementOnFocused(object? sender, FocusEventArgs _) =>
416416
private void OnElementOnUnfocused(object? sender, FocusEventArgs _) =>
417417
_hub.AddBreadcrumbForEvent(_options, sender, nameof(VisualElement.Unfocused), SystemType, RenderingCategory);
418418

419-
private void OnElementLoaded(object? sender, EventArgs _)
419+
internal void OnElementLoaded(object? sender, EventArgs _)
420420
{
421421
if (sender is not VisualElement element)
422422
{

test/Sentry.Maui.Tests/MauiEventsBinderTests.VisualElement.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
using Sentry.Maui.Internal;
22
using Sentry.Maui.Tests.Mocks;
3+
using Application = Android.App.Application;
4+
#if __ANDROID__
5+
using View = Android.Views.View;
6+
#endif
37

48
namespace Sentry.Maui.Tests;
59

@@ -46,4 +50,34 @@ public void VisualElement_UnbindFocusEvents_DoesNotAddBreadcrumb(string eventNam
4650
// Assert
4751
Assert.Single(_fixture.Scope.Breadcrumbs);
4852
}
53+
54+
[Fact]
55+
public void OnElementLoaded_SenderIsNotVisualElement_LogsDebugAndReturns()
56+
{
57+
// Arrange
58+
var element = new MockElement("element");
59+
60+
// Act
61+
_fixture.Binder.OnElementLoaded(element, EventArgs.Empty);
62+
63+
// Assert
64+
_fixture.Options.DiagnosticLogger.Received(1).LogDebug("OnElementLoaded: sender is not a VisualElement");
65+
}
66+
67+
[Fact]
68+
public void OnElementLoaded_HandlerIsNull_LogsDebugAndReturns()
69+
{
70+
// Arrange
71+
var element = new MockVisualElement("element")
72+
{
73+
Handler = null
74+
};
75+
76+
// Act
77+
_fixture.Binder.OnElementLoaded(element, EventArgs.Empty);
78+
79+
// Assert
80+
_fixture.Options.DiagnosticLogger.Received(1).LogDebug("OnElementLoaded: handler is null");
81+
}
82+
4983
}

test/Sentry.Maui.Tests/MauiEventsBinderTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ public Fixture()
1818
hub.When(h => h.ConfigureScope(Arg.Any<Action<Scope>>()))
1919
.Do(c => c.Arg<Action<Scope>>()(Scope));
2020

21+
Options.Debug = true;
22+
var logger = Substitute.For<IDiagnosticLogger>();
23+
logger.IsEnabled(Arg.Any<SentryLevel>()).Returns(true);
24+
Options.DiagnosticLogger = logger;
2125
var options = Microsoft.Extensions.Options.Options.Create(Options);
2226
Binder = new MauiEventsBinder(
2327
hub,

0 commit comments

Comments
 (0)