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 @@ -29,9 +29,9 @@ public async Task LoginRequestHandler_Handle_LoginRequest_IsHandled()

authenticationService.Setup(a => a.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.AccessToken);
configurationService.Setup(c => c.GetConfiguration(It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(new Configuration());
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();

LoginRequestHandler handler = new LoginRequestHandler(authenticationServiceResolver, configurationServiceResolver, memoryCacheService.Object);
LoginRequestHandler handler = new LoginRequestHandler(authenticationServiceResolver, configurationServiceResolver, applicationCache.Object);

LoginRequest request = LoginRequest.Create(TestData.UserName,TestData.Password);

Expand All @@ -57,9 +57,9 @@ public async Task LoginRequestHandler_Handle_RefreshTokenRequest_IsHandled()
});
authenticationService.Setup(a => a.RefreshAccessToken(It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.AccessToken);
configurationService.Setup(c => c.GetConfiguration(It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(new Configuration());
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();

LoginRequestHandler handler = new LoginRequestHandler(authenticationServiceResolver, configurationServiceResolver, memoryCacheService.Object);
LoginRequestHandler handler = new LoginRequestHandler(authenticationServiceResolver, configurationServiceResolver, applicationCache.Object);

RefreshTokenRequest request = RefreshTokenRequest.Create(TestData.RefreshToken);

Expand All @@ -85,9 +85,9 @@ public async Task LoginRequestHandler_Handle_GetConfigurationRequest_IsHandled()
});
authenticationService.Setup(a => a.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.AccessToken);
configurationService.Setup(c => c.GetConfiguration(It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(new Configuration());
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();

LoginRequestHandler handler = new LoginRequestHandler(authenticationServiceResolver, configurationServiceResolver, memoryCacheService.Object);
LoginRequestHandler handler = new LoginRequestHandler(authenticationServiceResolver, configurationServiceResolver, applicationCache.Object);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_IsHan

merchantService.Setup(m => m.GetContractProducts(It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.ContractProductList);
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();


MerchantRequestHandler handler = new MerchantRequestHandler(merchantServiceResolver, memoryCacheService.Object);
MerchantRequestHandler handler = new MerchantRequestHandler(merchantServiceResolver, applicationCache.Object);

GetContractProductsRequest request = GetContractProductsRequest.Create();

Expand All @@ -48,8 +47,8 @@ public async Task MerchantRequestHandler_GetMerchantBalanceRequest_Handle_IsHand
});
merchantService.Setup(m => m.GetMerchantBalance(It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.MerchantBalance);
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
MerchantRequestHandler handler = new MerchantRequestHandler(merchantServiceResolver, memoryCacheService.Object);
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
MerchantRequestHandler handler = new MerchantRequestHandler(merchantServiceResolver, applicationCache.Object);

GetMerchantBalanceRequest request = GetMerchantBalanceRequest.Create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_NoLogs_Handle_IsH

Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
databaseContext.Setup(d => d.GetLogMessages(It.IsAny<Int32>())).ReturnsAsync(new List<Database.LogMessage>());
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();

SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, memoryCacheService.Object);
SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);

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

Expand Down Expand Up @@ -59,9 +59,9 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_Only
new Database.LogMessage()
}).ReturnsAsync(new List<Database.LogMessage>());

Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();

SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, memoryCacheService.Object);
SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);

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

Expand Down Expand Up @@ -101,9 +101,9 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_15Me
new Database.LogMessage(),
}).ReturnsAsync(new List<Database.LogMessage>());

Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();

SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, memoryCacheService.Object);
SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_IsHan
return transactionService.Object;
});
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
transactionService.Setup(t => t.PerformLogon(It.IsAny<PerformLogonRequestModel>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.PerformLogonResponseModel);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, memoryCacheService.Object);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, applicationCache.Object);

LogonTransactionRequest request = LogonTransactionRequest.Create(TestData.TransactionDateTime,
TestData.TransactionNumber,
Expand All @@ -47,9 +47,9 @@ public async Task TransactionRequestHandler_PerformMobileTopupRequest_Handle_IsH
return transactionService.Object;
});
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
transactionService.Setup(t => t.PerformMobileTopup(It.IsAny<PerformMobileTopupRequestModel>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, memoryCacheService.Object);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, applicationCache.Object);

PerformMobileTopupRequest request = PerformMobileTopupRequest.Create(TestData.TransactionDateTime,
TestData.TransactionNumber,
Expand All @@ -76,9 +76,9 @@ public async Task TransactionRequestHandler_PerformVoucherIssueRequest_Handle_Is
return transactionService.Object;
});
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
transactionService.Setup(t => t.PerformVoucherIssue(It.IsAny<PerformVoucherIssueRequestModel>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, memoryCacheService.Object);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, applicationCache.Object);

PerformVoucherIssueRequest request = PerformVoucherIssueRequest.Create(TestData.TransactionDateTime,
TestData.TransactionNumber,
Expand Down Expand Up @@ -106,10 +106,10 @@ public async Task TransactionRequestHandler_PerformReconciliationRequest_NoTrans
return transactionService.Object;
});
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
transactionService.Setup(t => t.PerformReconciliation(It.IsAny<PerformReconciliationRequestModel>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);
databaseContext.Setup(d => d.GetTransactions()).ReturnsAsync(new List<TransactionRecord>());
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, memoryCacheService.Object);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, applicationCache.Object);

PerformReconciliationRequest request = PerformReconciliationRequest.Create(TestData.TransactionDateTime,
TestData.DeviceIdentifier,
Expand All @@ -129,11 +129,11 @@ public async Task TransactionRequestHandler_PerformReconciliationRequest_Transac
return transactionService.Object;
});
Mock<IDatabaseContext> databaseContext = new Mock<IDatabaseContext>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IApplicationCache> applicationCache = new Mock<IApplicationCache>();
transactionService.Setup(t => t.PerformReconciliation(It.IsAny<PerformReconciliationRequestModel>(), It.IsAny<CancellationToken>())).ReturnsAsync(true);

databaseContext.Setup(d => d.GetTransactions()).ReturnsAsync(TestData.StoredTransactions);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, memoryCacheService.Object);
TransactionRequestHandler handler = new TransactionRequestHandler(transactionServiceResolver, databaseContext.Object, applicationCache.Object);

PerformReconciliationRequest request = PerformReconciliationRequest.Create(TestData.TransactionDateTime,
TestData.DeviceIdentifier,
Expand Down
17 changes: 17 additions & 0 deletions TransactionMobile.Maui.BusinessLogic.Tests/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public static class TestData
RefreshToken = TestData.RefreshToken
};

public static Configuration Configuration = new Configuration();
public static Configuration NullConfiguration = null;

public static TokenResponseModel NullAccessToken => null;

public static String Token = "Token";

public static String RefreshToken = "RefreshToken";
Expand Down Expand Up @@ -115,6 +120,8 @@ public static class TestData
TestData.Operator3Product_200KES
};

public static List<ContractProductModel> ContractProductListEmpty = new List<ContractProductModel>();

public static ContractOperatorModel ContractOperatorModel = new ContractOperatorModel
{
OperatorIdentfier = TestData.OperatorIdentifier1,
Expand Down Expand Up @@ -174,6 +181,16 @@ public static class TestData
RequireApplicationUpdate = false,
ResponseMessage = "SUCCESS"
};

public static PerformLogonResponseModel PerformLogonResponseModelFailed =>
new PerformLogonResponseModel
{
EstateId = TestData.EstateId,
MerchantId = TestData.MerchantId,
IsSuccessful = false,
RequireApplicationUpdate = false,
ResponseMessage = "FAILED"
};
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace TransactionMobile.Maui.BusinessLogic.Tests.ViewModelTests
using ViewModels.Transactions;
using Xunit;
using TransactionMobile.Maui.BusinessLogic.Services;
using ViewModels.MyAccount;

public class AdminPageViewModelTests
{
Expand All @@ -23,32 +22,15 @@ public void AdminPageViewModel_AdminCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IMediator> mediator = new Mock<IMediator>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
Mock<IDeviceService> deviceService = new Mock<IDeviceService>();
Mock<IApplicationInfoService> applicationInfoService = new Mock<IApplicationInfoService>();
AdminPageViewModel viewModel = new AdminPageViewModel(mediator.Object,
navigationService.Object,
memoryCacheService.Object,
deviceService.Object,
applicationInfoService.Object);

viewModel.ReconciliationCommand.Execute(null);
navigationService.Verify(n => n.GoToHome(), Times.Once);
}
}

public class MyAccountPageViewModelTests
{
[Fact]
public void MyAccountPageViewModel_LogoutCommand_Execute_IsExecuted()
{
Mock<INavigationService> navigationService = new Mock<INavigationService>();
Mock<IMemoryCacheService> memoryCacheService = new Mock<IMemoryCacheService>();
MyAccountPageViewModel viewModel = new MyAccountPageViewModel(navigationService.Object,
memoryCacheService.Object);

viewModel.LogoutCommand.Execute(null);
navigationService.Verify(n => n.GoToLoginPage(), Times.Once);
}
}
}
Loading