-
-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathSentryMauiLogcatsTests.cs
More file actions
72 lines (60 loc) · 2.37 KB
/
SentryMauiLogcatsTests.cs
File metadata and controls
72 lines (60 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using Microsoft.Extensions.Options;
#if ANDROID
using Sentry.Android;
#endif
namespace Sentry.Maui.Tests;
public class SentryMauiLogcatsTests
{
private class Fixture
{
public MauiAppBuilder Builder { get; }
public FakeTransport Transport { get; private set; } = new FakeTransport();
public InMemoryDiagnosticLogger Logger { get; private set; } = new InMemoryDiagnosticLogger();
public Fixture()
{
var builder = MauiApp.CreateBuilder();
builder.Services.AddSingleton(Substitute.For<IApplication>());
builder.Services.Configure<SentryMauiOptions>(options =>
{
options.Transport = Transport;
options.Dsn = ValidDsn;
options.AttachScreenshot = false; //Disable the screenshot attachment to have the logcat as primary attachment
options.Debug = true;
options.DiagnosticLogger = Logger;
options.AutoSessionTracking = false; //Get rid of session envelope for easier Assert
options.CacheDirectoryPath = null; //Do not wrap our FakeTransport with a caching transport
options.FlushTimeout = TimeSpan.FromSeconds(10);
});
Builder = builder;
}
}
private readonly Fixture _fixture = new();
#if __MOBILE__
[SkippableFact]
public void CaptureException_CheckLogcatType()
{
#if __IOS__
Skip.If(true, "Doesn't support logcats");
#endif
var builder = _fixture.Builder.UseSentry(options =>
{
#if ANDROID
options.Android.LogCatIntegration = Android.LogCatIntegrationType.All;
#endif
});
// Arrange
var processor = Substitute.For<ISentryEventProcessorWithHint>();
using var app = builder.Build();
SentryHint hint = null;
var options = app.Services.GetRequiredService<IOptions<SentryMauiOptions>>().Value;
var scope = new Scope(options);
// Act
processor.Process(Arg.Any<SentryEvent>(), Arg.Do<SentryHint>(h => hint = h)).Returns(new SentryEvent());
options.AddEventProcessor(processor);
_ = new SentryClient(options).CaptureEvent(new SentryEvent(), scope);
// Assert
hint.Should().NotBeNull();
hint.Attachments.First().ContentType.Should().Be("text/plain", hint.Attachments.First().ContentType);
}
#endif
}