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
50 changes: 50 additions & 0 deletions TransactionMobile.Maui.BusinessLogic.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,56 @@ public static class TestData
RequireApplicationUpdate = false,
ResponseMessage = "FAILED"
};

public static MerchantDetailsModel MerchantDetailsModel => new MerchantDetailsModel {
MerchantName = TestData.MerchantName,
Contact = new ContactModel {
Name = TestData.ContactName,
EmailAddress = TestData.ContactEmailAddress,
MobileNumber = TestData.ContactMobileNumber
},
Address = new AddressModel {
AddressLine2 = TestData.AddressLine2,
Town = TestData.Town,
AddressLine4 = TestData.AddressLine4,
PostalCode = TestData.PostalCode,
Region = TestData.Region,
AddressLine3 = TestData.AddressLine3,
AddressLine1 = TestData.AddressLine1
},
AvailableBalance = TestData.AvailableBalance,
Balance = TestData.Balance,
LastStatementDate = TestData.LastStatementDate,
NextStatementDate = TestData.NextStatementDate,
SettlementSchedule = TestData.SettlementSchedule
};

public static Decimal Balance = 100.00m;

public static Decimal AvailableBalance = 99.00m;

public static String MerchantName = "Test Merchant";

public static DateTime NextStatementDate = new DateTime(2022, 09, 01);
public static DateTime LastStatementDate = new DateTime(2022, 08, 01);

public static String SettlementSchedule = "Monthly";

// Address
public static String AddressLine1 = "Address Line 1";
public static String AddressLine2 = "Address Line 2";
public static String AddressLine3 = "Address Line 3";
public static String AddressLine4 = "Address Line 4";
public static String PostalCode = "TE57 1NG";
public static String Region = "Region";
public static String Town = "Town";

// Contact
public static String ContactEmailAddress = "testcontact@myemail.com";

public static String ContactName = "Mr Test Contact";

public static String ContactMobileNumber = "077777777";
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.MyAccount;

using System.Threading;
using System.Threading.Tasks;
using Maui.UIServices;
using MediatR;
using Moq;
using Services;
using Shared.Logger;
using Shouldly;
using ViewModels.MyAccount;
using Xunit;

public class MyAccountAddressPageViewModelTests
{
[Fact]
public async Task MyAccountAddressPageViewModel_Initialise_IsInitialised()
{
Logger.Initialise(NullLogger.Instance);
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>();

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

applicationCache.Verify(a => a.GetMerchantDetails(), Times.Once);
viewModel.Address.ShouldNotBeNull();
viewModel.Address.AddressLine1.ShouldBe(TestData.AddressLine1);
viewModel.Address.AddressLine2.ShouldBe(TestData.AddressLine2);
viewModel.Address.AddressLine3.ShouldBe(TestData.AddressLine3);
viewModel.Address.AddressLine4.ShouldBe(TestData.AddressLine4);
viewModel.Address.Region.ShouldBe(TestData.Region);
viewModel.Address.Town.ShouldBe(TestData.Town);
viewModel.Address.PostalCode.ShouldBe(TestData.PostalCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.MyAccount;

using System.Threading;
using System.Threading.Tasks;
using Maui.UIServices;
using MediatR;
using Moq;
using Services;
using Shared.Logger;
using Shouldly;
using ViewModels.MyAccount;
using Xunit;

public class MyAccountContactPageViewModelTests
{
[Fact]
public async Task MyAccountContactPageViewModel_Initialise_IsInitialised()
{
Logger.Initialise(NullLogger.Instance);
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>();

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

applicationCache.Verify(a => a.GetMerchantDetails(), Times.Once);
viewModel.Contact.ShouldNotBeNull();
viewModel.Contact.EmailAddress.ShouldBe(TestData.ContactEmailAddress);
viewModel.Contact.Name.ShouldBe(TestData.ContactName);
viewModel.Contact.MobileNumber.ShouldBe(TestData.ContactMobileNumber);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.MyAccount;

using System.Threading;
using System.Threading.Tasks;
using Maui.UIServices;
using MediatR;
using Moq;
using Services;
using Shared.Logger;
using Shouldly;
using ViewModels.MyAccount;
using Xunit;

public class MyAccountDetailsPageViewModelTests
{
[Fact]
public async Task MyAccountDetailsPageViewModel_Initialise_IsInitialised()
{
Logger.Initialise(NullLogger.Instance);
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>();

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

applicationCache.Verify(a => a.GetMerchantDetails(), Times.Once);
viewModel.Balance.ShouldBe(TestData.Balance);
viewModel.AvailableBalance.ShouldBe(TestData.AvailableBalance);
viewModel.MerchantName.ShouldBe(TestData.MerchantName);
viewModel.LastStatementDate.ShouldBe(TestData.LastStatementDate);
viewModel.NextStatementDate.ShouldBe(TestData.NextStatementDate);
viewModel.SettlementSchedule.ShouldBe(TestData.SettlementSchedule);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.MyAccount;

using System;
using System.Threading;
using System.Threading.Tasks;
using Common;
using Maui.UIServices;
using MediatR;
using Microsoft.Extensions.Caching.Memory;
using Models;
using Moq;
using Requests;
using Services;
using Shared.Logger;
using Shouldly;
using ViewModels.MyAccount;
using Xunit;

public class MyAccountPageViewModelTests
{
#region Methods

[Fact]
public async Task MyAccountPageViewModel_Initialise_IsInitialised() {
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IMediator> mediator = new Mock<IMediator>();
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);
viewModel.LastLogin.ShouldBe(DateTime.Now, TimeSpan.FromSeconds(30));
applicationCache.Verify(a => a.SetMerchantDetails(It.IsAny<MerchantDetailsModel>(), It.IsAny<MemoryCacheEntryOptions>()), Times.Once);
}

[Fact]
public void MyAccountPageViewModel_OptionSelectedCommand_AccountInfo_Execute_IsExecuted() {
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IMediator> mediator = new Mock<IMediator>();
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object, applicationCache.Object, mediator.Object);
viewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.AccountInfo));

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

[Fact]
public void MyAccountPageViewModel_OptionSelectedCommand_Addresses_Execute_IsExecuted() {
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IMediator> mediator = new Mock<IMediator>();

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

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

[Fact]
public void MyAccountPageViewModel_OptionSelectedCommand_Contacts_Execute_IsExecuted() {
Logger.Initialise(NullLogger.Instance);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
Mock<IMediator> mediator = new Mock<IMediator>();

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

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

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

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

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

private ItemSelected<ListViewItem> CreateItemSelected(MyAccountPageViewModel.AccountOptions selectedOption) {
ItemSelected<ListViewItem> i = new ItemSelected<ListViewItem>();
i.SelectedItemIndex = (Int32)selectedOption;
return i;
}

#endregion
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.Support
{
using Maui.UIServices;
using MediatR;
Expand Down Expand Up @@ -33,7 +33,7 @@ public void SupportPageViewModel_UploadLogsCommand_Execute_IsExecuted()
applicationCache.Object);

viewModel.UploadLogsCommand.Execute(null);

navigationService.Verify(n => n.GoToHome(), Times.Once);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text;
using System.Threading.Tasks;

namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.Transactions.Admin
{
using Maui.UIServices;
using MediatR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;
namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests.Transactions.MobileTopup;

using Maui.UIServices;
using Moq;
Expand Down
Loading