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,97 @@
namespace TransactionMobile.Maui.BusinessLogic.Tests.RequestHandlerTests;

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Database;
using Moq;
using RequestHandlers;
using Requests;
using Services;
using Shouldly;
using Xunit;

public class SupportRequestHandlerTests
{
[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_NoLogs_Handle_IsHandled()
{
Mock<IConfigurationService> configurationService = new Mock<IConfigurationService>();
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
databaseContext.Setup(d => d.GetLogMessages(It.IsAny<Int32>())).ReturnsAsync(new List<Database.LogMessage>());

SupportRequestHandler handler = new SupportRequestHandler(configurationService.Object, databaseContext.Object);

UploadLogsRequest request = UploadLogsRequest.Create(TestData.DeviceIdentifier);

Boolean response = await handler.Handle(request, CancellationToken.None);

response.ShouldBeTrue();
}

[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_Only10Messages_Handle_IsHandled()
{
Mock<IConfigurationService> configurationService = new Mock<IConfigurationService>();
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
databaseContext.SetupSequence(d => d.GetLogMessages(It.IsAny<Int32>())).ReturnsAsync(new List<Database.LogMessage>()
{
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage()
}).ReturnsAsync(new List<Database.LogMessage>());

SupportRequestHandler handler = new SupportRequestHandler(configurationService.Object, databaseContext.Object);

UploadLogsRequest request = UploadLogsRequest.Create(TestData.DeviceIdentifier);

Boolean response = await handler.Handle(request, CancellationToken.None);

response.ShouldBeTrue();
databaseContext.Verify(d => d.RemoveUploadedMessages(It.IsAny<List<Database.LogMessage>>()), Times.Once);
}

[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_15Messages_Handle_IsHandled()
{
Mock<IConfigurationService> configurationService = new Mock<IConfigurationService>();
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
databaseContext.SetupSequence(d => d.GetLogMessages(It.IsAny<Int32>())).ReturnsAsync(new List<Database.LogMessage>()
{
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
}).ReturnsAsync(new List<Database.LogMessage>()
{
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
new Database.LogMessage(),
}).ReturnsAsync(new List<Database.LogMessage>());

SupportRequestHandler handler = new SupportRequestHandler(configurationService.Object, databaseContext.Object);

UploadLogsRequest request = UploadLogsRequest.Create(TestData.DeviceIdentifier);

Boolean response = await handler.Handle(request, CancellationToken.None);

response.ShouldBeTrue();
databaseContext.Verify(d => d.RemoveUploadedMessages(It.IsAny<List<Database.LogMessage>>()), Times.Exactly(2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_IsHan
{
Mock<ITransactionService> transactionService = new Mock<ITransactionService>();
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();

transactionService.Setup(t => t.PerformLogon(It.IsAny<PerformLogonRequestModel>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.PerformLogonResponseModel);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionService.Object, databaseContext.Object);

Expand Down Expand Up @@ -118,4 +119,4 @@ public async Task TransactionRequestHandler_PerformReconciliationRequest_Transac

response.ShouldBeTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ public void PerformReconciliationRequest_Create_IsCreated()
request.TransactionDateTime.ShouldBe(TestData.TransactionDateTime);
request.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier);
request.ApplicationVersion.ShouldBe(TestData.ApplicationVersion);
}

[Fact]
public void UploadLogsRequest_Create_IsCreated()
{
UploadLogsRequest request = UploadLogsRequest.Create(TestData.DeviceIdentifier);

request.ShouldNotBeNull();
request.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;
using Models;
using Moq;
using Requests;
using Shared.Logger;
using TransactionMobile.Maui.BusinessLogic.Services;
using TransactionMobile.Maui.Database;
using UIServices;
using ViewModels;
using Xunit;
Expand All @@ -25,7 +27,7 @@ public void LoginPageViewModel_LoginCommand_Execute_IsExecuted()
Mock<IApplicationInfoService> applicationInfoService = new Mock<IApplicationInfoService>();
LoginPageViewModel viewModel = new LoginPageViewModel(mediator.Object, navigationService.Object, memoryCacheService.Object,
deviceService.Object,applicationInfoService.Object);

Logger.Initialise(NullLogger.Instance);
mediator.Setup(m => m.Send(It.IsAny<GetConfigurationRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(new Configuration());
mediator.Setup(m => m.Send(It.IsAny<LoginRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.AccessToken);
mediator.Setup(m => m.Send(It.IsAny<LogonTransactionRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.PerformLogonResponseModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;

using Maui.UIServices;
using Moq;
using Shared.Logger;
using UIServices;
using ViewModels.Transactions;
using Xunit;
Expand All @@ -12,6 +13,7 @@ public class MobileTopupFailedPageViewModelTests
public void MobileTopupFailedPageViewModel_CancelledCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupFailedPageViewModel viewModel = new MobileTopupFailedPageViewModel(navigationService.Object);

viewModel.CancelledCommand.Execute(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;
using MediatR;
using Moq;
using Requests;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.Transactions;
Expand All @@ -19,6 +20,7 @@ public void MobileTopupPerformTopupPageViewModel_ApplyQueryAttributes_QueryAttri
{
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupPerformTopupPageViewModel viewModel = new MobileTopupPerformTopupPageViewModel(mediator.Object, navigationService.Object);

viewModel.ApplyQueryAttributes(new Dictionary<String, Object>
Expand All @@ -40,6 +42,7 @@ public void MobileTopupPerformTopupPageViewModel_CustomerEmailAddressEntryComple
{
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupPerformTopupPageViewModel viewModel = new MobileTopupPerformTopupPageViewModel(mediator.Object, navigationService.Object);
Boolean isCompletedCalled = false;
viewModel.OnCustomerEmailAddressEntryCompleted = () =>
Expand All @@ -63,6 +66,7 @@ public void MobileTopupPerformTopupPageViewModel_CustomerMobileNumberEntryComple
{
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupPerformTopupPageViewModel viewModel = new MobileTopupPerformTopupPageViewModel(mediator.Object, navigationService.Object);
Boolean isCompletedCalled = false;
viewModel.OnCustomerMobileNumberEntryCompleted = () =>
Expand All @@ -86,6 +90,7 @@ public void MobileTopupPerformTopupPageViewModel_TopupAmountEntryCompletedComman
{
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupPerformTopupPageViewModel viewModel = new MobileTopupPerformTopupPageViewModel(mediator.Object, navigationService.Object);
Boolean isCompletedCalled = false;
viewModel.OnTopupAmountEntryCompleted = () =>
Expand All @@ -110,6 +115,7 @@ public void MobileTopupPerformTopupPageViewModel_PerformTopupCommand_Execute_Suc
Mock<IMediator> mediator = new Mock<IMediator>();
mediator.Setup(m => m.Send(It.IsAny<PerformMobileTopupRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupPerformTopupPageViewModel viewModel = new MobileTopupPerformTopupPageViewModel(mediator.Object, navigationService.Object);
viewModel.ApplyQueryAttributes(new Dictionary<String, Object>
{
Expand All @@ -129,6 +135,7 @@ public void MobileTopupPerformTopupPageViewModel_PerformTopupCommand_Execute_Fai
Mock<IMediator> mediator = new Mock<IMediator>();
mediator.Setup(m => m.Send(It.IsAny<PerformMobileTopupRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(false);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupPerformTopupPageViewModel viewModel = new MobileTopupPerformTopupPageViewModel(mediator.Object, navigationService.Object);
viewModel.ApplyQueryAttributes(new Dictionary<String, Object>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;
using Models;
using Moq;
using Requests;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.Transactions;
Expand Down Expand Up @@ -34,6 +35,7 @@ public async Task MobileTopupSelectOperatorPageViewModel_OperatorSelectedCommand
Mock<IMediator> mediator = new Mock<IMediator>();
mediator.Setup(m => m.Send(It.IsAny<GetContractProductsRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ContractProductList);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupSelectOperatorPageViewModel viewModel = new MobileTopupSelectOperatorPageViewModel(mediator.Object, navigationService.Object);

await viewModel.Initialise(CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;
using Models;
using Moq;
using Requests;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.Transactions;
Expand Down Expand Up @@ -55,6 +56,7 @@ public async Task MobileTopupSelectProductPageViewModel_ProductSelectedCommand_E
Mock<IMediator> mediator = new Mock<IMediator>();
mediator.Setup(m => m.Send(It.IsAny<GetContractProductsRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ContractProductList);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupSelectProductPageViewModel viewModel = new MobileTopupSelectProductPageViewModel(mediator.Object, navigationService.Object);

viewModel.ApplyQueryAttributes(new Dictionary<String, Object>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;

using Maui.UIServices;
using Moq;
using Shared.Logger;
using UIServices;
using ViewModels.Transactions;
using Xunit;
Expand All @@ -12,6 +13,7 @@ public class MobileTopupSuccessPageViewModelTests
public void MobileTopupSuccessPageViewModel_CompletedCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
MobileTopupSuccessPageViewModel viewModel = new MobileTopupSuccessPageViewModel(navigationService.Object);

viewModel.CompletedCommand.Execute(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;

namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests
{
using Maui.UIServices;
using MediatR;
using Moq;
using UIServices;
using Xunit;
using TransactionMobile.Maui.BusinessLogic.ViewModels.Support;
using TransactionMobile.Maui.Database;
using Shared.Logger;
using System.Collections.Generic;

public class SupportPageViewModelTests
{
[Fact]
public void SupportPageViewModel_UploadLogsCommand_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>();
Logger.Initialise(NullLogger.Instance);
SupportPageViewModel viewModel = new SupportPageViewModel(deviceService.Object,applicationInfoService.Object,
databaseContext.Object, mediator.Object,navigationService.Object);

viewModel.UploadLogsCommand.Execute(null);

navigationService.Verify(n => n.GoToHome(), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;

using Maui.UIServices;
using Moq;
using Shared.Logger;
using UIServices;
using ViewModels.Transactions;
using Xunit;
Expand All @@ -22,6 +23,7 @@ public void TransactionsPageViewModel_AdminCommand_Execute_IsExecuted()
public void TransactionsPageViewModel_BillPaymentCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
TransactionsPageViewModel viewModel = new TransactionsPageViewModel(navigationService.Object);

viewModel.BillPaymentCommand.Execute(null);
Expand All @@ -32,6 +34,7 @@ public void TransactionsPageViewModel_BillPaymentCommand_Execute_IsExecuted()
public void TransactionsPageViewModel_MobileTopupCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
TransactionsPageViewModel viewModel = new TransactionsPageViewModel(navigationService.Object);

viewModel.MobileTopupCommand.Execute(null);
Expand All @@ -42,6 +45,7 @@ public void TransactionsPageViewModel_MobileTopupCommand_Execute_IsExecuted()
public void TransactionsPageViewModel_MobileWalletCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
TransactionsPageViewModel viewModel = new TransactionsPageViewModel(navigationService.Object);

viewModel.MobileWalletCommand.Execute(null);
Expand All @@ -52,6 +56,7 @@ public void TransactionsPageViewModel_MobileWalletCommand_Execute_IsExecuted()
public void TransactionsPageViewModel_VoucherCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
TransactionsPageViewModel viewModel = new TransactionsPageViewModel(navigationService.Object);

viewModel.VoucherCommand.Execute(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;

using Maui.UIServices;
using Moq;
using Shared.Logger;
using UIServices;
using ViewModels.Transactions;
using Xunit;
Expand All @@ -12,6 +13,7 @@ public class VoucherIssueFailedPageViewModelTests
public void VoucherIssueFailedPageViewModel_CancelledCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
VoucherIssueFailedPageViewModel viewModel = new VoucherIssueFailedPageViewModel(navigationService.Object);

viewModel.CancelledCommand.Execute(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;
using Models;
using Moq;
using Requests;
using Shared.Logger;
using Shouldly;
using UIServices;
using ViewModels.Transactions;
Expand Down Expand Up @@ -55,6 +56,7 @@ public async Task VoucherIssueSelectProductPageViewModel_ProductSelectedCommand_
Mock<IMediator> mediator = new Mock<IMediator>();
mediator.Setup(m => m.Send(It.IsAny<GetContractProductsRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ContractProductList);
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
VoucherSelectProductPageViewModel viewModel = new VoucherSelectProductPageViewModel(mediator.Object, navigationService.Object);

viewModel.ApplyQueryAttributes(new Dictionary<String, Object>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests;

using Maui.UIServices;
using Moq;
using Shared.Logger;
using UIServices;
using ViewModels.Transactions;
using Xunit;
Expand All @@ -12,6 +13,7 @@ public class VoucherIssueSuccessPageViewModelTests
public void VoucherIssueSuccessPageViewModel_CompletedCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Logger.Initialise(NullLogger.Instance);
VoucherIssueSuccessPageViewModel viewModel = new VoucherIssueSuccessPageViewModel(navigationService.Object);

viewModel.CompletedCommand.Execute(null);
Expand Down
Loading