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
2 changes: 1 addition & 1 deletion src/Sentry.Maui/IMauiElementEventBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public interface IMauiElementEventBinder
public record BreadcrumbEvent(
object? Sender,
string EventName,
params IEnumerable<(string Key, string Value)>[] ExtraData
params (string Key, string Value)[] ExtraData
);
9 changes: 8 additions & 1 deletion src/Sentry.Maui/Internal/MauiEventsBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ internal void OnBreadcrumbCreateCallback(BreadcrumbEvent breadcrumb)
breadcrumb.Sender,
breadcrumb.EventName,
UserType,
UserActionCategory
UserActionCategory,
extra =>
{
foreach (var (key, value) in breadcrumb.ExtraData)
{
extra[key] = value;
}
}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static void OnPointerEnteredGesture(object? sender, PointerEventArgs e)
ToPointerData(e)
));

private static IEnumerable<(string Key, string Value)> ToPointerData(PointerEventArgs e) =>
private static (string Key, string Value)[] ToPointerData(PointerEventArgs e) =>
[
#if ANDROID
("MotionEventAction", e.PlatformArgs?.MotionEvent.Action.ToString() ?? string.Empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace Sentry.Maui
{
public BreadcrumbEvent(object? Sender, string EventName, [System.Runtime.CompilerServices.TupleElementNames(new string[] {
"Key",
"Value"})] params System.Collections.Generic.IEnumerable<System.ValueTuple<string, string>>[] ExtraData) { }
"Value"})] params System.ValueTuple<string, string>[] ExtraData) { }
public string EventName { get; init; }
[System.Runtime.CompilerServices.TupleElementNames(new string[] {
"Key",
"Value"})]
public System.Collections.Generic.IEnumerable<System.ValueTuple<string, string>>[] ExtraData { get; init; }
public System.ValueTuple<string, string>[] ExtraData { get; init; }
public object? Sender { get; init; }
}
public interface IMauiElementEventBinder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ namespace Sentry.Maui
{
public BreadcrumbEvent(object? Sender, string EventName, [System.Runtime.CompilerServices.TupleElementNames(new string[] {
"Key",
"Value"})] params System.Collections.Generic.IEnumerable<System.ValueTuple<string, string>>[] ExtraData) { }
"Value"})] params System.ValueTuple<string, string>[] ExtraData) { }
public string EventName { get; init; }
[System.Runtime.CompilerServices.TupleElementNames(new string[] {
"Key",
"Value"})]
public System.Collections.Generic.IEnumerable<System.ValueTuple<string, string>>[] ExtraData { get; init; }
public System.ValueTuple<string, string>[] ExtraData { get; init; }
public object? Sender { get; init; }
}
public interface IMauiElementEventBinder
Expand Down
28 changes: 28 additions & 0 deletions test/Sentry.Maui.Tests/MauiEventsBinderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,32 @@ public Fixture()
private readonly Fixture _fixture = new();

// Tests are in partial class files for better organization

[Fact]
public void OnBreadcrumbCreateCallback_CreatesBreadcrumb()
{
// Arrange
var breadcrumbEvent = new BreadcrumbEvent(new object(), "TestName",
("key1", "value1"), ("key2", "value2")
);

// Act
_fixture.Binder.OnBreadcrumbCreateCallback(breadcrumbEvent);

// Assert
using (new AssertionScope())
{
var crumb = Assert.Single(_fixture.Scope.Breadcrumbs);
Assert.Equal("Object.TestName", crumb.Message);
Assert.Equal(BreadcrumbLevel.Info, crumb.Level);
Assert.Equal(MauiEventsBinder.UserType, crumb.Type);
Assert.Equal(MauiEventsBinder.UserActionCategory, crumb.Category);
Assert.NotNull(crumb.Data);
Assert.Equal(breadcrumbEvent.ExtraData.Length, crumb.Data.Count);
foreach (var (key, value) in breadcrumbEvent.ExtraData)
{
crumb.Data.Should().Contain(kvp => kvp.Key == key && kvp.Value == value);
}
}
}
}
Loading