Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public async Task ConfigurationService_GetConfiguration_ResultSuccess_And_Config
DeviceIdentifier = TestData.DeviceIdentifier,
LogLevel = configLoggingLevel,
Id = Guid.NewGuid().ToString(),
SentryDsn = "https://[email protected]/123",
};
Logger.Initialise(new NullLogger());

Expand All @@ -68,6 +69,7 @@ public async Task ConfigurationService_GetConfiguration_ResultSuccess_And_Config
configurationResult.Data.SecurityServiceUri.ShouldBe(expectedConfiguration.HostAddresses.Single(s => s.ServiceType == ServiceType.Security).Uri);
configurationResult.Data.TransactionProcessorAclUri.ShouldBe(expectedConfiguration.HostAddresses.Single(s => s.ServiceType == ServiceType.TransactionProcessorAcl).Uri);
configurationResult.Data.LogLevel.ShouldBe(expectedLogLevel);
configurationResult.Data.SentryDsn.ShouldBe(expectedConfiguration.SentryDsn);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class LoginPageViewModelTests
private readonly Mock<IUpdateService> UpdateService;

private readonly Mock<IBalanceRefresher> BalanceRefresher;

private readonly Mock<ISentryService> SentryService;

public LoginPageViewModelTests() {
this.Mediator = new Mock<IMediator>();
this.NavigationService = new Mock<INavigationService>();
Expand All @@ -46,13 +49,14 @@ public LoginPageViewModelTests() {
this.DialogService = new Mock<IDialogService>();
this.UpdateService = new Mock<IUpdateService>();
this.BalanceRefresher = new Mock<IBalanceRefresher>();
this.SentryService = new Mock<ISentryService>();


this.ViewModel = new LoginPageViewModel(this.Mediator.Object, this.NavigationService.Object, this.ApplicationCache.Object,
this.DeviceService.Object, this.ApplicationInfoService.Object,
this.DialogService.Object, this.NavigationParameterService.Object,
this.UpdateService.Object, this.ApplicationUpdateLauncherService.Object,
this.BalanceRefresher.Object);
this.BalanceRefresher.Object, this.SentryService.Object);
Logger.Initialise(new Logging.NullLogger());
}

Expand Down Expand Up @@ -281,6 +285,21 @@ public void LoginPageViewModel_BackButtonCommand_Execute_IsExecuted()
this.ViewModel.BackButtonCommand.Execute(null);
this.NavigationService.Verify(n => n.QuitApplication(), Times.Once);
}

[Fact]
public async Task LoginPageViewModel_LoginCommand_Execute_SentryInitialisedWithDsnFromConfiguration()
{
String sentryDsn = "https://[email protected]/123";
this.Mediator.Setup(m => m.Send(It.IsAny<LogonQueries.GetConfigurationQuery>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success(new Configuration { SentryDsn = sentryDsn }));
this.Mediator.Setup(m => m.Send(It.IsAny<LogonCommands.GetTokenCommand>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.AccessToken));
this.Mediator.Setup(m => m.Send(It.IsAny<TransactionCommands.PerformLogonCommand>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel));
this.Mediator.Setup(m => m.Send(It.IsAny<MerchantQueries.GetContractProductsQuery>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.ContractProductList));

await this.ViewModel.LogonCommand.ExecuteAsync(null);

this.SentryService.Verify(s => s.InitializeSentry(sentryDsn), Times.Once);
}

[Fact]
public void LoginPageViewModel_PropertyTests_ValuesAreAsExpected(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public class Configuration

public Boolean ShowDebugMessages { get; set; }
public Int32? LogMessageBatchSize { get; set; }
public String SentryDsn { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public async Task<Result<Configuration>> GetConfiguration(String deviceIdentifie
TransactionProcessorAclUri =
apiResponse.HostAddresses.Single(h => h.ServiceType == ServiceType.TransactionProcessorAcl).Uri,
LogMessageBatchSize = apiResponse.LogMessageBatchSize.GetValueOrDefault(),
SentryDsn = apiResponse.SentryDsn ?? String.Empty,
};

Logger.LogDebug($"About to xlate log level");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public class ConfigurationResponse
public LoggingLevel LogLevel { get; set; }

public Int32? LogMessageBatchSize { get; set; }

public String SentryDsn { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public async Task<Result<Configuration>> GetConfiguration(String deviceIdentifie
EstateReportingUri = "http://localhost:5006",
LogLevel = LogLevel.Debug,
SecurityServiceUri = "http://localhost:5001",
TransactionProcessorAclUri = "http://localhost:5003"
});
TransactionProcessorAclUri = "http://localhost:5003",
SentryDsn = "https://22dde94969082eb69783ee0beb25f401@o4504618032693248.ingest.us.sentry.io/4511070608293888",
});
}

public async Task PostDiagnosticLogs(String deviceIdentifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TransactionProcessor.Mobile.BusinessLogic.UIServices
{
public interface ISentryService
{
void InitializeSentry(String dsn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public partial class LoginPageViewModel : ExtendedBaseViewModel
private readonly IApplicationUpdateLauncherService ApplicationUpdateLauncherService;
private readonly IBalanceRefresher BalanceRefresher;
private readonly IUpdateService UpdateService;
private readonly ISentryService SentryService;

private String userName;

Expand All @@ -39,13 +40,15 @@ public LoginPageViewModel(IMediator mediator, INavigationService navigationServi
INavigationParameterService navigationParameterService,
IUpdateService updateService,
IApplicationUpdateLauncherService applicationUpdateLauncherService,
IBalanceRefresher balanceRefresher) : base(applicationCache,dialogService,navigationService, deviceService, navigationParameterService)
IBalanceRefresher balanceRefresher,
ISentryService sentryService) : base(applicationCache,dialogService,navigationService, deviceService, navigationParameterService)
{
this.ApplicationInfoService = applicationInfoService;
this.ApplicationUpdateLauncherService = applicationUpdateLauncherService;
this.BalanceRefresher = balanceRefresher;
this.Mediator = mediator;
this.UpdateService = updateService;
this.SentryService = sentryService;
}

#endregion
Expand Down Expand Up @@ -96,6 +99,8 @@ private async Task<Result<Configuration>> GetConfiguration() {
if (configurationResult.IsSuccess) {
// Cache the config object
this.ApplicationCache.SetConfiguration(configurationResult.Data);
// Initialise Sentry with the DSN from the configuration service
this.SentryService.InitializeSentry(configurationResult.Data.SentryDsn);
}

return configurationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static MauiAppBuilder ConfigureUIServices(this MauiAppBuilder builder) {
builder.Services.AddSingleton<IApplicationUpdateLauncherService, ApplicationUpdateLauncherService>();
builder.Services.AddSingleton<IApplicationThemeService, ApplicationThemeService>();
builder.Services.AddSingleton<INavigationParameterService, NavigationParameterService>();
builder.Services.AddSingleton<ISentryService, SentryService>();
return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<PackageReference Include="banditoth.MAUI.DeviceId" Version="1.0.2" />
<PackageReference Include="CommunityToolkit.Maui" Version="13.0.0" />
<PackageReference Include="LiveChartsCore.SkiaSharpView.Maui" Version="2.0.0-rc2" />
<PackageReference Include="Sentry.Maui" Version="6.4.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-android'">
Expand Down
34 changes: 34 additions & 0 deletions TransactionProcessor.Mobile/UIServices/SentryService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Sentry;
using TransactionProcessor.Mobile.BusinessLogic.UIServices;

namespace TransactionProcessor.Mobile.UIServices;

public class SentryService : ISentryService
{
private readonly IApplicationInfoService ApplicationInfoService;
private Boolean isInitialized;

public SentryService(IApplicationInfoService applicationInfoService) {
this.ApplicationInfoService = applicationInfoService;
}

public void InitializeSentry(String dsn)
{
if (this.isInitialized || String.IsNullOrWhiteSpace(dsn))
{
return;
}

SentrySdk.Init(o =>
{
o.Dsn = dsn;
#if ANDROID || IOS || MACCATALYST
o.Native.AttachScreenshot = true;
#endif
o.SendDefaultPii = true;
o.Release = this.ApplicationInfoService.VersionString;
});

this.isInitialized = true;
}
}
Loading