diff --git a/Directory.Packages.props b/Directory.Packages.props
index 7bc942bf..c8b61371 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -13,6 +13,7 @@
+
@@ -20,7 +21,6 @@
-
@@ -48,4 +48,4 @@
-
\ No newline at end of file
+
diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/CommonTests/ExtensionsTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/CommonTests/ExtensionsTests.cs
index 6a901875..295b496f 100644
--- a/TransactionProcessor.Mobile.BusinessLogic.Tests/CommonTests/ExtensionsTests.cs
+++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/CommonTests/ExtensionsTests.cs
@@ -1,4 +1,4 @@
-using Shouldly;
+using Shouldly;
using SimpleResults;
using TransactionProcessor.Mobile.BusinessLogic.Common;
using TransactionProcessor.Mobile.BusinessLogic.Database;
diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ImposterGeneration.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ImposterGeneration.cs
new file mode 100644
index 00000000..ad7966b6
--- /dev/null
+++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ImposterGeneration.cs
@@ -0,0 +1,36 @@
+global using Configuration = TransactionProcessor.Mobile.BusinessLogic.Models.Configuration;
+global using TokenResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.TokenResponseModel;
+global using ContractProductModel = TransactionProcessor.Mobile.BusinessLogic.Models.ContractProductModel;
+global using ContractOperatorModel = TransactionProcessor.Mobile.BusinessLogic.Models.ContractOperatorModel;
+global using PerformLogonResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformLogonResponseModel;
+global using PerformMobileTopupResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformMobileTopupResponseModel;
+global using PerformVoucherIssueResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformVoucherIssueResponseModel;
+global using PerformReconciliationResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformReconciliationResponseModel;
+global using PerformBillPaymentGetAccountResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformBillPaymentGetAccountResponseModel;
+global using PerformBillPaymentGetMeterResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformBillPaymentGetMeterResponseModel;
+global using PerformBillPaymentMakePaymentResponseModel = TransactionProcessor.Mobile.BusinessLogic.Models.PerformBillPaymentMakePaymentResponseModel;
+global using DailyPerformanceSummaryModel = TransactionProcessor.Mobile.BusinessLogic.Models.DailyPerformanceSummaryModel;
+global using TransactionMixSummaryModel = TransactionProcessor.Mobile.BusinessLogic.Models.TransactionMixSummaryModel;
+global using RecentActivityReceiptReportModel = TransactionProcessor.Mobile.BusinessLogic.Models.RecentActivityReceiptReportModel;
+
+using Imposter.Abstractions;
+
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IApplicationCache))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.IApplicationInfoService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.IApplicationThemeService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.IApplicationUpdateLauncherService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IAuthenticationService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IBalanceRefresher))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IConfigurationService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Database.IDatabaseContext))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.IDeviceService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.IDialogService))]
+[assembly: GenerateImposter(typeof(MediatR.IMediator))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IMerchantService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.INavigationParameterService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.INavigationService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IReportsService))]
+[assembly: GenerateImposter(typeof(SecurityService.Client.ISecurityServiceClient))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.UIServices.ISentryService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.ITransactionService))]
+[assembly: GenerateImposter(typeof(TransactionProcessor.Mobile.BusinessLogic.Services.IUpdateService))]
diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/LoginRequestHandlerTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/LoginRequestHandlerTests.cs
index a2a8c6e1..12411862 100644
--- a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/LoginRequestHandlerTests.cs
+++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/LoginRequestHandlerTests.cs
@@ -1,5 +1,5 @@
-using Microsoft.Extensions.Caching.Memory;
-using Moq;
+using Microsoft.Extensions.Caching.Memory;
+using Imposter.Abstractions;
using Shouldly;
using SimpleResults;
using TransactionProcessor.Mobile.BusinessLogic.Models;
@@ -11,28 +11,28 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.RequestHandlerTests;
public class LoginRequestHandlerTests
{
- private Mock AuthenticationService = null;
- private Mock ConfigurationService = null;
+ private IAuthenticationServiceImposter AuthenticationService = null;
+ private IConfigurationServiceImposter ConfigurationService = null;
private LoginRequestHandler LoginRequestHandler = null;
- private readonly Mock ApplicationCache;
+ private readonly IApplicationCacheImposter ApplicationCache;
private Func AuthenticationServiceResolver;
private Func ConfigurationServiceResolver;
public LoginRequestHandlerTests() {
- this.AuthenticationService = new Mock();
- this.ConfigurationService= new Mock();
- this.ApplicationCache = new Mock();
- this.AuthenticationServiceResolver = _ => this.AuthenticationService.Object;
- this.ConfigurationServiceResolver = _ => this.ConfigurationService.Object;
+ this.AuthenticationService = new IAuthenticationServiceImposter();
+ this.ConfigurationService= new IConfigurationServiceImposter();
+ this.ApplicationCache = new IApplicationCacheImposter();
+ this.AuthenticationServiceResolver = _ => this.AuthenticationService.Instance();
+ this.ConfigurationServiceResolver = _ => this.ConfigurationService.Instance();
- this.LoginRequestHandler = new LoginRequestHandler(this.AuthenticationServiceResolver, this.ConfigurationServiceResolver, this.ApplicationCache.Object);
+ this.LoginRequestHandler = new LoginRequestHandler(this.AuthenticationServiceResolver, this.ConfigurationServiceResolver, this.ApplicationCache.Instance());
}
[Fact]
public async Task LoginRequestHandler_Handle_LoginRequest_IsHandled()
{
- this.ApplicationCache.Setup(a => a.GetConfiguration()).Returns(new Configuration { ClientId = TestData.ClientId, ClientSecret = TestData.ClientSecret });
- this.AuthenticationService.Setup(a => a.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken));
+ this.ApplicationCache.GetConfiguration().Returns(new Configuration { ClientId = TestData.ClientId, ClientSecret = TestData.ClientSecret });
+ this.AuthenticationService.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken));
LogonCommands.GetTokenCommand request = new(TestData.UserName, TestData.Password);
@@ -42,27 +42,27 @@ public async Task LoginRequestHandler_Handle_LoginRequest_IsHandled()
result.Data.AccessToken.ShouldBe(TestData.Token);
result.Data.ExpiryInMinutes.ShouldBe(TestData.TokenExpiryInMinutes);
result.Data.RefreshToken.ShouldBe(TestData.RefreshToken);
- this.AuthenticationService.Verify(a => a.GetToken(TestData.UserName, TestData.Password, TestData.ClientId, TestData.ClientSecret, It.IsAny()), Times.Once);
+ this.AuthenticationService.GetToken(TestData.UserName, TestData.Password, TestData.ClientId, TestData.ClientSecret, Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task LoginRequestHandler_Handle_LoginRequest_ConfigurationNotCached_FailureReturned()
{
- this.ApplicationCache.Setup(a => a.GetConfiguration()).Returns((Configuration)null);
+ this.ApplicationCache.GetConfiguration().Returns((Configuration)null);
LogonCommands.GetTokenCommand request = new(TestData.UserName, TestData.Password);
Result result = await this.LoginRequestHandler.Handle(request, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
- this.AuthenticationService.Verify(a => a.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never);
+ this.AuthenticationService.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).Called(Count.Never());
}
[Fact]
public async Task LoginRequestHandler_Handle_RefreshTokenRequest_IsHandled()
{
- this.ApplicationCache.Setup(a => a.GetConfiguration()).Returns(new Configuration { ClientId = TestData.ClientId, ClientSecret = TestData.ClientSecret });
- this.AuthenticationService.Setup(a => a.RefreshAccessToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken));
+ this.ApplicationCache.GetConfiguration().Returns(new Configuration { ClientId = TestData.ClientId, ClientSecret = TestData.ClientSecret });
+ this.AuthenticationService.RefreshAccessToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken));
LogonCommands.RefreshTokenCommand request = new(TestData.RefreshToken);
@@ -72,27 +72,27 @@ public async Task LoginRequestHandler_Handle_RefreshTokenRequest_IsHandled()
result.Data.AccessToken.ShouldBe(TestData.Token);
result.Data.ExpiryInMinutes.ShouldBe(TestData.TokenExpiryInMinutes);
result.Data.RefreshToken.ShouldBe(TestData.RefreshToken);
- this.AuthenticationService.Verify(a => a.RefreshAccessToken(TestData.RefreshToken, TestData.ClientId, TestData.ClientSecret, It.IsAny()), Times.Once);
+ this.AuthenticationService.RefreshAccessToken(TestData.RefreshToken, TestData.ClientId, TestData.ClientSecret, Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task LoginRequestHandler_Handle_RefreshTokenRequest_ConfigurationNotCached_FailureReturned()
{
- this.ApplicationCache.Setup(a => a.GetConfiguration()).Returns((Configuration)null);
+ this.ApplicationCache.GetConfiguration().Returns((Configuration)null);
LogonCommands.RefreshTokenCommand request = new(TestData.RefreshToken);
Result result = await this.LoginRequestHandler.Handle(request, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
- this.AuthenticationService.Verify(a => a.RefreshAccessToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never);
+ this.AuthenticationService.RefreshAccessToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).Called(Count.Never());
}
[Fact]
public async Task LoginRequestHandler_Handle_GetConfigurationRequest_CacheMiss_ServiceIsCalled_ConfigIsCached()
{
- this.ApplicationCache.Setup(a => a.GetConfiguration()).Returns((Configuration)null);
- this.ConfigurationService.Setup(c => c.GetConfiguration(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new Configuration()));
+ this.ApplicationCache.GetConfiguration().Returns((Configuration)null);
+ this.ConfigurationService.GetConfiguration(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new Configuration()));
LogonQueries.GetConfigurationQuery request = new LogonQueries.GetConfigurationQuery(TestData.DeviceIdentifier);
@@ -100,14 +100,14 @@ public async Task LoginRequestHandler_Handle_GetConfigurationRequest_CacheMiss_S
result.IsSuccess.ShouldBeTrue();
result.Data.ShouldNotBeNull();
- this.ConfigurationService.Verify(c => c.GetConfiguration(It.IsAny(), It.IsAny()), Times.Once);
- this.ApplicationCache.Verify(a => a.SetConfiguration(It.IsAny(), It.IsAny()), Times.Once);
+ this.ConfigurationService.GetConfiguration(Arg.Any(), Arg.Any()).Called(Count.Once());
+ this.ApplicationCache.SetConfiguration(Arg.Any(), Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task LoginRequestHandler_Handle_GetConfigurationRequest_CacheHit_ServiceIsNotCalled()
{
- this.ApplicationCache.Setup(a => a.GetConfiguration()).Returns(new Configuration());
+ this.ApplicationCache.GetConfiguration().Returns(new Configuration());
LogonQueries.GetConfigurationQuery request = new LogonQueries.GetConfigurationQuery(TestData.DeviceIdentifier);
@@ -115,7 +115,7 @@ public async Task LoginRequestHandler_Handle_GetConfigurationRequest_CacheHit_Se
result.IsSuccess.ShouldBeTrue();
result.Data.ShouldNotBeNull();
- this.ConfigurationService.Verify(c => c.GetConfiguration(It.IsAny(), It.IsAny()), Times.Never);
- this.ApplicationCache.Verify(a => a.SetConfiguration(It.IsAny(), It.IsAny()), Times.Never);
+ this.ConfigurationService.GetConfiguration(Arg.Any(), Arg.Any()).Called(Count.Never());
+ this.ApplicationCache.SetConfiguration(Arg.Any(), Arg.Any()).Called(Count.Never());
}
}
diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/MerchantRequestHandlerTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/MerchantRequestHandlerTests.cs
index 411ae5f3..6ed4735d 100644
--- a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/MerchantRequestHandlerTests.cs
+++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/MerchantRequestHandlerTests.cs
@@ -1,5 +1,5 @@
-using Microsoft.Extensions.Caching.Memory;
-using Moq;
+using Microsoft.Extensions.Caching.Memory;
+using Imposter.Abstractions;
using Shouldly;
using SimpleResults;
using TransactionProcessor.Mobile.BusinessLogic.Models;
@@ -13,11 +13,11 @@ public class MerchantRequestHandlerTests
{
#region Fields
- private readonly Mock ApplicationCache;
+ private readonly IApplicationCacheImposter ApplicationCache;
private readonly MerchantRequestHandler MerchantRequestHandler;
- private readonly Mock MerchantService;
+ private readonly IMerchantServiceImposter MerchantService;
private Func MerchantServiceResolver;
#endregion
@@ -25,13 +25,13 @@ public class MerchantRequestHandlerTests
#region Constructors
public MerchantRequestHandlerTests() {
- this.MerchantService = new Mock();
- this.ApplicationCache = new Mock();
- this.MerchantService = new Mock();
+ this.MerchantService = new IMerchantServiceImposter();
+ this.ApplicationCache = new IApplicationCacheImposter();
+ this.MerchantService = new IMerchantServiceImposter();
this.MerchantServiceResolver = (param) => {
- return this.MerchantService.Object;
+ return this.MerchantService.Instance();
};
- this.MerchantRequestHandler = new MerchantRequestHandler(this.MerchantServiceResolver, this.ApplicationCache.Object);
+ this.MerchantRequestHandler = new MerchantRequestHandler(this.MerchantServiceResolver, this.ApplicationCache.Instance());
}
#endregion
@@ -40,7 +40,7 @@ public MerchantRequestHandlerTests() {
[Fact]
public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_IsHandled() {
- this.MerchantService.Setup(m => m.GetContractProducts(It.IsAny()))
+ this.MerchantService.GetContractProducts(Arg.Any())
.ReturnsAsync(Result.Success(TestData.ContractProductList));
MerchantQueries.GetContractProductsQuery request = new MerchantQueries.GetContractProductsQuery();
@@ -54,9 +54,9 @@ public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_IsHan
[Fact]
public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_CacheIsNull_ServiceIsCalled_ProductsAreCached(){
List products = null;
- this.ApplicationCache.Setup(a => a.GetContractProducts()).Returns(products);
+ this.ApplicationCache.GetContractProducts().Returns(products);
- this.MerchantService.Setup(m => m.GetContractProducts(It.IsAny()))
+ this.MerchantService.GetContractProducts(Arg.Any())
.ReturnsAsync(Result.Success(TestData.ContractProductList));
MerchantQueries.GetContractProductsQuery request = new MerchantQueries.GetContractProductsQuery();
@@ -65,16 +65,16 @@ public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_Cache
result.IsSuccess.ShouldBeTrue();
result.Data.Count.ShouldBe(TestData.ContractProductList.Count);
- this.ApplicationCache.Verify(a => a.SetContractProducts(It.IsAny>(), It.IsAny()), Times.Once);
+ this.ApplicationCache.SetContractProducts(Arg>.Any(), Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_GetContractProductsFailed_IsHandled()
{
List products = new List();
- this.ApplicationCache.Setup(a => a.GetContractProducts()).Returns(products);
+ this.ApplicationCache.GetContractProducts().Returns(products);
- this.MerchantService.Setup(m => m.GetContractProducts(It.IsAny()))
+ this.MerchantService.GetContractProducts(Arg.Any())
.ReturnsAsync(Result.Failure("failed"));
MerchantQueries.GetContractProductsQuery request = new MerchantQueries.GetContractProductsQuery();
@@ -87,7 +87,7 @@ public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_GetCo
[Fact]
public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_FilterByType_IsHandled()
{
- this.MerchantService.Setup(m => m.GetContractProducts(It.IsAny()))
+ this.MerchantService.GetContractProducts(Arg.Any())
.ReturnsAsync(Result.Success(TestData.ContractProductList));
MerchantQueries.GetContractProductsQuery request = new MerchantQueries.GetContractProductsQuery(ProductType.Voucher);
@@ -102,9 +102,9 @@ public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_Filte
public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_CacheIsEmpty_ServiceIsCalled_ProductsAreCached()
{
List products = new List();
- this.ApplicationCache.Setup(a => a.GetContractProducts()).Returns(products);
+ this.ApplicationCache.GetContractProducts().Returns(products);
- this.MerchantService.Setup(m => m.GetContractProducts(It.IsAny()))
+ this.MerchantService.GetContractProducts(Arg.Any())
.ReturnsAsync(Result.Success(TestData.ContractProductList));
MerchantQueries.GetContractProductsQuery request = new MerchantQueries.GetContractProductsQuery();
@@ -113,12 +113,12 @@ public async Task MerchantRequestHandler_GetContractProductsRequest_Handle_Cache
result.IsSuccess.ShouldBeTrue();
result.Data.Count.ShouldBe(TestData.ContractProductList.Count);
- this.ApplicationCache.Verify(a => a.SetContractProducts(It.IsAny>(), It.IsAny()), Times.Once);
+ this.ApplicationCache.SetContractProducts(Arg>.Any(), Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task MerchantRequestHandler_GetMerchantBalanceRequest_Handle_IsHandled() {
- this.MerchantService.Setup(m => m.GetMerchantBalance(It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantBalance));
+ this.MerchantService.GetMerchantBalance(Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantBalance));
MerchantQueries.GetMerchantBalanceQuery request = new MerchantQueries.GetMerchantBalanceQuery();
@@ -131,30 +131,30 @@ public async Task MerchantRequestHandler_GetMerchantBalanceRequest_Handle_IsHand
[Fact]
public async Task MerchantRequestHandler_GetMerchantDetailsRequest_Handle_CacheMiss_ServiceIsCalled_DetailsAreCached()
{
- this.ApplicationCache.Setup(a => a.GetMerchantDetails()).Returns((MerchantDetailsModel)null);
- this.MerchantService.Setup(m => m.GetMerchantDetails(It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel));
+ this.ApplicationCache.GetMerchantDetails().Returns((MerchantDetailsModel)null);
+ this.MerchantService.GetMerchantDetails(Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel));
MerchantQueries.GetMerchantDetailsQuery request = new MerchantQueries.GetMerchantDetailsQuery();
Result result = await this.MerchantRequestHandler.Handle(request, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
- this.MerchantService.Verify(m => m.GetMerchantDetails(It.IsAny()), Times.Once);
- this.ApplicationCache.Verify(a => a.SetMerchantDetails(It.IsAny(), It.IsAny()), Times.Once);
+ this.MerchantService.GetMerchantDetails(Arg.Any()).Called(Count.Once());
+ this.ApplicationCache.SetMerchantDetails(Arg.Any(), Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task MerchantRequestHandler_GetMerchantDetailsRequest_Handle_CacheHit_ServiceIsNotCalled()
{
- this.ApplicationCache.Setup(a => a.GetMerchantDetails()).Returns(TestData.MerchantDetailsModel);
+ this.ApplicationCache.GetMerchantDetails().Returns(TestData.MerchantDetailsModel);
MerchantQueries.GetMerchantDetailsQuery request = new MerchantQueries.GetMerchantDetailsQuery();
Result result = await this.MerchantRequestHandler.Handle(request, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
- this.MerchantService.Verify(m => m.GetMerchantDetails(It.IsAny()), Times.Never);
- this.ApplicationCache.Verify(a => a.SetMerchantDetails(It.IsAny(), It.IsAny()), Times.Never);
+ this.MerchantService.GetMerchantDetails(Arg.Any()).Called(Count.Never());
+ this.ApplicationCache.SetMerchantDetails(Arg.Any(), Arg.Any()).Called(Count.Never());
}
#endregion
diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/ReportRequestHandlerTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/ReportRequestHandlerTests.cs
index 1756205b..2bff75c0 100644
--- a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/ReportRequestHandlerTests.cs
+++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/ReportRequestHandlerTests.cs
@@ -1,5 +1,5 @@
using MediatR;
-using Moq;
+using Imposter.Abstractions;
using SimpleResults;
using Shouldly;
using TransactionProcessor.Mobile.BusinessLogic.RequestHandlers;
@@ -14,23 +14,23 @@ public class ReportRequestHandlerTests
[Fact]
public async Task GetDailyPerformanceSummaryQuery_ReturnsMockedSummaryForToday()
{
- Mock reportsService = new();
- Mock applicationCache = new();
+ IReportsServiceImposter reportsService = new();
+ IApplicationCacheImposter applicationCache = new();
MerchantDetailsModel merchantDetails = new()
{
MerchantReportingId = 12345
};
- applicationCache.Setup(a => a.GetMerchantDetails()).Returns(merchantDetails);
- reportsService.Setup(r => r.GetDailyPerformanceSummary(
+ applicationCache.GetMerchantDetails().Returns(merchantDetails);
+ reportsService.GetDailyPerformanceSummary(
PerformanceSummaryPeriod.Today,
merchantDetails.MerchantReportingId,
- It.IsAny(),
- It.IsAny(),
- It.IsAny()))
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any())
.ReturnsAsync(Result.Success(DailyPerformanceSummaryModel.CreateMock(PerformanceSummaryPeriod.Today)));
- ReportRequestHandler handler = new(reportsService.Object, applicationCache.Object);
+ ReportRequestHandler handler = new(reportsService.Instance(), applicationCache.Instance());
Result result = await handler.Handle(new ReportQueries.GetDailyPerformanceSummaryQuery(PerformanceSummaryPeriod.Today), CancellationToken.None);
@@ -38,68 +38,66 @@ public async Task GetDailyPerformanceSummaryQuery_ReturnsMockedSummaryForToday()
result.Data.Period.ShouldBe(PerformanceSummaryPeriod.Today);
result.Data.Metrics.ShouldContain(m => m.Title == "Total transaction count" && m.Value == "48");
result.Data.DrillDownTransactions.ShouldContain(t => t.Reference == "TXN-00048");
- reportsService.Verify(r => r.GetDailyPerformanceSummary(
+ reportsService.GetDailyPerformanceSummary(
PerformanceSummaryPeriod.Today,
merchantDetails.MerchantReportingId,
- It.IsAny(),
- It.IsAny(),
- It.IsAny()),
- Times.Once);
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task GetDailyPerformanceSummaryQuery_InvalidPeriod_ReturnsFailure()
{
- Mock reportsService = new();
- Mock applicationCache = new();
+ IReportsServiceImposter reportsService = new();
+ IApplicationCacheImposter applicationCache = new();
MerchantDetailsModel merchantDetails = new()
{
MerchantReportingId = 12345
};
- applicationCache.Setup(a => a.GetMerchantDetails()).Returns(merchantDetails);
+ applicationCache.GetMerchantDetails().Returns(merchantDetails);
- ReportRequestHandler handler = new(reportsService.Object, applicationCache.Object);
+ ReportRequestHandler handler = new(reportsService.Instance(), applicationCache.Instance());
Result result = await handler.Handle(
new ReportQueries.GetDailyPerformanceSummaryQuery((PerformanceSummaryPeriod)999),
CancellationToken.None);
result.IsFailed.ShouldBeTrue();
- reportsService.Verify(r => r.GetDailyPerformanceSummary(
- It.IsAny(),
- It.IsAny(),
- It.IsAny(),
- It.IsAny(),
- It.IsAny()),
- Times.Never);
+ reportsService.GetDailyPerformanceSummary(
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any(),
+ Arg.Any()).Called(Count.Never());
}
[Fact]
public async Task GetTransactionMixSummaryQuery_ReturnsRequestedBreakdown()
{
- Mock reportsService = new();
- Mock applicationCache = new();
+ IReportsServiceImposter reportsService = new();
+ IApplicationCacheImposter applicationCache = new();
MerchantDetailsModel merchantDetails = new()
{
MerchantReportingId = 12345
};
- applicationCache.Setup(a => a.GetMerchantDetails()).Returns(merchantDetails);
- reportsService.Setup(r => r.GetTransactionMixSummary(
+ applicationCache.GetMerchantDetails().Returns(merchantDetails);
+ reportsService.GetTransactionMixSummary(
merchantDetails.MerchantReportingId,
- It.IsAny(),
- It.IsAny(),
+ Arg.Any(),
+ Arg.Any(),
TransactionMixBreakdown.Product,
TransactionMixMeasure.Value,
5,
- It.IsAny()))
+ Arg.Any())
.ReturnsAsync(Result.Success(TransactionMixSummaryModel.CreateMock(
merchantReportingId: merchantDetails.MerchantReportingId,
breakdown: TransactionMixBreakdown.Product,
measure: TransactionMixMeasure.Value)));
- ReportRequestHandler handler = new(reportsService.Object, applicationCache.Object);
+ ReportRequestHandler handler = new(reportsService.Instance(), applicationCache.Instance());
Result result = await handler.Handle(
new ReportQueries.GetTransactionMixSummaryQuery(
@@ -114,22 +112,21 @@ public async Task GetTransactionMixSummaryQuery_ReturnsRequestedBreakdown()
result.Data.Breakdown.ShouldBe(TransactionMixBreakdown.Product);
result.Data.Measure.ShouldBe(TransactionMixMeasure.Value);
result.Data.Items.ShouldNotBeEmpty();
- reportsService.Verify(r => r.GetTransactionMixSummary(
+ reportsService.GetTransactionMixSummary(
merchantDetails.MerchantReportingId,
new DateTime(2026, 7, 1),
new DateTime(2026, 7, 31),
TransactionMixBreakdown.Product,
TransactionMixMeasure.Value,
5,
- It.IsAny()),
- Times.Once);
+ Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task GetRecentActivityReceiptReportQuery_ReturnsMockedResultsForOneDate()
{
- Mock reportsService = new();
- Mock applicationCache = new();
+ IReportsServiceImposter reportsService = new();
+ IApplicationCacheImposter applicationCache = new();
MerchantDetailsModel merchantDetails = new()
{
MerchantReportingId = 12345
@@ -137,17 +134,17 @@ public async Task GetRecentActivityReceiptReportQuery_ReturnsMockedResultsForOne
DateTime reportDate = new(2026, 7, 6);
- applicationCache.Setup(a => a.GetMerchantDetails()).Returns(merchantDetails);
- reportsService.Setup(r => r.GetRecentActivityReceiptReport(
+ applicationCache.GetMerchantDetails().Returns(merchantDetails);
+ reportsService.GetRecentActivityReceiptReport(
merchantDetails.MerchantReportingId,
reportDate,
"TXN-10001",
1,
5,
- It.IsAny()))
+ Arg.Any())
.ReturnsAsync(Result.Success(RecentActivityReceiptReportModel.CreateMock(reportDate, "TXN-10001")));
- ReportRequestHandler handler = new(reportsService.Object, applicationCache.Object);
+ ReportRequestHandler handler = new(reportsService.Instance(), applicationCache.Instance());
Result result = await handler.Handle(
new ReportQueries.GetRecentActivityReceiptReportQuery(
@@ -161,21 +158,20 @@ public async Task GetRecentActivityReceiptReportQuery_ReturnsMockedResultsForOne
result.Data.ReportDate.ShouldBe(reportDate);
result.Data.Items.ShouldNotBeEmpty();
result.Data.Items.All(item => item.TransactionDateTime.Date == reportDate).ShouldBeTrue();
- reportsService.Verify(r => r.GetRecentActivityReceiptReport(
+ reportsService.GetRecentActivityReceiptReport(
merchantDetails.MerchantReportingId,
reportDate,
"TXN-10001",
1,
5,
- It.IsAny()),
- Times.Once);
+ Arg.Any()).Called(Count.Once());
}
[Fact]
public async Task GetRecentActivityReceiptReportQuery_PassesPagingToService()
{
- Mock reportsService = new();
- Mock applicationCache = new();
+ IReportsServiceImposter reportsService = new();
+ IApplicationCacheImposter applicationCache = new();
MerchantDetailsModel merchantDetails = new()
{
MerchantReportingId = 12345
@@ -183,17 +179,17 @@ public async Task GetRecentActivityReceiptReportQuery_PassesPagingToService()
DateTime reportDate = new(2026, 7, 6);
- applicationCache.Setup(a => a.GetMerchantDetails()).Returns(merchantDetails);
- reportsService.Setup(r => r.GetRecentActivityReceiptReport(
+ applicationCache.GetMerchantDetails().Returns(merchantDetails);
+ reportsService.GetRecentActivityReceiptReport(
merchantDetails.MerchantReportingId,
reportDate,
- null,
+ Arg.Any(),
2,
5,
- It.IsAny()))
+ Arg.Any())
.ReturnsAsync(Result.Success(RecentActivityReceiptReportModel.CreateMock(reportDate, null)));
- ReportRequestHandler handler = new(reportsService.Object, applicationCache.Object);
+ ReportRequestHandler handler = new(reportsService.Instance(), applicationCache.Instance());
Result result = await handler.Handle(
new ReportQueries.GetRecentActivityReceiptReportQuery(
@@ -204,13 +200,12 @@ public async Task GetRecentActivityReceiptReportQuery_PassesPagingToService()
CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
- reportsService.Verify(r => r.GetRecentActivityReceiptReport(
+ reportsService.GetRecentActivityReceiptReport(
merchantDetails.MerchantReportingId,
reportDate,
- null,
+ Arg.Any(),
2,
5,
- It.IsAny()),
- Times.Once);
+ Arg.Any()).Called(Count.Once());
}
}
diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/SupportRequestHandlerTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/SupportRequestHandlerTests.cs
index 13902504..9778c0b4 100644
--- a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/SupportRequestHandlerTests.cs
+++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/SupportRequestHandlerTests.cs
@@ -1,4 +1,4 @@
-using Moq;
+using Imposter.Abstractions;
using Shouldly;
using SimpleResults;
using TransactionProcessor.Mobile.BusinessLogic.Database;
@@ -17,17 +17,17 @@ public class SupportRequestHandlerTests
[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_NoLogs_Handle_IsHandled()
{
- Mock configurationService = new Mock();
+ IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter();
Func configurationServiceResolver = new Func((param) =>
{
- return configurationService.Object;
+ return configurationService.Instance();
});
- Mock databaseContext = new Mock();
- databaseContext.Setup(d => d.GetLogMessages(It.IsAny(), It.IsAny())).ReturnsAsync(new List());
- Mock applicationCache = new Mock();
- applicationCache.Setup(s => s.GetConfiguration()).Returns(new Configuration());
- SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);
+ IDatabaseContextImposter databaseContext = new IDatabaseContextImposter();
+ databaseContext.GetLogMessages(Arg.Any(), Arg.Any()).ReturnsAsync(new List());
+ IApplicationCacheImposter applicationCache = new IApplicationCacheImposter();
+ applicationCache.GetConfiguration().Returns(new Configuration());
+ SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Instance(), applicationCache.Instance());
SupportCommands.UploadLogsCommand request = new(TestData.DeviceIdentifier);
@@ -39,35 +39,35 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_NoLogs_Handle_IsH
[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_NoConfiguration_ReturnsFailure()
{
- Mock configurationService = new Mock();
- Func configurationServiceResolver = _ => configurationService.Object;
+ IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter();
+ Func configurationServiceResolver = _ => configurationService.Instance();
- Mock databaseContext = new Mock();
- Mock applicationCache = new Mock();
- applicationCache.Setup(s => s.GetConfiguration()).Returns((Configuration)null);
+ IDatabaseContextImposter databaseContext = new IDatabaseContextImposter();
+ IApplicationCacheImposter applicationCache = new IApplicationCacheImposter();
+ applicationCache.GetConfiguration().Returns((Configuration)null);
- SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);
+ SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Instance(), applicationCache.Instance());
SupportCommands.UploadLogsCommand request = new(TestData.DeviceIdentifier);
Result response = await handler.Handle(request, CancellationToken.None);
response.IsFailed.ShouldBeTrue();
- configurationService.Verify(c => c.PostDiagnosticLogs(It.IsAny(), It.IsAny>(), It.IsAny()), Times.Never);
- databaseContext.Verify(d => d.GetLogMessages(It.IsAny(), It.IsAny()), Times.Never);
+ configurationService.PostDiagnosticLogs(Arg.Any(), Arg>.Any(), Arg.Any()).Called(Count.Never());
+ databaseContext.GetLogMessages(Arg.Any(), Arg.Any()).Called(Count.Never());
}
[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_Only10Messages_Handle_IsHandled()
{
- Mock configurationService = new Mock();
- configurationService.Setup(c => c.PostDiagnosticLogs(It.IsAny(), It.IsAny>(), It.IsAny())).ReturnsAsync(Result.Success());
+ IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter();
+ configurationService.PostDiagnosticLogs(Arg.Any(), Arg>.Any(), Arg.Any()).ReturnsAsync(Result.Success());
Func configurationServiceResolver = new Func((param) =>
{
- return configurationService.Object;
+ return configurationService.Instance();
});
- Mock databaseContext = new Mock();
- databaseContext.SetupSequence(d => d.GetLogMessages(It.IsAny(), It.IsAny())).ReturnsAsync(new List()
+ IDatabaseContextImposter databaseContext = new IDatabaseContextImposter();
+ databaseContext.GetLogMessages(Arg.Any(), Arg.Any()).ReturnsAsync(new List()
{
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
@@ -79,32 +79,32 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_Only
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()}
- }).ReturnsAsync(new List());
+ }).Then().ReturnsAsync(new List());
- Mock applicationCache = new Mock();
- applicationCache.Setup(s => s.GetConfiguration()).Returns(new Configuration());
+ IApplicationCacheImposter applicationCache = new IApplicationCacheImposter();
+ applicationCache.GetConfiguration().Returns(new Configuration());
- SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);
+ SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Instance(), applicationCache.Instance());
SupportCommands.UploadLogsCommand request = new(TestData.DeviceIdentifier);
Result response = await handler.Handle(request, CancellationToken.None);
response.IsSuccess.ShouldBeTrue();
- databaseContext.Verify(d => d.RemoveUploadedMessages(It.IsAny>()), Times.Once);
+ databaseContext.RemoveUploadedMessages(Arg>.Any()).Called(Count.Once());
}
[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_15Messages_Handle_IsHandled()
{
- Mock configurationService = new Mock();
- configurationService.Setup(c => c.PostDiagnosticLogs(It.IsAny(), It.IsAny>(), It.IsAny())).ReturnsAsync(Result.Success());
+ IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter();
+ configurationService.PostDiagnosticLogs(Arg.Any(), Arg>.Any(), Arg.Any()).ReturnsAsync(Result.Success());
Func configurationServiceResolver = new Func((param) =>
{
- return configurationService.Object;
+ return configurationService.Instance();
});
- Mock databaseContext = new Mock();
- databaseContext.SetupSequence(d => d.GetLogMessages(It.IsAny(), It.IsAny())).ReturnsAsync(new List()
+ IDatabaseContextImposter databaseContext = new IDatabaseContextImposter();
+ databaseContext.GetLogMessages(Arg.Any(), Arg.Any()).ReturnsAsync(new List()
{
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
@@ -116,91 +116,92 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_LogsToUpload_15Me
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
- }).ReturnsAsync(new List()
+ }).Then().ReturnsAsync(new List()
{
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
new Database.LogMessage{LogLevel = LogLevel.Debug.ToString()},
- }).ReturnsAsync(new List());
+ }).Then().ReturnsAsync(new List());
- Mock applicationCache = new Mock();
- applicationCache.Setup(s => s.GetConfiguration()).Returns(new Configuration());
+ IApplicationCacheImposter applicationCache = new IApplicationCacheImposter();
+ applicationCache.GetConfiguration().Returns(new Configuration());
- SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Object, applicationCache.Object);
+ SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext.Instance(), applicationCache.Instance());
SupportCommands.UploadLogsCommand request = new(TestData.DeviceIdentifier);
Result response = await handler.Handle(request, CancellationToken.None);
response.IsSuccess.ShouldBeTrue();
- databaseContext.Verify(d => d.RemoveUploadedMessages(It.IsAny>()), Times.Exactly(2));
+ databaseContext.RemoveUploadedMessages(Arg>.Any()).Called(Count.Exactly(2));
}
[Fact]
public async Task SupportRequestHandlerTests_UploadLogsRequest_InvalidLogLevel_ReturnsFailure()
{
- Mock