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,11 +52,24 @@ public async Task SupportPageViewModel_UploadLogsCommand_Execute_IsExecuted(){
this.ViewModel.LogMessages.Count.ShouldBe(1);
}

[Fact]
public async Task ViewLogsPageViewModel_LoadLogMessages_RaisesPropertyChanged(){
this.Mediator.Setup(m => m.Send(It.IsAny<SupportQueries.ViewLogsQuery>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(new List<LogMessage>(){
new LogMessage()
}));
String? changedPropertyName = null;
this.ViewModel.PropertyChanged += (_, args) => changedPropertyName = args.PropertyName;

await this.ViewModel.LoadLogMessages();

changedPropertyName.ShouldBe(nameof(ViewLogsPageViewModel.LogMessages));
}

[Fact]
public void ViewLogsPageViewModel_BackButtonCommand_Execute_IsExecuted()
{
this.ViewModel.BackButtonCommand.Execute(null);

this.NavigationService.Verify(n => n.GoBack(), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ViewLogsPageViewModel : ExtendedBaseViewModel
#region Fields

private readonly IMediator Mediator;
private List<LogMessageModel> logMessages = new();

#endregion

Expand All @@ -31,7 +32,10 @@ public ViewLogsPageViewModel(IMediator mediator,

#region Properties

public List<LogMessageModel> LogMessages { get; private set; }
public List<LogMessageModel> LogMessages {
get => this.logMessages;
private set => this.SetProperty(ref this.logMessages, value);
}

#endregion

Expand Down Expand Up @@ -59,4 +63,4 @@ public async Task LoadLogMessages() {
}

#endregion
}
}
31 changes: 16 additions & 15 deletions TransactionProcessor.Mobile/Extensions/MauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public static MauiAppBuilder ConfigureAppServices(this MauiAppBuilder builder) {
return factory.CreateClient("default");
});

builder.Services.AddSingleton(new Func<String, String>(configSetting => {
IApplicationCache applicationCache = MauiProgram.Container.Services.GetService<IApplicationCache>();
builder.Services.AddSingleton<Func<String, String>>(serviceProvider => configSetting => {
IApplicationCache applicationCache = serviceProvider.GetService<IApplicationCache>();

if (applicationCache != null)
return configSetting switch {
Expand All @@ -75,7 +75,7 @@ public static MauiAppBuilder ConfigureAppServices(this MauiAppBuilder builder) {
};

return null;
}));
});

builder.Services.AddSingleton<IConfigurationService, ConfigurationService>();
builder.Services.AddSingleton<IAuthenticationService, AuthenticationService>();
Expand Down Expand Up @@ -103,50 +103,50 @@ public static MauiAppBuilder ConfigureAppServices(this MauiAppBuilder builder) {
}

private static MauiAppBuilder RegisterConfigurationService(this MauiAppBuilder builder) {
builder.Services.AddSingleton(new Func<Boolean, IConfigurationService>(useTrainingMode =>
builder.Services.AddSingleton<Func<Boolean, IConfigurationService>>(serviceProvider => useTrainingMode =>
{
return useTrainingMode switch {
true => new TrainingConfigurationService(),
_ => MauiProgram.Container.Services.GetService<IConfigurationService>()
_ => serviceProvider.GetService<IConfigurationService>()
} ?? throw new InvalidOperationException("Failed to resolve IConfigurationService.");
}));
});
return builder;
}

private static MauiAppBuilder RegisterAuthenticationService(this MauiAppBuilder builder)
{
builder.Services.AddSingleton(new Func<Boolean, IAuthenticationService>(useTrainingMode => {
builder.Services.AddSingleton<Func<Boolean, IAuthenticationService>>(serviceProvider => useTrainingMode => {
return useTrainingMode switch
{
true => new TrainingAuthenticationService(),
_ => MauiProgram.Container.Services.GetService<IAuthenticationService>()
_ => serviceProvider.GetService<IAuthenticationService>()
} ?? throw new InvalidOperationException("Failed to resolve IConfigurationService.");
}));
});
return builder;
}

private static MauiAppBuilder RegisterTransactionService(this MauiAppBuilder builder) {
builder.Services.AddSingleton(new Func<Boolean, ITransactionService>(useTrainingMode =>
builder.Services.AddSingleton<Func<Boolean, ITransactionService>>(serviceProvider => useTrainingMode =>
{
return useTrainingMode switch
{
true => new TrainingTransactionService(),
_ => MauiProgram.Container.Services.GetService<ITransactionService>()
_ => serviceProvider.GetService<ITransactionService>()
} ?? throw new InvalidOperationException("Failed to resolve ITransactionService.");
}));
});
return builder;
}

private static MauiAppBuilder RegisterMerchantService(this MauiAppBuilder builder)
{
builder.Services.AddSingleton(new Func<Boolean, IMerchantService>(useTrainingMode =>
builder.Services.AddSingleton<Func<Boolean, IMerchantService>>(serviceProvider => useTrainingMode =>
{
return useTrainingMode switch
{
true => new TrainingMerchantService(),
_ => MauiProgram.Container.Services.GetService<IMerchantService>()
_ => serviceProvider.GetService<IMerchantService>()
} ?? throw new InvalidOperationException("Failed to resolve ITransactionService.");
}));
});
return builder;
}

Expand Down Expand Up @@ -236,6 +236,7 @@ public static MauiAppBuilder ConfigureViewModels(this MauiAppBuilder builder) {
}

public static MauiAppBuilder ConfigurePages(this MauiAppBuilder builder) {
builder.Services.AddTransient<LoadingPage>();
builder.Services.AddTransient<LoginPage>();
builder.Services.AddTransient<HomePage>();
builder.Services.AddTransient<TransactionsPage>();
Expand Down
7 changes: 3 additions & 4 deletions TransactionProcessor.Mobile/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace TransactionProcessor.Mobile
{
public static class MauiProgram
{
public static MauiApp Container { get; private set; } = default!;
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
Expand All @@ -37,14 +36,14 @@ public static MauiApp CreateMauiApp()

builder.Logging.SetMinimumLevel(LogLevel.Trace);

Container = builder.Build();
MauiApp app = builder.Build();

var serialiser = Container.Services.GetRequiredService<IStringSerialiser>();
var serialiser = app.Services.GetRequiredService<IStringSerialiser>();
StringSerialiser.Initialise(serialiser);

Logger.Initialise(new ConsoleLogger());

return Container;
return app;
}
}

Expand Down
5 changes: 3 additions & 2 deletions TransactionProcessor.Mobile/Pages/AppHome/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public partial class HomePage : NoBackWithoutLogoutPage
public HomePage(HomePageViewModel vm,
IDialogService dialogService,
IApplicationCache applicationCache,
INavigationService navigationService) {
INavigationService navigationService)
: base(navigationService, dialogService, applicationCache) {
this.InitializeComponent();
this.BindingContext = vm;
}
Expand All @@ -33,4 +34,4 @@ protected override async void OnAppearing() {
}

#endregion
}
}
32 changes: 20 additions & 12 deletions TransactionProcessor.Mobile/Pages/Common/NoBackWithoutLogoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ namespace TransactionProcessor.Mobile.Pages.Common;

public class NoBackWithoutLogoutPage : ContentPage
{
private readonly INavigationService navigationService;
private readonly IDialogService dialogService;
private readonly IApplicationCache applicationCache;

protected NoBackWithoutLogoutPage(INavigationService navigationService,
IDialogService dialogService,
IApplicationCache applicationCache)
{
this.navigationService = navigationService;
this.dialogService = dialogService;
this.applicationCache = applicationCache;
}

protected override Boolean OnBackButtonPressed() {
Type type = this.GetType().UnderlyingSystemType;

Expand All @@ -28,24 +41,19 @@ protected override Boolean OnBackButtonPressed() {
}

private async Task ShowHomePage() {
INavigationService navigationService = MauiProgram.Container.Services.GetRequiredService<INavigationService>();
await navigationService.GoToHome();
await this.navigationService.GoToHome();
}

private async Task ShowLoginPage()
{
IDialogService dialogService = MauiProgram.Container.Services.GetRequiredService<IDialogService>();
IApplicationCache applicationCache = MauiProgram.Container.Services.GetRequiredService<IApplicationCache>();
INavigationService navigationService = MauiProgram.Container.Services.GetRequiredService<INavigationService>();

Boolean leave = await dialogService.ShowDialog("Title", "Logout Message", "yes", "no");
Boolean leave = await this.dialogService.ShowDialog("Title", "Logout Message", "yes", "no");
if (leave)
{
applicationCache.SetIsLoggedIn(false);
applicationCache.ClearAccessToken();
applicationCache.ClearMerchantDetails();
this.applicationCache.SetIsLoggedIn(false);
this.applicationCache.ClearAccessToken();
this.applicationCache.ClearMerchantDetails();

await navigationService.GoToLoginPage();
await this.navigationService.GoToLoginPage();
}
}
}
}
10 changes: 6 additions & 4 deletions TransactionProcessor.Mobile/Pages/LoadingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace TransactionProcessor.Mobile.Pages;

public partial class LoadingPage : ContentPage {
public LoadingPage() {
private readonly IApplicationCache applicationCache;

public LoadingPage(IApplicationCache applicationCache) {
Comment thread
StuartFerguson marked this conversation as resolved.
Resolved
InitializeComponent();
this.applicationCache = applicationCache;
}

protected override async void OnNavigatedTo(NavigatedToEventArgs args) {
Expand All @@ -20,8 +23,7 @@ protected override async void OnNavigatedTo(NavigatedToEventArgs args) {

async Task<bool> isAuthenticated() {
await Task.Delay(2000);
IApplicationCache applicationCache = MauiProgram.Container.Services.GetService<IApplicationCache>();
Boolean isLoggedIn = applicationCache.GetIsLoggedIn();
Boolean isLoggedIn = this.applicationCache.GetIsLoggedIn();
return isLoggedIn;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using TransactionProcessor.Mobile.BusinessLogic.Common;
using TransactionProcessor.Mobile.BusinessLogic.Models;
using TransactionProcessor.Mobile.BusinessLogic.Services;
using TransactionProcessor.Mobile.BusinessLogic.UIServices;
using TransactionProcessor.Mobile.BusinessLogic.ViewModels.MyAccount;
using TransactionProcessor.Mobile.Pages.Common;

Expand All @@ -9,7 +11,11 @@ public partial class MyAccountPage : NoBackWithoutLogoutPage
{
private MyAccountPageViewModel viewModel => BindingContext as MyAccountPageViewModel;

public MyAccountPage(MyAccountPageViewModel vm)
public MyAccountPage(MyAccountPageViewModel vm,
INavigationService navigationService,
IDialogService dialogService,
IApplicationCache applicationCache)
: base(navigationService, dialogService, applicationCache)
{
this.InitializeComponent();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using TransactionProcessor.Mobile.BusinessLogic.Common;
using TransactionProcessor.Mobile.BusinessLogic.Models;
using TransactionProcessor.Mobile.BusinessLogic.Services;
using TransactionProcessor.Mobile.BusinessLogic.UIServices;
using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Reports;
using TransactionProcessor.Mobile.Pages.Common;

Expand All @@ -9,7 +11,11 @@ public partial class ReportsPage : NoBackWithoutLogoutPage
{
private ReportsPageViewModel viewModel => BindingContext as ReportsPageViewModel;

public ReportsPage(ReportsPageViewModel vm)
public ReportsPage(ReportsPageViewModel vm,
INavigationService navigationService,
IDialogService dialogService,
IApplicationCache applicationCache)
: base(navigationService, dialogService, applicationCache)
{
this.InitializeComponent();
BindingContext = vm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using TransactionProcessor.Mobile.BusinessLogic.Services;
using TransactionProcessor.Mobile.BusinessLogic.UIServices;
using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Support;
using TransactionProcessor.Mobile.Pages.Common;

Expand All @@ -9,7 +11,11 @@ public partial class SupportPage : NoBackWithoutLogoutPage
{
private SupportPageViewModel viewModel => BindingContext as SupportPageViewModel;

public SupportPage(SupportPageViewModel vm) {
public SupportPage(SupportPageViewModel vm,
INavigationService navigationService,
IDialogService dialogService,
IApplicationCache applicationCache)
: base(navigationService, dialogService, applicationCache) {
this.InitializeComponent();
BindingContext = vm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public ViewLogsPage(ViewLogsPageViewModel vm) {
}

protected override async void OnAppearing() {
ViewLogsPageViewModel vm = MauiProgram.Container.Services.GetRequiredService<ViewLogsPageViewModel>();
await vm.LoadLogMessages();
this.BindingContext = vm;
await this.viewModel.LoadLogMessages();
Comment thread
StuartFerguson marked this conversation as resolved.
Resolved
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions;
using TransactionProcessor.Mobile.BusinessLogic.Services;
using TransactionProcessor.Mobile.BusinessLogic.UIServices;
using TransactionProcessor.Mobile.Pages.Common;

namespace TransactionProcessor.Mobile.Pages.Transactions;
Expand All @@ -7,7 +9,11 @@ public partial class TransactionsPage : NoBackWithoutLogoutPage
{
private TransactionsPageViewModel viewModel => BindingContext as TransactionsPageViewModel;

public TransactionsPage(TransactionsPageViewModel vm)
public TransactionsPage(TransactionsPageViewModel vm,
INavigationService navigationService,
IDialogService dialogService,
IApplicationCache applicationCache)
: base(navigationService, dialogService, applicationCache)
{
this.InitializeComponent();
BindingContext = vm;
Expand All @@ -17,4 +23,4 @@ protected override async void OnAppearing()
{
base.OnAppearing();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ namespace TransactionProcessor.Mobile.UIServices;
public class ShellNavigationService : INavigationService
{
private readonly INavigationParameterService NavigationParameterService;
private readonly IServiceProvider ServiceProvider;

#region Methods

public ShellNavigationService(INavigationParameterService navigationParameterService) {
public ShellNavigationService(INavigationParameterService navigationParameterService,
IServiceProvider serviceProvider) {
this.NavigationParameterService = navigationParameterService;
this.ServiceProvider = serviceProvider;
}

public async Task QuitApplication(){
Expand Down Expand Up @@ -172,7 +175,7 @@ public async Task GoToViewLogsPage() {
}

public async Task GoToMyAccountAddresses() {
MyAccountAddressesPage p = (MyAccountAddressesPage)MauiProgram.Container.Services.GetService(typeof(MyAccountAddressesPage));
MyAccountAddressesPage p = this.ServiceProvider.GetRequiredService<MyAccountAddressesPage>();
await this.NavigateTo(p);
}

Expand Down
Loading