Skip to content
Merged
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
Device tests - SentryMauiLogcatsTests | Add logcat tests type
  • Loading branch information
bricefriha committed Oct 30, 2024
commit defbf1ab1bbde310436eaaa3819f55824089357a
72 changes: 72 additions & 0 deletions test/Sentry.Maui.Tests/SentryMauiLogcatsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
Loading