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
@@ -0,0 +1,55 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;

using System;
using Maui.UIServices;
using Moq;
using Services;
using Shared.Logger;
using UIServices;
using ViewModels;
using Xunit;

public class HomePageViewModelTests
{
[Fact]
public void HomePageViewModel_BackButtonCommand_Execute_UserSelectsToLogout_LoginPageDisplayed()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
dialogService.Setup(d => d.ShowDialog(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<String>())).ReturnsAsync(true);
HomePageViewModel viewModel = new HomePageViewModel(applicationCache.Object,
dialogService.Object,
navigationService.Object);
Logger.Initialise(NullLogger.Instance);

viewModel.BackButtonCommand.Execute(null);

navigationService.Verify(n => n.GoToLoginPage(), Times.Once);
dialogService.Verify(d => d.ShowDialog(It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>()), Times.Once);
}

[Fact]
public void HomePageViewModel_BackButtonCommand_Execute_UserSelectsNotToLogout_LoginPageDisplayed()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
dialogService.Setup(d => d.ShowDialog(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<String>(), It.IsAny<String>())).ReturnsAsync(false);
HomePageViewModel viewModel = new HomePageViewModel(applicationCache.Object,
dialogService.Object,
navigationService.Object);
Logger.Initialise(NullLogger.Instance);

viewModel.BackButtonCommand.Execute(null);

navigationService.VerifyNoOtherCalls();
dialogService.Verify(d => d.ShowDialog(It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>()), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Services;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.MyAccount;
using Xunit;

Expand All @@ -20,10 +21,12 @@ public async Task MyAccountAddressPageViewModel_Initialise_IsInitialised()
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
applicationCache.Setup(a => a.GetMerchantDetails()).Returns(TestData.MerchantDetailsModel);
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();

MyAccountAddressPageViewModel viewModel = new MyAccountAddressPageViewModel(navigationService.Object,
applicationCache.Object,
dialogService.Object,
mediator.Object);
await viewModel.Initialise(CancellationToken.None);

Expand All @@ -37,4 +40,21 @@ public async Task MyAccountAddressPageViewModel_Initialise_IsInitialised()
viewModel.Address.Town.ShouldBe(TestData.Town);
viewModel.Address.PostalCode.ShouldBe(TestData.PostalCode);
}

[Fact]
public async Task MyAccountAddressPageViewModel_BackButtonCommand_PreviousPageIsShown()
{
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();
MyAccountAddressPageViewModel viewModel = new MyAccountAddressPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);

viewModel.BackButtonCommand.Execute(null);

navigationService.Verify(n => n.GoBack(), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Services;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.MyAccount;
using Xunit;

Expand All @@ -20,11 +21,11 @@ public async Task MyAccountContactPageViewModel_Initialise_IsInitialised()
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
applicationCache.Setup(a => a.GetMerchantDetails()).Returns(TestData.MerchantDetailsModel);
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();

MyAccountContactPageViewModel viewModel = new MyAccountContactPageViewModel(navigationService.Object,
applicationCache.Object,
mediator.Object);
dialogService.Object);
await viewModel.Initialise(CancellationToken.None);

applicationCache.Verify(a => a.GetMerchantDetails(), Times.Once);
Expand All @@ -33,4 +34,19 @@ public async Task MyAccountContactPageViewModel_Initialise_IsInitialised()
viewModel.Contact.Name.ShouldBe(TestData.ContactName);
viewModel.Contact.MobileNumber.ShouldBe(TestData.ContactMobileNumber);
}

[Fact]
public async Task MyAccountContactPageViewModel_BackButtonCommand_PreviousPageIsShown()
{
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
MyAccountContactPageViewModel viewModel = new MyAccountContactPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object);

viewModel.BackButtonCommand.Execute(null);

navigationService.Verify(n => n.GoBack(), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Services;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.MyAccount;
using Xunit;

Expand All @@ -20,11 +21,11 @@ public async Task MyAccountDetailsPageViewModel_Initialise_IsInitialised()
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
applicationCache.Setup(a => a.GetMerchantDetails()).Returns(TestData.MerchantDetailsModel);
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();

MyAccountDetailsPageViewModel viewModel = new MyAccountDetailsPageViewModel(navigationService.Object,
applicationCache.Object,
mediator.Object);
dialogService.Object);
await viewModel.Initialise(CancellationToken.None);

applicationCache.Verify(a => a.GetMerchantDetails(), Times.Once);
Expand All @@ -35,4 +36,19 @@ public async Task MyAccountDetailsPageViewModel_Initialise_IsInitialised()
viewModel.NextStatementDate.ShouldBe(TestData.NextStatementDate);
viewModel.SettlementSchedule.ShouldBe(TestData.SettlementSchedule);
}

[Fact]
public async Task MyAccountDetailsPageViewModel_BackButtonCommand_PreviousPageIsShown()
{
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
MyAccountDetailsPageViewModel viewModel = new MyAccountDetailsPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object);

viewModel.BackButtonCommand.Execute(null);

navigationService.Verify(n => n.GoBack(), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Services;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.MyAccount;
using Xunit;

Expand All @@ -25,10 +26,14 @@ public async Task MyAccountPageViewModel_Initialise_IsInitialised() {
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();

MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);
mediator.Setup(m => m.Send(It.IsAny<GetMerchantDetailsRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.MerchantDetailsModel);

MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object, mediator.Object);
await viewModel.Initialise(CancellationToken.None);

viewModel.MerchantName.ShouldBe(TestData.MerchantDetailsModel.MerchantName);
Expand All @@ -41,8 +46,12 @@ public void MyAccountPageViewModel_OptionSelectedCommand_AccountInfo_Execute_IsE
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object, mediator.Object);

MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);
viewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.AccountInfo));

navigationService.Verify(n => n.GoToMyAccountDetails(), Times.Once);
Expand All @@ -53,9 +62,12 @@ public void MyAccountPageViewModel_OptionSelectedCommand_Addresses_Execute_IsExe
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();

MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object, mediator.Object);
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);
viewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.Addresses));

navigationService.Verify(n => n.GoToMyAccountAddresses(), Times.Once);
Expand All @@ -66,9 +78,12 @@ public void MyAccountPageViewModel_OptionSelectedCommand_Contacts_Execute_IsExec
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();

MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object, mediator.Object);
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);
viewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.Contacts));

navigationService.Verify(n => n.GoToMyAccountContacts(), Times.Once);
Expand All @@ -79,14 +94,35 @@ public void MyAccountPageViewModel_OptionSelectedCommand_Logout_Execute_IsExecut
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object, mediator.Object);

MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);

viewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.Logout));

navigationService.Verify(n => n.GoToLoginPage(), Times.Once);
}

[Fact]
public async Task MyAccountPageViewModel_BackButtonCommand_HomePageIsShown()
{
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Mock<IMediator> mediator = new Mock<IMediator>();
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object,
dialogService.Object,
mediator.Object);

viewModel.BackButtonCommand.Execute(null);

navigationService.Verify(n=> n.GoToHome(),Times.Once);
}

private ItemSelected<ListViewItem> CreateItemSelected(MyAccountPageViewModel.AccountOptions selectedOption) {
ItemSelected<ListViewItem> i = new ItemSelected<ListViewItem>();
i.SelectedItemIndex = (Int32)selectedOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.Support
using TransactionMobile.Maui.Database;
using Shared.Logger;
using System.Collections.Generic;
using System.Threading;
using Requests;
using Services;

public class SupportPageViewModelTests
Expand All @@ -24,16 +26,43 @@ public void SupportPageViewModel_UploadLogsCommand_Execute_IsExecuted()
Mock<IDeviceService> deviceService = new Mock<IDeviceService>();
Mock<IApplicationInfoService> applicationInfoService = new Mock<IApplicationInfoService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Logger.Initialise(NullLogger.Instance);
SupportPageViewModel viewModel = new SupportPageViewModel(deviceService.Object,
applicationInfoService.Object,
databaseContext.Object,
mediator.Object,
navigationService.Object,
applicationCache.Object);
applicationCache.Object,
dialogService.Object);

viewModel.UploadLogsCommand.Execute(null);

mediator.Verify(m => m.Send(It.IsAny<UploadLogsRequest>(),It.IsAny<CancellationToken>()),Times.Once);
navigationService.Verify(n => n.GoToHome(), Times.Once);
}

[Fact]
public void SupportPageViewModel_BackButtonCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<IDeviceService> deviceService = new Mock<IDeviceService>();
Mock<IApplicationInfoService> applicationInfoService = new Mock<IApplicationInfoService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IDialogService> dialogService = new Mock<IDialogService>();
Logger.Initialise(NullLogger.Instance);
SupportPageViewModel viewModel = new SupportPageViewModel(deviceService.Object,
applicationInfoService.Object,
databaseContext.Object,
mediator.Object,
navigationService.Object,
applicationCache.Object,
dialogService.Object);

viewModel.BackButtonCommand.Execute(null);

navigationService.Verify(n => n.GoToHome(), Times.Once);
}
}
Expand Down
Loading