Skip to content

Commit 86b25b9

Browse files
committed
Passing tests
1 parent c55a364 commit 86b25b9

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/Sentry.Maui.CommunityToolkit.Mvvm/CtMvvmMauiElementEventBinder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ private void RelayCommandOnPropertyChanged(object? sender, PropertyChangedEventA
130130
if (relay.IsRunning)
131131
{
132132
var transaction = hub.StartTransaction("ctmvvm", "relay.command");
133+
hub.ConfigureScope(x => x.Transaction ??= transaction);
134+
133135
_contexts.TryAdd(relay, transaction);
134136
}
135137
else if (_contexts.TryGetValue(relay, out var value))

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using CommunityToolkit.Mvvm.Input;
3-
using Sentry.Maui.Internal;
4-
using Sentry.Maui.Tests.Mocks;
3+
using Sentry.Maui.CommunityToolkitMvvm;
54

65
namespace Sentry.Maui.Tests;
76

87
public partial class MauiEventsBinderTests
98
{
109
[Fact]
11-
public async Task AsyncRelayCommand_AddsSpan()
10+
public async Task AsyncRelayCommand_AddsTransaction()
1211
{
1312
var vm = new TestCtMvvmViewModel();
14-
button.Command = vm.TestCommand;
15-
16-
_fixture.Binder.OnApplicationOnDescendantAdded(null, new ElementEventArgs(button));
13+
var button = new Button
14+
{
15+
Command = vm.TestCommand
16+
};
17+
//_fixture.Binder.OnApplicationOnDescendantAdded(null, new ElementEventArgs(button));
18+
var binder = new CtMvvmMauiElementEventBinder(_fixture.Hub);
19+
binder.Bind(button, _ => {});
1720

1821
button.Command.Execute(null!);
1922

2023
// we need to wait for async command to run
2124
await Task.Delay(TimeSpan.FromSeconds(1.1));
2225

2326
// Assert
24-
_fixture.Scope.Span.Should().NotBeNull();
27+
_fixture.Scope.Transaction.Should().NotBeNull("Transaction should be created");
28+
_fixture.Scope.Transaction!.Name.Should().Be("ctmvvm");
29+
_fixture.Scope.Transaction!.Status.Should().Be(SpanStatus.Ok, "Transaction should be ok");
2530
}
2631
}
2732

test/Sentry.Maui.Tests/MauiEventsBinderTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public partial class MauiEventsBinderTests
77
{
88
private class Fixture
99
{
10+
public IHub Hub { get; }
11+
1012
public MauiEventsBinder Binder { get; }
1113

1214
public Scope Scope { get; } = new();
@@ -15,8 +17,8 @@ private class Fixture
1517

1618
public Fixture()
1719
{
18-
var hub = Substitute.For<IHub>();
19-
hub.When(h => h.ConfigureScope(Arg.Any<Action<Scope>>()))
20+
Hub = Substitute.For<IHub>();
21+
Hub.When(h => h.ConfigureScope(Arg.Any<Action<Scope>>()))
2022
.Do(c => c.Arg<Action<Scope>>()(Scope));
2123

2224
Options.Debug = true;
@@ -25,12 +27,12 @@ public Fixture()
2527
Options.DiagnosticLogger = logger;
2628
var options = Microsoft.Extensions.Options.Options.Create(Options);
2729
Binder = new MauiEventsBinder(
28-
hub,
30+
Hub,
2931
options,
3032
[
3133
new MauiButtonEventsBinder(),
3234
new MauiImageButtonEventsBinder(),
33-
new CtMvvmMauiElementEventBinder(hub)
35+
new CtMvvmMauiElementEventBinder(Hub)
3436
]
3537
);
3638
}

0 commit comments

Comments
 (0)