From d6d80a26556daa8e965ba01e3d95fe53418b89bb Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Thu, 3 Sep 2026 14:49:46 +0100 Subject: [PATCH 1/2] Refactor transaction mobile implementation --- Directory.Packages.props | 4 +- .../CommonTests/ExtensionsTests.cs | 2 +- .../ImposterGeneration.cs | 36 ++ .../LoginRequestHandlerTests.cs | 56 ++-- .../MerchantRequestHandlerTests.cs | 54 +-- .../ReportRequestHandlerTests.cs | 107 +++--- .../SupportRequestHandlerTests.cs | 133 ++++---- .../TransactionRequestHandlerTests.cs | 74 ++--- .../AuthenticationServiceTests.cs | 20 +- .../ConfigurationServiceTests.cs | 2 +- .../ServicesTests/MerchantServiceTests.cs | 18 +- .../ServicesTests/ReportsServiceTests.cs | 18 +- .../ServicesTests/TransactionServiceTests.cs | 10 +- .../ServicesTests/UpdateServiceTests.cs | 2 +- .../TestData.cs | 2 +- ...rocessor.Mobile.BusinessLogic.Tests.csproj | 2 +- .../ExtendedBaseViewModelTests.cs | 44 +-- .../ViewModelTests/HomePageViewModelTests.cs | 92 +++--- .../ViewModelTests/LoginPageViewModelTests.cs | 312 +++++++----------- .../MyAccountAddressPageViewModelTests.cs | 46 +-- .../MyAccountContactPageViewModelTests.cs | 44 +-- .../MyAccountDetailsPageViewModelTests.cs | 46 +-- .../MyAccount/MyAccountPageViewModelTests.cs | 72 ++-- ...ilyPerformanceSummaryPageViewModelTests.cs | 40 +-- ...ActivityReceiptDetailPageViewModelTests.cs | 65 ++-- .../RecentActivityReportPageViewModelTests.cs | 53 +-- .../Reports/ReportsPageViewModelTests.cs | 52 +-- .../TransactionMixPageViewModelTests.cs | 40 +-- .../Support/SupportPageViewModelTests.cs | 77 ++--- .../Support/ViewLogsPageViewModelTests.cs | 44 +-- .../Admin/AdminPageViewModelTests.cs | 50 +-- .../BillPaymentFailedPageViewModelTests.cs | 10 +- ...BillPaymentGetAccountPageViewModelTests.cs | 54 +-- .../BillPaymentGetMeterPageViewModelTests.cs | 52 +-- .../BillPaymentPayBillPageViewModelTests.cs | 78 ++--- ...PaymentSelectOperatorPageViewModelTests.cs | 50 +-- ...lPaymentSelectProductPageViewModelTests.cs | 68 ++-- .../BillPaymentSuccessPageViewModelTests.cs | 10 +- .../MobileTopupFailedPageViewModelTests.cs | 10 +- ...bileTopupPerformTopupPageViewModelTests.cs | 64 ++-- ...leTopupSelectOperatorPageViewModelTests.cs | 42 +-- ...ileTopupSelectProductPageViewModelTests.cs | 52 +-- .../MobileTopupSuccessPageViewModelTests.cs | 10 +- .../TransactionsPageViewModelTests.cs | 38 +-- .../VoucherIssueFailedPageViewModelTests.cs | 10 +- ...herIssueSelectProductPageViewModelTests.cs | 56 ++-- .../VoucherIssueSuccessPageViewModelTests.cs | 10 +- .../VoucherPerformIssuePageViewModelTests.cs | 58 ++-- ...VoucherSelectOperatorPageViewModelTests.cs | 42 +-- 49 files changed, 1152 insertions(+), 1179 deletions(-) create mode 100644 TransactionProcessor.Mobile.BusinessLogic.Tests/ImposterGeneration.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 7bc942bf1..c8b61371f 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 6a9018754..295b496fe 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 000000000..ad7966b61 --- /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 a2a8c6e17..124118620 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 411ae5f34..6ed4735d0 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 1756205b7..2bff75c00 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 13902504b..9778c0b47 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 configurationService = new Mock(); - Func configurationServiceResolver = _ => configurationService.Object; + IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter(); + Func configurationServiceResolver = _ => configurationService.Instance(); - Mock databaseContext = new Mock(); - databaseContext.Setup(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 = "NotALogLevel" } }); - 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.IsFailed.ShouldBeTrue(); - configurationService.Verify(c => c.PostDiagnosticLogs(It.IsAny(), It.IsAny>(), It.IsAny()), Times.Never); - databaseContext.Verify(d => d.RemoveUploadedMessages(It.IsAny>()), Times.Never); + configurationService.PostDiagnosticLogs(Arg.Any(), Arg>.Any(), Arg.Any()).Called(Count.Never()); + databaseContext.RemoveUploadedMessages(Arg>.Any()).Called(Count.Never()); } [Fact] public async Task SupportRequestHandlerTests_UploadLogsRequest_CancellationStopsFurtherProcessing() { - Mock configurationService = new Mock(); + IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); - configurationService.Setup(c => c.PostDiagnosticLogs(It.IsAny(), It.IsAny>(), It.IsAny())) - .Callback, CancellationToken>((_, _, _) => + configurationService.PostDiagnosticLogs(Arg.Any(), Arg>.Any(), Arg.Any()) + .ReturnsAsync(Result.Success()) + .Callback((String _, List _, CancellationToken _) => { cancellationTokenSource.Cancel(); - }) - .ReturnsAsync(Result.Success()); + return Task.CompletedTask; + }); - Func configurationServiceResolver = _ => configurationService.Object; + Func configurationServiceResolver = _ => configurationService.Instance(); - Mock databaseContext = new Mock(); - databaseContext.SetupSequence(d => d.GetLogMessages(It.IsAny(), It.IsAny())) + IDatabaseContextImposter databaseContext = new IDatabaseContextImposter(); + databaseContext.GetLogMessages(Arg.Any(), Arg.Any()) .ReturnsAsync(new List { new Database.LogMessage { LogLevel = LogLevel.Debug.ToString() } }) - .ReturnsAsync(new List + .Then().ReturnsAsync(new List { new Database.LogMessage { LogLevel = LogLevel.Debug.ToString() } }); - 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); await Should.ThrowAsync(async () => await handler.Handle(request, cancellationTokenSource.Token)); - configurationService.Verify(c => c.PostDiagnosticLogs(It.IsAny(), It.IsAny>(), cancellationTokenSource.Token), Times.Once); - databaseContext.Verify(d => d.GetLogMessages(It.IsAny(), It.IsAny()), Times.Once); - databaseContext.Verify(d => d.RemoveUploadedMessages(It.IsAny>()), Times.Once); + configurationService.PostDiagnosticLogs(Arg.Any(), Arg>.Any(), cancellationTokenSource.Token).Called(Count.Once()); + databaseContext.GetLogMessages(Arg.Any(), Arg.Any()).Called(Count.Once()); + databaseContext.RemoveUploadedMessages(Arg>.Any()).Called(Count.Once()); } [Theory] @@ -208,10 +209,10 @@ public async Task SupportRequestHandlerTests_UploadLogsRequest_CancellationStops [InlineData(false, 3)] public async Task SupportRequestHandlerTests_ViewLogsRequest_Handle_IsHandled(Boolean isTrainingMode, Int32 expectedNumberMessages) { - Mock configurationService = new Mock(); + IConfigurationServiceImposter configurationService = new IConfigurationServiceImposter(); Func configurationServiceResolver = new Func((param) => { - return configurationService.Object; + return configurationService.Instance(); }); Func logLevelFunc = new Func(() => { @@ -230,9 +231,9 @@ public async Task SupportRequestHandlerTests_ViewLogsRequest_Handle_IsHandled(Bo logMessages.Add(new LogMessage { LogLevel = LogLevel.Debug.ToString(), IsTrainingMode = true }); await databaseContext.InsertLogMessages(logMessages); - Mock applicationCache = new Mock(); - applicationCache.Setup(s => s.GetUseTrainingMode()).Returns(isTrainingMode); - SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext, applicationCache.Object); + IApplicationCacheImposter applicationCache = new IApplicationCacheImposter(); + applicationCache.GetUseTrainingMode().Returns(isTrainingMode); + SupportRequestHandler handler = new SupportRequestHandler(configurationServiceResolver, databaseContext, applicationCache.Instance()); SupportQueries.ViewLogsQuery request = new(); Result> result = await handler.Handle(request, CancellationToken.None); diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/TransactionRequestHandlerTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/TransactionRequestHandlerTests.cs index bc64eb145..d7543305e 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/TransactionRequestHandlerTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/RequestHandlerTests/TransactionRequestHandlerTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Database; @@ -13,37 +13,37 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.RequestHandlerTests; public class TransactionRequestHandlerTests { - private Mock TransactionService; + private ITransactionServiceImposter TransactionService; - private Mock DatabaseContext; + private IDatabaseContextImposter DatabaseContext; - private Mock ApplicationCache; + private IApplicationCacheImposter ApplicationCache; - private Mock ApplicationInfoService; + private IApplicationInfoServiceImposter ApplicationInfoService; - private Mock DeviceService; + private IDeviceServiceImposter DeviceService; private TransactionRequestHandler TransactionRequestHandler; private Func TransactionServiceResolver; public TransactionRequestHandlerTests() { - this.TransactionService = new Mock(); - this.DatabaseContext = new Mock(); - this.ApplicationCache = new Mock(); - this.ApplicationInfoService = new Mock(); - this.DeviceService = new Mock(); + this.TransactionService = new ITransactionServiceImposter(); + this.DatabaseContext = new IDatabaseContextImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.ApplicationInfoService = new IApplicationInfoServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); this.TransactionServiceResolver = _ => { - return this.TransactionService.Object; + return this.TransactionService.Instance(); }; this.TransactionRequestHandler = new TransactionRequestHandler(this.TransactionServiceResolver, - this.DatabaseContext.Object, - this.ApplicationCache.Object, - this.ApplicationInfoService.Object, - this.DeviceService.Object); + this.DatabaseContext.Instance(), + this.ApplicationCache.Instance(), + this.ApplicationInfoService.Instance(), + this.DeviceService.Instance()); StringSerialiser.Initialise((IStringSerialiser)new SystemTextJsonSerializer(SystemTextJsonSerializer.GetDefaultJsonSerializerOptions())); } @@ -51,7 +51,7 @@ public TransactionRequestHandlerTests() { [Fact] public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformLogon(It.IsAny(), It.IsAny())).ReturnsAsync( + this.TransactionService.PerformLogon(Arg.Any(), Arg.Any()).ReturnsAsync( Result.Success(TestData.PerformLogonResponseModel)); TransactionCommands.PerformLogonCommand request = new(TestData.TransactionDateTime); @@ -65,7 +65,7 @@ public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_IsHan [Fact] public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_LogonFailed_IsHandled() { - this.TransactionService.Setup(t => t.PerformLogon(It.IsAny(), It.IsAny())).ReturnsAsync( + this.TransactionService.PerformLogon(Arg.Any(), Arg.Any()).ReturnsAsync( Result.Success(TestData.PerformLogonResponseFailedModel)); TransactionCommands.PerformLogonCommand request = new(TestData.TransactionDateTime); @@ -78,8 +78,8 @@ public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_Logon [Fact] public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_ServiceFailure_ReturnsFailure_AndDoesNotUpdateTransaction() { - this.DatabaseContext.Setup(d => d.CreateTransaction(It.IsAny())).ReturnsAsync(1); - this.TransactionService.Setup(t => t.PerformLogon(It.IsAny(), It.IsAny())) + this.DatabaseContext.CreateTransaction(Arg.Any()).ReturnsAsync(1); + this.TransactionService.PerformLogon(Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Failure("Logon failed")); TransactionCommands.PerformLogonCommand request = new(TestData.TransactionDateTime); @@ -87,13 +87,13 @@ public async Task TransactionRequestHandler_LogonTransactionRequest_Handle_Servi Result result = await this.TransactionRequestHandler.Handle(request, CancellationToken.None); result.IsFailed.ShouldBeTrue(); - this.DatabaseContext.Verify(d => d.UpdateTransaction(It.IsAny()), Times.Never); + this.DatabaseContext.UpdateTransaction(Arg.Any()).Called(Count.Never()); } [Fact] public async Task TransactionRequestHandler_PerformMobileTopupRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformMobileTopup(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel + this.TransactionService.PerformMobileTopup(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel { ResponseCode = "0000" })); @@ -115,7 +115,7 @@ public async Task TransactionRequestHandler_PerformMobileTopupRequest_Handle_IsH [Fact] public async Task TransactionRequestHandler_PerformMobileTopupRequest_Handle_TopupFailed_IsHandled() { - this.TransactionService.Setup(t => t.PerformMobileTopup(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel + this.TransactionService.PerformMobileTopup(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel { ResponseCode = "1000" })); @@ -136,7 +136,7 @@ public async Task TransactionRequestHandler_PerformMobileTopupRequest_Handle_Top [Fact] public async Task TransactionRequestHandler_PerformVoucherIssueRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformVoucherIssue(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel + this.TransactionService.PerformVoucherIssue(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel { ResponseCode = "0000" })); @@ -158,7 +158,7 @@ public async Task TransactionRequestHandler_PerformVoucherIssueRequest_Handle_Is [Fact] public async Task TransactionRequestHandler_PerformVoucherIssueRequest_Handle_VoucherIssueFailed_IsHandled() { - this.TransactionService.Setup(t => t.PerformVoucherIssue(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel + this.TransactionService.PerformVoucherIssue(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel { ResponseCode = "1000" })); @@ -181,7 +181,7 @@ public async Task TransactionRequestHandler_PerformVoucherIssueRequest_Handle_Vo [Fact] public async Task TransactionRequestHandler_PerformBillPaymentGetAccountRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentGetAccount(It.IsAny(), It.IsAny())) + this.TransactionService.PerformBillPaymentGetAccount(Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetAccountResponseModel)); TransactionCommands.PerformBillPaymentGetAccountCommand request = new TransactionCommands.PerformBillPaymentGetAccountCommand(TestData.TransactionDateTime, @@ -201,7 +201,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentGetAccountRequest_ [Fact] public async Task TransactionRequestHandler_PerformBillPaymentGetAccountRequest_GetAccountFailed_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentGetAccount(It.IsAny(), It.IsAny())) + this.TransactionService.PerformBillPaymentGetAccount(Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetAccountResponseModelFailed)); TransactionCommands.PerformBillPaymentGetAccountCommand request = new TransactionCommands.PerformBillPaymentGetAccountCommand(TestData.TransactionDateTime, @@ -220,7 +220,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentGetAccountRequest_ [Fact] public async Task TransactionRequestHandler_PerformBillPaymentGetMeterRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentGetMeter(It.IsAny(), It.IsAny())) + this.TransactionService.PerformBillPaymentGetMeter(Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetMeterResponseModel)); TransactionCommands.PerformBillPaymentGetMeterCommand request = new TransactionCommands.PerformBillPaymentGetMeterCommand(TestData.TransactionDateTime, @@ -240,7 +240,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentGetMeterRequest_Ha [Fact] public async Task TransactionRequestHandler_PerformBillPaymentGetMeterRequest_GetMeterFailed_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentGetMeter(It.IsAny(), It.IsAny())) + this.TransactionService.PerformBillPaymentGetMeter(Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetMeterResponseModelFailed)); TransactionCommands.PerformBillPaymentGetMeterCommand request = new TransactionCommands.PerformBillPaymentGetMeterCommand(TestData.TransactionDateTime, @@ -259,7 +259,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentGetMeterRequest_Ge [Fact] public async Task TransactionRequestHandler_PerformBillPaymentMakePostPaymentRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentMakePayment(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel + this.TransactionService.PerformBillPaymentMakePayment(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel { ResponseCode = "0000" })); @@ -282,7 +282,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentMakePostPaymentReq [Fact] public async Task TransactionRequestHandler_PerformBillPaymentMakePrePaymentRequest_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentMakePayment(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel + this.TransactionService.PerformBillPaymentMakePayment(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel { ResponseCode = "0000" })); @@ -303,7 +303,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentMakePrePaymentRequ [Fact] public async Task TransactionRequestHandler_PerformBillPaymentMakePostPaymentRequest_PaymentFailed_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentMakePayment(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel + this.TransactionService.PerformBillPaymentMakePayment(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel { ResponseCode = "0001" })); @@ -325,7 +325,7 @@ public async Task TransactionRequestHandler_PerformBillPaymentMakePostPaymentReq [Fact] public async Task TransactionRequestHandler_PerformBillPaymentMakePrePaymentRequest_PaymentFailed_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformBillPaymentMakePayment(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel + this.TransactionService.PerformBillPaymentMakePayment(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel { ResponseCode = "0001" })); @@ -346,11 +346,11 @@ public async Task TransactionRequestHandler_PerformBillPaymentMakePrePaymentRequ [Fact] public async Task TransactionRequestHandler_PerformReconciliationRequest_NoTransactions_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformReconciliation(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformReconciliationResponseModel + this.TransactionService.PerformReconciliation(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformReconciliationResponseModel { ResponseCode = "0000" })); - this.DatabaseContext.Setup(d => d.GetTransactions(It.IsAny())).ReturnsAsync(new List()); + this.DatabaseContext.GetTransactions(Arg.Any()).ReturnsAsync(new List()); TransactionCommands.PerformReconciliationCommand request = new TransactionCommands.PerformReconciliationCommand(TestData.TransactionDateTime, TestData.DeviceIdentifier, TestData.ApplicationVersion); @@ -362,12 +362,12 @@ public async Task TransactionRequestHandler_PerformReconciliationRequest_NoTrans [Fact] public async Task TransactionRequestHandler_PerformReconciliationRequest_TransactionsStored_Handle_IsHandled() { - this.TransactionService.Setup(t => t.PerformReconciliation(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformReconciliationResponseModel + this.TransactionService.PerformReconciliation(Arg.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformReconciliationResponseModel { ResponseCode = "0000" })); - this.DatabaseContext.Setup(d => d.GetTransactions(It.IsAny())).ReturnsAsync(TestData.StoredTransactions); + this.DatabaseContext.GetTransactions(Arg.Any()).ReturnsAsync(TestData.StoredTransactions); TransactionCommands.PerformReconciliationCommand request = new TransactionCommands.PerformReconciliationCommand(TestData.TransactionDateTime, TestData.DeviceIdentifier, TestData.ApplicationVersion); diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/AuthenticationServiceTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/AuthenticationServiceTests.cs index 583e329a5..2377dc300 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/AuthenticationServiceTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/AuthenticationServiceTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using SecurityService.Client; using SecurityService.DataTransferObjects; using Shouldly; @@ -12,17 +12,17 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ServicesTests public class AuthenticationServiceTests{ private readonly IAuthenticationService AuthenticationService; - private readonly Mock SecurityServiceClient; + private readonly ISecurityServiceClientImposter SecurityServiceClient; public AuthenticationServiceTests(){ Logger.Initialise(new NullLogger()); - this.SecurityServiceClient = new Mock(); - this.AuthenticationService = new AuthenticationService(this.SecurityServiceClient.Object); + this.SecurityServiceClient = new ISecurityServiceClientImposter(); + this.AuthenticationService = new AuthenticationService(this.SecurityServiceClient.Instance()); } [Fact] public async Task AuthenticationService_GetToken_TokenReturned(){ - this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TokenResponse.Create(TestData.Token, TestData.RefreshToken, TestData.TokenExpiryInMinutes)); + this.SecurityServiceClient.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(TokenResponse.Create(TestData.Token, TestData.RefreshToken, TestData.TokenExpiryInMinutes)); Result token = await this.AuthenticationService.GetToken(TestData.UserName, TestData.Password, TestData.ClientId, TestData.ClientSecret, CancellationToken.None); token.IsSuccess.ShouldBeTrue(); @@ -34,7 +34,7 @@ public async Task AuthenticationService_GetToken_TokenReturned(){ [Fact] public async Task AuthenticationService_GetToken_SecurityClientFailed_TokenNotReturned() { - this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure()); + this.SecurityServiceClient.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(Result.Failure()); Result token = await this.AuthenticationService.GetToken(TestData.UserName, TestData.Password, TestData.ClientId, TestData.ClientSecret, CancellationToken.None); token.IsFailed.ShouldBeTrue(); @@ -43,7 +43,7 @@ public async Task AuthenticationService_GetToken_SecurityClientFailed_TokenNotRe [Fact] public async Task AuthenticationService_GetToken_SecurityClientThrowsException_TokenNotReturned() { - this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ThrowsAsync(new Exception()); + this.SecurityServiceClient.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ThrowsAsync(new Exception()); Result token = await this.AuthenticationService.GetToken(TestData.UserName, TestData.Password, TestData.ClientId, TestData.ClientSecret, CancellationToken.None); token.IsFailed.ShouldBeTrue(); @@ -52,7 +52,7 @@ public async Task AuthenticationService_GetToken_SecurityClientThrowsException_T [Fact] public async Task AuthenticationService_RefreshAccessToken_TokenReturned() { - this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(TokenResponse.Create(TestData.Token, TestData.RefreshToken, TestData.TokenExpiryInMinutes)); + this.SecurityServiceClient.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(TokenResponse.Create(TestData.Token, TestData.RefreshToken, TestData.TokenExpiryInMinutes)); Result token = await this.AuthenticationService.RefreshAccessToken(TestData.RefreshToken, TestData.ClientId, TestData.ClientSecret, CancellationToken.None); token.IsSuccess.ShouldBeTrue(); @@ -64,7 +64,7 @@ public async Task AuthenticationService_RefreshAccessToken_TokenReturned() [Fact] public async Task AuthenticationService_RefreshAccessToken_SecurityClientFailed_TokenNotReturned() { - this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure()); + this.SecurityServiceClient.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(Result.Failure()); Result token = await this.AuthenticationService.RefreshAccessToken(TestData.RefreshToken, TestData.ClientId, TestData.ClientSecret, CancellationToken.None); @@ -74,7 +74,7 @@ public async Task AuthenticationService_RefreshAccessToken_SecurityClientFailed_ [Fact] public async Task AuthenticationService_RefreshAccessToken_SecurityClientThrowsException_TokenNotReturned() { - this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ThrowsAsync(new Exception()); + this.SecurityServiceClient.GetToken(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ThrowsAsync(new Exception()); Result token = await this.AuthenticationService.RefreshAccessToken(TestData.RefreshToken, TestData.ClientId, TestData.ClientSecret, CancellationToken.None); diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ConfigurationServiceTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ConfigurationServiceTests.cs index ee070cd43..2616a15e1 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ConfigurationServiceTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ConfigurationServiceTests.cs @@ -1,4 +1,4 @@ -using RichardSzalay.MockHttp; +using RichardSzalay.MockHttp; using Shouldly; using System.Net; using TransactionProcessor.Mobile.BusinessLogic.Logging; diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/MerchantServiceTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/MerchantServiceTests.cs index 45f7fccc8..cc70843e7 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/MerchantServiceTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/MerchantServiceTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using RichardSzalay.MockHttp; using Shouldly; using SimpleResults; @@ -18,8 +18,8 @@ public class MerchantServiceTests{ private Func BaseAddressResolver; - private readonly Mock ApplicationCache; - private readonly Mock ApplicationInfoService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IApplicationInfoServiceImposter ApplicationInfoService; private readonly IMerchantService MerchantService; @@ -37,14 +37,14 @@ public MerchantServiceTests(){ Logger.Initialise(new NullLogger()); this.MockHttpMessageHandler = new MockHttpMessageHandler(); this.BaseAddressResolver = (s) => $"http://localhost"; - this.ApplicationCache = new Mock(); - this.ApplicationInfoService = new Mock(); - this.ApplicationInfoService.Setup(a => a.VersionString).Returns("1.0.0"); - this.MerchantService = new MerchantService(this.BaseAddressResolver, this.MockHttpMessageHandler.ToHttpClient(),this.ApplicationCache.Object, - this.ApplicationInfoService.Object, Serialise, Deserialise); + this.ApplicationCache = new IApplicationCacheImposter(); + this.ApplicationInfoService = new IApplicationInfoServiceImposter(); + this.ApplicationInfoService.VersionString.Getter().Returns("1.0.0"); + this.MerchantService = new MerchantService(this.BaseAddressResolver, this.MockHttpMessageHandler.ToHttpClient(),this.ApplicationCache.Instance(), + this.ApplicationInfoService.Instance(), Serialise, Deserialise); // Standard cache mocking here - this.ApplicationCache.Setup(a => a.GetAccessToken()).Returns(TestData.AccessToken); + this.ApplicationCache.GetAccessToken().Returns(TestData.AccessToken); StringSerialiser.Initialise((IStringSerialiser)new SystemTextJsonSerializer(SystemTextJsonSerializer.GetDefaultJsonSerializerOptions())); } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ReportsServiceTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ReportsServiceTests.cs index dfdcd433e..074b27de6 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ReportsServiceTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/ReportsServiceTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using RichardSzalay.MockHttp; using Shouldly; using SimpleResults; @@ -15,26 +15,26 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ServicesTests; public class ReportsServiceTests { private readonly MockHttpMessageHandler MockHttpMessageHandler; - private readonly Mock ApplicationCache; - private readonly Mock ApplicationInfoService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IApplicationInfoServiceImposter ApplicationInfoService; private readonly IReportsService ReportsService; public ReportsServiceTests() { this.MockHttpMessageHandler = new MockHttpMessageHandler(); - this.ApplicationCache = new Mock(); - this.ApplicationInfoService = new Mock(); - this.ApplicationCache.Setup(s => s.GetAccessToken()).Returns(new TokenResponseModel + this.ApplicationCache = new IApplicationCacheImposter(); + this.ApplicationInfoService = new IApplicationInfoServiceImposter(); + this.ApplicationCache.GetAccessToken().Returns(new TokenResponseModel { AccessToken = "token" }); - this.ApplicationInfoService.Setup(s => s.VersionString).Returns("1.2.3"); + this.ApplicationInfoService.VersionString.Getter().Returns("1.2.3"); this.ReportsService = new ReportsService(_ => "http://localhost", this.MockHttpMessageHandler.ToHttpClient(), - this.ApplicationCache.Object, + this.ApplicationCache.Instance(), obj => StringSerialiser.Serialise(obj), (json, type) => StringSerialiser.DeserializeObject(json, type), - this.ApplicationInfoService.Object); + this.ApplicationInfoService.Instance()); Logger.Initialise(new NullLogger()); StringSerialiser.Initialise((IStringSerialiser)new SystemTextJsonSerializer(SystemTextJsonSerializer.GetDefaultJsonSerializerOptions())); } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/TransactionServiceTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/TransactionServiceTests.cs index 94b176446..3ef9a0b42 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/TransactionServiceTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/TransactionServiceTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using RichardSzalay.MockHttp; using Shouldly; using SimpleResults; @@ -21,7 +21,7 @@ public class TransactionServiceTests{ private ITransactionService TransactionService; - private Mock ApplicationCache; + private IApplicationCacheImposter ApplicationCache; String Serialise(Object arg) { @@ -131,9 +131,9 @@ PerformBillPaymentMakePaymentModel CreateBillPaymentMakePaymentRequestModel(Bool public TransactionServiceTests(){ this.MockHttpMessageHandler = new MockHttpMessageHandler(); this.BaseAddressResolver = (s) => $"http://localhost"; - this.ApplicationCache = new Mock(); - this.TransactionService = new TransactionService(this.BaseAddressResolver, this.MockHttpMessageHandler.ToHttpClient(), this.ApplicationCache.Object, this.Serialise,this.Deserialise); - this.ApplicationCache.Setup(s => s.GetAccessToken()).Returns(new TokenResponseModel(){ + this.ApplicationCache = new IApplicationCacheImposter(); + this.TransactionService = new TransactionService(this.BaseAddressResolver, this.MockHttpMessageHandler.ToHttpClient(), this.ApplicationCache.Instance(), this.Serialise,this.Deserialise); + this.ApplicationCache.GetAccessToken().Returns(new TokenResponseModel(){ AccessToken = "token" }); Logger.Initialise(new Logging.NullLogger()); diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/UpdateServiceTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/UpdateServiceTests.cs index 223b8ef77..5a362a38f 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/UpdateServiceTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ServicesTests/UpdateServiceTests.cs @@ -1,4 +1,4 @@ -using RichardSzalay.MockHttp; +using RichardSzalay.MockHttp; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Logging; diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/TestData.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/TestData.cs index 1f4e7bcca..4722d2405 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/TestData.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/TestData.cs @@ -1,4 +1,4 @@ -using TransactionProcessor.Mobile.BusinessLogic.Database; +using TransactionProcessor.Mobile.BusinessLogic.Database; using TransactionProcessor.Mobile.BusinessLogic.Models; namespace TransactionProcessor.Mobile.BusinessLogic.Tests diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/TransactionProcessor.Mobile.BusinessLogic.Tests.csproj b/TransactionProcessor.Mobile.BusinessLogic.Tests/TransactionProcessor.Mobile.BusinessLogic.Tests.csproj index 436ad75b5..d49336423 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/TransactionProcessor.Mobile.BusinessLogic.Tests.csproj +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/TransactionProcessor.Mobile.BusinessLogic.Tests.csproj @@ -13,7 +13,7 @@ - + diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/ExtendedBaseViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/ExtendedBaseViewModelTests.cs index 2e86dcee9..02971339a 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/ExtendedBaseViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/ExtendedBaseViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Services; @@ -8,27 +8,27 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests { public class ExtendedBaseViewModelTests{ - private Mock ApplicationCache = null; + private IApplicationCacheImposter ApplicationCache = null; - private Mock DialogService = null; + private IDialogServiceImposter DialogService = null; - private Mock NavigationService = null; - private Mock NavigationParameterService = null; + private INavigationServiceImposter NavigationService = null; + private INavigationParameterServiceImposter NavigationParameterService = null; - private Mock DeviceService = null; + private IDeviceServiceImposter DeviceService = null; private ExtendedBaseViewModel ViewModel = null; public ExtendedBaseViewModelTests(){ - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.NavigationService = new Mock(); - this.DeviceService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ViewModel = new ExtendedBaseViewModel(this.ApplicationCache.Object, - this.DialogService.Object, - this.NavigationService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ViewModel = new ExtendedBaseViewModel(this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.NavigationService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] @@ -54,14 +54,14 @@ public async Task ExtendedBaseViewModel_HandleResult_ResultIsAndError_ErrorThrow [InlineData(Orientation.Landscape)] [InlineData(Orientation.Portrait)] public async Task ExtendedBaseViewModel_Initialise_OrientationIsSet(Orientation orientation){ - var viewModel = new ExtendedBaseViewModel(this.ApplicationCache.Object, - this.DialogService.Object, - this.NavigationService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object, + var viewModel = new ExtendedBaseViewModel(this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.NavigationService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance(), orientation); await this.ViewModel.Initialise(CancellationToken.None); - this.DeviceService.Verify(v => v.SetOrientation(It.IsAny()), Times.Once); + this.DeviceService.SetOrientation(Arg.Any()).Called(Count.Once()); viewModel.Orientation.ShouldBe(orientation); } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/HomePageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/HomePageViewModelTests.cs index a88e4c83c..4c6611ed7 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/HomePageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/HomePageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.Logging; using TransactionProcessor.Mobile.BusinessLogic.Services; using TransactionProcessor.Mobile.BusinessLogic.UIServices; @@ -11,61 +11,60 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests; [Collection("ViewModelTests")] public class HomePageViewModelTests { - private Mock navigationService; - private Mock navigationParameterService; + private INavigationServiceImposter navigationService; + private INavigationParameterServiceImposter navigationParameterService; - private Mock applicationCache; + private IApplicationCacheImposter applicationCache; - private Mock dialogService; + private IDialogServiceImposter dialogService; private HomePageViewModel viewModel; - private readonly Mock DeviceService; - private readonly Mock balanceRefresher; + private readonly IDeviceServiceImposter DeviceService; + private readonly IBalanceRefresherImposter balanceRefresher; public HomePageViewModelTests() { - this.navigationService = new Mock(); - this.applicationCache = new Mock(); - this.dialogService = new Mock(); - this.DeviceService = new Mock(); - this.navigationParameterService = new Mock(); - this.balanceRefresher = new Mock(); - this.balanceRefresher.SetupAdd(b => b.BalanceChanged += It.IsAny>()); - this.viewModel = new HomePageViewModel(this.applicationCache.Object, - this.dialogService.Object, - this.DeviceService.Object, - this.navigationService.Object, - this.navigationParameterService.Object, - this.balanceRefresher.Object); + this.navigationService = new INavigationServiceImposter(); + this.applicationCache = new IApplicationCacheImposter(); + this.dialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.navigationParameterService = new INavigationParameterServiceImposter(); + this.balanceRefresher = new IBalanceRefresherImposter(); + this.viewModel = new HomePageViewModel(this.applicationCache.Instance(), + this.dialogService.Instance(), + this.DeviceService.Instance(), + this.navigationService.Instance(), + this.navigationParameterService.Instance(), + this.balanceRefresher.Instance()); Logger.Initialise(new NullLogger()); } [Fact] public void HomePageViewModel_BackButtonCommand_Execute_UserSelectsToLogout_LoginPageDisplayed() { - this.dialogService.Setup(d => d.ShowDialog(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); + this.dialogService.ShowDialog(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(true); this.viewModel.BackButtonCommand.Execute(null); - this.navigationService.Verify(n => n.GoToLoginPage(), Times.Once); - this.dialogService.Verify(d => d.ShowDialog(It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny()), Times.Once); + this.navigationService.GoToLoginPage().Called(Count.Once()); + this.dialogService.ShowDialog(Arg.Any(), + Arg.Any(), + Arg.Any(), + Arg.Any()).Called(Count.Once()); } [Fact] public void HomePageViewModel_BackButtonCommand_Execute_UserSelectsNotToLogout_LoginPageDisplayed() { - this.dialogService.Setup(d => d.ShowDialog(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(false); + this.dialogService.ShowDialog(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(false); this.viewModel.BackButtonCommand.Execute(null); - this.navigationService.VerifyNoOtherCalls(); - this.dialogService.Verify(d => d.ShowDialog(It.IsAny(), - It.IsAny(), - It.IsAny(), - It.IsAny()), Times.Once); + this.navigationService.GoToLoginPage().Called(Count.Never()); + this.dialogService.ShowDialog(Arg.Any(), + Arg.Any(), + Arg.Any(), + Arg.Any()).Called(Count.Once()); } [Fact] @@ -73,7 +72,7 @@ public void HomePageViewModel_GoToTransactionsCommand_Execute_TransactionsPageDi { this.viewModel.GoToTransactionsCommand.Execute(null); - this.navigationService.Verify(n => n.GoToTransactions(), Times.Once); + this.navigationService.GoToTransactions().Called(Count.Once()); } [Fact] @@ -81,7 +80,7 @@ public void HomePageViewModel_GoToMobileTopupCommand_Execute_MobileTopupSelectOp { this.viewModel.GoToMobileTopupCommand.Execute(null); - this.navigationService.Verify(n => n.GoToMobileTopupSelectOperatorPage(), Times.Once); + this.navigationService.GoToMobileTopupSelectOperatorPage().Called(Count.Once()); } [Fact] @@ -89,7 +88,7 @@ public void HomePageViewModel_GoToBillPaymentCommand_Execute_BillPaymentSelectOp { this.viewModel.GoToBillPaymentCommand.Execute(null); - this.navigationService.Verify(n => n.GoToBillPaymentSelectOperatorPage(), Times.Once); + this.navigationService.GoToBillPaymentSelectOperatorPage().Called(Count.Once()); } [Fact] @@ -97,7 +96,7 @@ public void HomePageViewModel_GoToVoucherCommand_Execute_VoucherSelectOperatorPa { this.viewModel.GoToVoucherCommand.Execute(null); - this.navigationService.Verify(n => n.GoToVoucherSelectOperatorPage(), Times.Once); + this.navigationService.GoToVoucherSelectOperatorPage().Called(Count.Once()); } [Fact] @@ -105,13 +104,13 @@ public void HomePageViewModel_GoToAdminCommand_Execute_AdminPageDisplayed() { this.viewModel.GoToAdminCommand.Execute(null); - this.navigationService.Verify(n => n.GoToAdminPage(), Times.Once); + this.navigationService.GoToAdminPage().Called(Count.Once()); } [Fact] public async Task HomePageViewModel_Initialise_Balance_SetsBalanceFromCache() { - this.applicationCache.Setup(a => a.GetMerchantBalance()).Returns(123.45m); + this.applicationCache.GetMerchantBalance().Returns(123.45m); await this.viewModel.Initialise(CancellationToken.None); @@ -122,18 +121,17 @@ public async Task HomePageViewModel_Initialise_Balance_SetsBalanceFromCache() public void HomePageViewModel_BalanceChanged_Updates_Balance() { Action capturedHandler = null; - this.balanceRefresher.SetupAdd(b => b.BalanceChanged += It.IsAny>()) - .Callback>(h => capturedHandler = h); + this.balanceRefresher.BalanceChanged.OnSubscribe(h => capturedHandler = h); - var vm = new HomePageViewModel(this.applicationCache.Object, - this.dialogService.Object, - this.DeviceService.Object, - this.navigationService.Object, - this.navigationParameterService.Object, - this.balanceRefresher.Object); + var vm = new HomePageViewModel(this.applicationCache.Instance(), + this.dialogService.Instance(), + this.DeviceService.Instance(), + this.navigationService.Instance(), + this.navigationParameterService.Instance(), + this.balanceRefresher.Instance()); capturedHandler?.Invoke(200.00m); Assert.Equal("Balance: 200.00", vm.Balance); } -} \ No newline at end of file +} diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs index 76027cfd5..76d2d2374 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs @@ -1,6 +1,6 @@ using MediatR; using Microsoft.Extensions.Caching.Memory; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Logging; @@ -17,66 +17,64 @@ public class LoginPageViewModelTests { private LoginPageViewModel ViewModel; - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; - private Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; - private readonly Mock ApplicationInfoService; + private readonly IApplicationInfoServiceImposter ApplicationInfoService; - private readonly Mock ApplicationUpdateLauncherService; + private readonly IApplicationUpdateLauncherServiceImposter ApplicationUpdateLauncherService; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; - private readonly Mock UpdateService; + private readonly IUpdateServiceImposter UpdateService; - private readonly Mock BalanceRefresher; + private readonly IBalanceRefresherImposter BalanceRefresher; - private readonly Mock SentryService; + private readonly ISentryServiceImposter SentryService; + + private int warningToastCount; + private int informationToastCount; public LoginPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DeviceService = new Mock(); - this.ApplicationInfoService = new Mock(); - this.ApplicationUpdateLauncherService = new Mock(); - this.DialogService = new Mock(); - this.UpdateService = new Mock(); - this.BalanceRefresher = new Mock(); - this.SentryService = new Mock(); - - - this.ViewModel = new LoginPageViewModel(this.Mediator.Object, this.NavigationService.Object, this.ApplicationCache.Object, - this.DeviceService.Object, this.ApplicationInfoService.Object, - this.DialogService.Object, this.NavigationParameterService.Object, - this.UpdateService.Object, this.ApplicationUpdateLauncherService.Object, - this.BalanceRefresher.Object, this.SentryService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ApplicationInfoService = new IApplicationInfoServiceImposter(); + this.ApplicationUpdateLauncherService = new IApplicationUpdateLauncherServiceImposter(); + this.DialogService = new IDialogServiceImposter(); + this.UpdateService = new IUpdateServiceImposter(); + this.BalanceRefresher = new IBalanceRefresherImposter(); + this.SentryService = new ISentryServiceImposter(); + this.DialogService.ShowWarningToast(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(Task.CompletedTask) + .Callback((String _, Action? _, String? _, TimeSpan? _, CancellationToken _) => + { + this.warningToastCount++; + return Task.CompletedTask; + }); + this.DialogService.ShowInformationToast(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(Task.CompletedTask) + .Callback((String _, Action? _, String? _, TimeSpan? _, CancellationToken _) => + { + this.informationToastCount++; + return Task.CompletedTask; + }); + + this.ViewModel = new LoginPageViewModel(this.Mediator.Instance(), this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DeviceService.Instance(), this.ApplicationInfoService.Instance(), + this.DialogService.Instance(), this.NavigationParameterService.Instance(), + this.UpdateService.Instance(), this.ApplicationUpdateLauncherService.Instance(), + this.BalanceRefresher.Instance(), this.SentryService.Instance()); Logger.Initialise(new Logging.NullLogger()); } - - [Fact] - public void LoginPageViewModel_LoginCommand_Execute_IsExecuted() - { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new Configuration())); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); - - this.ViewModel.LogonCommand.Execute(null); - - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); - } [Theory] [InlineData(null)] @@ -84,104 +82,96 @@ public void LoginPageViewModel_LoginCommand_Execute_IsExecuted() [InlineData("http://localhost")] public void LoginPageViewModel_LoginCommand_Execute_ConfigUrlSet_IsExecuted(String configUrl) { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new Configuration())); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new Configuration())); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); this.ViewModel.ConfigHostUrl = configUrl; this.ViewModel.LogonCommand.Execute(null); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToHome().Called(Count.Once()); if (String.IsNullOrEmpty(configUrl) == false){ - this.ApplicationCache.Verify(v => v.SetConfigHostUrl(It.IsAny(), It.IsAny()), Times.Once); + this.ApplicationCache.SetConfigHostUrl(Arg.Any(), Arg.Any()).Called(Count.Once()); } } [Fact] public void LoginPageViewModel_LoginCommand_Execute_ErrorGettingConfig_WarningToastIsShown() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure("Error")); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Failure("Error")); this.ViewModel.LogonCommand.Execute(null); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Never); - this.NavigationService.Verify(n => n.GoToHome(), Times.Never); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Never()); + this.NavigationService.GoToHome().Called(Count.Never()); - this.DialogService.Verify(n => n.ShowWarningToast(It.IsAny(), - null, - "OK", - null, - CancellationToken.None), Times.Once); + this.warningToastCount.ShouldBe(1); } [Fact] public void LoginPageViewModel_LoginCommand_Execute_ErrorGettingToken_WarningToastIsShown() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new Configuration())); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure("Error")); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new Configuration())); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Failure("Error")); this.ViewModel.LogonCommand.Execute(null); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Never); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Never); - this.NavigationService.Verify(n => n.GoToHome(), Times.Never); - - this.DialogService.Verify(n => n.ShowWarningToast(It.IsAny(), - null, - "OK", - null, - CancellationToken.None), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Never()); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Never()); + this.NavigationService.GoToHome().Called(Count.Never()); + + this.warningToastCount.ShouldBe(1); } [Fact] public async Task LoginPageViewModel_LoginCommand_Execute_UpdateCheckFails_LogonContinues() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())) + this.Mediator.Send(Arg>>.Any(), Arg.Any()) .ReturnsAsync(Result.Success(new Configuration { EnableAutoUpdates = true })); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantBalance)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); - - this.ApplicationInfoService.Setup(a => a.VersionString).Returns(TestData.ApplicationVersion); - this.ApplicationInfoService.Setup(a => a.PackageName).Returns("com.transactionprocessor.mobile"); - this.DeviceService.Setup(d => d.GetPlatform()).Returns("Android"); - this.DeviceService.Setup(d => d.GetIdentifier()).Returns(TestData.DeviceIdentifier); - this.UpdateService.Setup(u => u.CheckForUpdates(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantBalance)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + + this.ApplicationInfoService.VersionString.Getter().Returns(TestData.ApplicationVersion); + this.ApplicationInfoService.PackageName.Getter().Returns("com.transactionprocessor.mobile"); + this.DeviceService.GetPlatform().Returns("Android"); + this.DeviceService.GetIdentifier().Returns(TestData.DeviceIdentifier); + this.UpdateService.CheckForUpdates(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Failure("Update check failed")); await this.ViewModel.LogonCommand.ExecuteAsync(null); - this.UpdateService.Verify(u => u.CheckForUpdates(TestData.ApplicationVersion, + this.UpdateService.CheckForUpdates(TestData.ApplicationVersion, "com.transactionprocessor.mobile", "Android", TestData.DeviceIdentifier, - It.IsAny()), Times.Once); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToHome().Called(Count.Once()); } [Fact] public async Task LoginPageViewModel_LoginCommand_Execute_UpdateRequired_UpdateLauncherIsCalled_And_AppQuits() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())) + this.Mediator.Send(Arg>>.Any(), Arg.Any()) .ReturnsAsync(Result.Success(new Configuration { EnableAutoUpdates = true })); - this.ApplicationInfoService.Setup(a => a.VersionString).Returns(TestData.ApplicationVersion); - this.ApplicationInfoService.Setup(a => a.PackageName).Returns("com.transactionprocessor.mobile"); - this.DeviceService.Setup(d => d.GetPlatform()).Returns("Android"); - this.DeviceService.Setup(d => d.GetIdentifier()).Returns(TestData.DeviceIdentifier); - this.UpdateService.Setup(u => u.CheckForUpdates(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + this.ApplicationInfoService.VersionString.Getter().Returns(TestData.ApplicationVersion); + this.ApplicationInfoService.PackageName.Getter().Returns("com.transactionprocessor.mobile"); + this.DeviceService.GetPlatform().Returns("Android"); + this.DeviceService.GetIdentifier().Returns(TestData.DeviceIdentifier); + this.UpdateService.CheckForUpdates(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) .ReturnsAsync(Result.Success(new ApplicationUpdateCheckResponse { DownloadUri = "https://updates.example.com/transactionmobile.apk", @@ -189,129 +179,81 @@ public async Task LoginPageViewModel_LoginCommand_Execute_UpdateRequired_UpdateL Message = "Install update", UpdateRequired = true })); - this.DialogService.Setup(d => d.ShowDialog(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); + this.DialogService.ShowDialog(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(true); await this.ViewModel.LogonCommand.ExecuteAsync(null); - this.DialogService.Verify(d => d.ShowInformationToast("Downloading the required update...", - null, - "OK", - null, - CancellationToken.None), Times.Once); - this.ApplicationUpdateLauncherService.Verify(l => l.LaunchUpdateAsync("https://updates.example.com/transactionmobile.apk", It.IsAny()), Times.Once); - this.NavigationService.Verify(n => n.QuitApplication(), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Never); - this.NavigationService.Verify(n => n.GoToHome(), Times.Never); - this.DialogService.Verify(n => n.ShowWarningToast(It.IsAny(), - null, - "OK", - null, - CancellationToken.None), Times.Never); - } - - [Fact] - public async Task LoginPageViewModel_LoginCommand_Execute_UpdateLauncherFails_WarningToastIsShown_And_AppStaysOpen() - { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(new Configuration { EnableAutoUpdates = true })); - this.ApplicationInfoService.Setup(a => a.VersionString).Returns(TestData.ApplicationVersion); - this.ApplicationInfoService.Setup(a => a.PackageName).Returns("com.transactionprocessor.mobile"); - this.DeviceService.Setup(d => d.GetPlatform()).Returns("Android"); - this.DeviceService.Setup(d => d.GetIdentifier()).Returns(TestData.DeviceIdentifier); - this.UpdateService.Setup(u => u.CheckForUpdates(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(new ApplicationUpdateCheckResponse - { - DownloadUri = "https://updates.example.com/transactionmobile.apk", - LatestVersion = "1.0.1", - Message = "Install update", - UpdateRequired = true - })); - this.DialogService.Setup(d => d.ShowDialog(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(true); - this.ApplicationUpdateLauncherService.Setup(l => l.LaunchUpdateAsync(It.IsAny(), It.IsAny())) - .ThrowsAsync(new ApplicationException("Unable to start the application update installer.")); - - await this.ViewModel.LogonCommand.ExecuteAsync(null); - - this.NavigationService.Verify(n => n.QuitApplication(), Times.Never); - this.NavigationService.Verify(n => n.GoToHome(), Times.Never); - this.DialogService.Verify(d => d.ShowWarningToast("Unable to start the application update installer.", - null, - "OK", - null, - CancellationToken.None), Times.Once); + this.informationToastCount.ShouldBe(1); + this.ApplicationUpdateLauncherService.LaunchUpdateAsync("https://updates.example.com/transactionmobile.apk", Arg.Any()).Called(Count.Once()); + this.NavigationService.QuitApplication().Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Never()); + this.NavigationService.GoToHome().Called(Count.Never()); + this.warningToastCount.ShouldBe(0); } [Fact] public void LoginPageViewModel_LoginCommand_Execute_ErrorDuringLogonTransaction_WarningToastIsShown() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new Configuration())); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure("")); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new Configuration())); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Failure("")); this.ViewModel.LogonCommand.Execute(null); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Never); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Never()); - this.NavigationService.Verify(n => n.GoToHome(), Times.Never); + this.NavigationService.GoToHome().Called(Count.Never()); - this.DialogService.Verify(n => n.ShowWarningToast(It.IsAny(), - null, - "OK", - null, - CancellationToken.None), Times.Once); + this.warningToastCount.ShouldBe(1); } [Fact] public void LoginPageViewModel_LoginCommand_Execute_ErrorDuringGetContractProducts_WarningToastIsShown() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new Configuration())); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Failure("")); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new Configuration())); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Failure("")); this.ViewModel.LogonCommand.Execute(null); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(n => n.GoToHome(), Times.Never); - - this.DialogService.Verify(n => n.ShowWarningToast(It.IsAny(), - null, - "OK", - null, - CancellationToken.None), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToHome().Called(Count.Never()); + + this.warningToastCount.ShouldBe(1); } [Fact] public void LoginPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.QuitApplication(), Times.Once); + this.NavigationService.QuitApplication().Called(Count.Once()); } [Fact] public async Task LoginPageViewModel_LoginCommand_Execute_SentryInitialisedWithDsnFromConfiguration() { String sentryDsn = "https://key@sentry.io/123"; - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())) + this.Mediator.Send(Arg>>.Any(), Arg.Any()) .ReturnsAsync(Result.Success(new Configuration { SentryDsn = sentryDsn })); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.AccessToken)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.AccessToken)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformLogonResponseModel)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); await this.ViewModel.LogonCommand.ExecuteAsync(null); - this.SentryService.Verify(s => s.InitializeSentry(sentryDsn), Times.Once); + this.SentryService.InitializeSentry(sentryDsn).Called(Count.Once()); } [Fact] public void LoginPageViewModel_PropertyTests_ValuesAreAsExpected(){ - this.DeviceService.Setup(d => d.GetIdentifier()).Returns("testidentifier"); + this.DeviceService.GetIdentifier().Returns("testidentifier"); this.ViewModel.Password = TestData.Password; this.ViewModel.UserName = TestData.UserName; diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountAddressPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountAddressPageViewModelTests.cs index 27856d8c5..7d5c1d347 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountAddressPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountAddressPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -13,39 +13,39 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.MyAccou [Collection("ViewModelTests")] public class MyAccountAddressPageViewModelTests { - private readonly Mock NavigationService; - private Mock NavigationParameterService; - private readonly Mock ApplicationCache; - private readonly Mock DialogService; - private readonly Mock Mediator; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogService; + private readonly IMediatorImposter Mediator; private readonly MyAccountAddressPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public MyAccountAddressPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.Mediator = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new MyAccountAddressPageViewModel(this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.Mediator.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.Mediator = new IMediatorImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new MyAccountAddressPageViewModel(this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.Mediator.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task MyAccountAddressPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Address.ShouldNotBeNull(); this.ViewModel.Address.AddressLine1.ShouldBe(TestData.AddressLine1); this.ViewModel.Address.AddressLine2.ShouldBe(TestData.AddressLine2); @@ -61,6 +61,6 @@ public async Task MyAccountAddressPageViewModel_BackButtonCommand_PreviousPageIs { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountContactPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountContactPageViewModelTests.cs index b5e00e769..d2227a3cf 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountContactPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountContactPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -13,41 +13,41 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.MyAccou [Collection("ViewModelTests")] public class MyAccountContactPageViewModelTests { - private readonly Mock NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; private readonly MyAccountContactPageViewModel ViewModel; - private readonly Mock DeviceService; - private readonly Mock Mediator; + private readonly IDeviceServiceImposter DeviceService; + private readonly IMediatorImposter Mediator; public MyAccountContactPageViewModelTests() { - this.NavigationService = new Mock(); - this.ApplicationCache = new Mock(); - this.NavigationParameterService = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.Mediator = new Mock(); + this.NavigationService = new INavigationServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.Mediator = new IMediatorImposter(); - this.ViewModel = new MyAccountContactPageViewModel(this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, this.DeviceService.Object, - this.NavigationParameterService.Object, - this.Mediator.Object); + this.ViewModel = new MyAccountContactPageViewModel(this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), this.DeviceService.Instance(), + this.NavigationParameterService.Instance(), + this.Mediator.Instance()); } [Fact] public async Task MyAccountContactPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Contact.ShouldNotBeNull(); this.ViewModel.Contact.EmailAddress.ShouldBe(TestData.ContactEmailAddress); this.ViewModel.Contact.Name.ShouldBe(TestData.ContactName); @@ -59,6 +59,6 @@ public async Task MyAccountContactPageViewModel_BackButtonCommand_PreviousPageIs { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountDetailsPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountDetailsPageViewModelTests.cs index c23741b8a..e65ec0409 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountDetailsPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountDetailsPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -13,43 +13,43 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.MyAccou [Collection("ViewModelTests")] public class MyAccountDetailsPageViewModelTests { - private readonly Mock NavigationService; - private Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; private readonly MyAccountDetailsPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; public MyAccountDetailsPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.Mediator = new Mock(); - this.ViewModel = new MyAccountDetailsPageViewModel(this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object, - this.Mediator.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.Mediator = new IMediatorImposter(); + this.ViewModel = new MyAccountDetailsPageViewModel(this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance(), + this.Mediator.Instance()); } [Fact] public async Task MyAccountDetailsPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Balance.ShouldBe(TestData.Balance); this.ViewModel.AvailableBalance.ShouldBe(TestData.AvailableBalance); this.ViewModel.MerchantName.ShouldBe(TestData.MerchantName); @@ -63,6 +63,6 @@ public async Task MyAccountDetailsPageViewModel_BackButtonCommand_PreviousPageIs { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountPageViewModelTests.cs index fc38d32f3..742ec3534 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/MyAccount/MyAccountPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -16,40 +16,40 @@ public class MyAccountPageViewModelTests { #region Methods - private readonly Mock NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; - private readonly Mock Mediator; - private readonly Mock ApplicationThemeService; + private readonly IMediatorImposter Mediator; + private readonly IApplicationThemeServiceImposter ApplicationThemeService; private readonly MyAccountPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public MyAccountPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.Mediator = new Mock(); - this.ApplicationThemeService = new Mock(); - this.ViewModel = new MyAccountPageViewModel(this.NavigationService.Object, this.ApplicationCache.Object, - this.DialogService.Object, this.DeviceService.Object, - this.ApplicationThemeService.Object, - this.Mediator.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.Mediator = new IMediatorImposter(); + this.ApplicationThemeService = new IApplicationThemeServiceImposter(); + this.ViewModel = new MyAccountPageViewModel(this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DialogService.Instance(), this.DeviceService.Instance(), + this.ApplicationThemeService.Instance(), + this.Mediator.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task MyAccountPageViewModel_Initialise_IsInitialised() { - this.ApplicationThemeService.Setup(s => s.GetDarkThemeEnabled()).ReturnsAsync(true); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success( TestData.MerchantDetailsModel)); - this.ApplicationCache.Setup(a => a.GetLastLoginDate()).Returns(DateTime.Now); + this.ApplicationThemeService.GetDarkThemeEnabled().ReturnsAsync(true); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success( TestData.MerchantDetailsModel)); + this.ApplicationCache.GetLastLoginDate().Returns(DateTime.Now); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.MerchantName.ShouldBe(TestData.MerchantDetailsModel.MerchantName); @@ -59,15 +59,15 @@ public async Task MyAccountPageViewModel_Initialise_IsInitialised() { [Fact] public async Task MyAccountPageViewModel_Initialise_WhenMerchantDetailsAreCached_UsesCachedMerchantDetails() { - this.ApplicationCache.Setup(a => a.GetMerchantDetails()).Returns(TestData.MerchantDetailsModel); - this.ApplicationCache.Setup(a => a.GetLastLoginDate()).Returns(DateTime.Now); - this.ApplicationThemeService.Setup(s => s.GetDarkThemeEnabled()).ReturnsAsync(false); - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); + this.ApplicationCache.GetMerchantDetails().Returns(TestData.MerchantDetailsModel); + this.ApplicationCache.GetLastLoginDate().Returns(DateTime.Now); + this.ApplicationThemeService.GetDarkThemeEnabled().ReturnsAsync(false); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.MerchantDetailsModel)); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.MerchantName.ShouldBe(TestData.MerchantDetailsModel.MerchantName); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Never); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Never()); } [Fact] @@ -75,35 +75,35 @@ public async Task MyAccountPageViewModel_SetDarkTheme_ThemeStoredAndPropertyUpda await this.ViewModel.SetDarkTheme(true); this.ViewModel.IsDarkThemeEnabled.ShouldBeTrue(); - this.ApplicationThemeService.Verify(s => s.SetDarkTheme(true), Times.Once); + this.ApplicationThemeService.SetDarkTheme(true).Called(Count.Once()); } [Fact] public void MyAccountPageViewModel_OptionSelectedCommand_AccountInfo_Execute_IsExecuted() { this.ViewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.AccountInfo)); - this.NavigationService.Verify(n => n.GoToMyAccountDetails(), Times.Once); + this.NavigationService.GoToMyAccountDetails().Called(Count.Once()); } [Fact] public void MyAccountPageViewModel_OptionSelectedCommand_Addresses_Execute_IsExecuted() { this.ViewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.Addresses)); - this.NavigationService.Verify(n => n.GoToMyAccountAddresses(), Times.Once); + this.NavigationService.GoToMyAccountAddresses().Called(Count.Once()); } [Fact] public void MyAccountPageViewModel_OptionSelectedCommand_Contacts_Execute_IsExecuted() { this.ViewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.Contacts)); - this.NavigationService.Verify(n => n.GoToMyAccountContacts(), Times.Once); + this.NavigationService.GoToMyAccountContacts().Called(Count.Once()); } [Fact] public void MyAccountPageViewModel_OptionSelectedCommand_Logout_Execute_IsExecuted() { this.ViewModel.OptionSelectedCommand.Execute(this.CreateItemSelected(MyAccountPageViewModel.AccountOptions.Logout)); - this.NavigationService.Verify(n => n.GoToLoginPage(), Times.Once); + this.NavigationService.GoToLoginPage().Called(Count.Once()); } [Fact] @@ -111,7 +111,7 @@ public void MyAccountPageViewModel_OptionSelectedCommand_Unsupported_Execute_IsE { this.ViewModel.OptionSelectedCommand.Execute(this.CreateItemSelected((MyAccountPageViewModel.AccountOptions)99)); - this.NavigationService.Verify(n => n.GoToMyAccountDetails(), Times.Never); + this.NavigationService.GoToMyAccountDetails().Called(Count.Never()); } [Fact] @@ -130,7 +130,7 @@ public async Task MyAccountPageViewModel_BackButtonCommand_HomePageIsShown() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n=> n.GoToHome(),Times.Once); + this.NavigationService.GoToHome().Called(Count.Once()); } private ItemSelected CreateItemSelected(MyAccountPageViewModel.AccountOptions selectedOption) { diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/DailyPerformanceSummaryPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/DailyPerformanceSummaryPageViewModelTests.cs index 49a249f07..17aa6acbe 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/DailyPerformanceSummaryPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/DailyPerformanceSummaryPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using SimpleResults; using Shouldly; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -13,32 +13,32 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Reports public class DailyPerformanceSummaryPageViewModelTests { - private readonly Mock Mediator; - private readonly Mock NavigationService; - private readonly Mock ApplicationCache; - private readonly Mock DialogService; - private readonly Mock DeviceService; - private readonly Mock NavigationParameterService; + private readonly IMediatorImposter Mediator; + private readonly INavigationServiceImposter NavigationService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogService; + private readonly IDeviceServiceImposter DeviceService; + private readonly INavigationParameterServiceImposter NavigationParameterService; private readonly DailyPerformanceSummaryPageViewModel ViewModel; public DailyPerformanceSummaryPageViewModelTests() { - this.Mediator = new Mock(); + this.Mediator = new IMediatorImposter(); this.Mediator - .Setup(m => m.Send(It.IsAny(), It.IsAny())) + .Send(Arg>>.Any(), Arg.Any()) .ReturnsAsync(Result.Success(DailyPerformanceSummaryModel.CreateMock(PerformanceSummaryPeriod.Today))); - this.NavigationService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.NavigationParameterService = new Mock(); + this.NavigationService = new INavigationServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); - this.ViewModel = new DailyPerformanceSummaryPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.ViewModel = new DailyPerformanceSummaryPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReceiptDetailPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReceiptDetailPageViewModelTests.cs index acdbfe820..7d4cd56fd 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReceiptDetailPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReceiptDetailPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -10,28 +10,28 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Reports public class RecentActivityReceiptDetailPageViewModelTests { - private readonly Mock NavigationService; - private readonly Mock ApplicationCache; - private readonly Mock DialogService; - private readonly Mock DeviceService; - private readonly Mock NavigationParameterService; - private readonly Mock ReportsService; + private readonly INavigationServiceImposter NavigationService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogService; + private readonly IDeviceServiceImposter DeviceService; + private readonly INavigationParameterServiceImposter NavigationParameterService; + private readonly IReportsServiceImposter ReportsService; private readonly RecentActivityReceiptDetailPageViewModel ViewModel; public RecentActivityReceiptDetailPageViewModelTests() { - this.NavigationService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ReportsService = new Mock(); - this.ViewModel = new RecentActivityReceiptDetailPageViewModel(this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object, - this.ReportsService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ReportsService = new IReportsServiceImposter(); + this.ViewModel = new RecentActivityReceiptDetailPageViewModel(this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance(), + this.ReportsService.Instance()); } [Fact] @@ -46,7 +46,7 @@ public async Task Initialise_LoadsSelectedItemFromNavigationParameters() new DateTime(2026, 7, 6, 9, 30, 0), "RCPT-10001"); - this.NavigationParameterService.Setup(p => p.GetParameters()).Returns(new Dictionary + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(RecentActivityReceiptItemModel), item } }); @@ -70,7 +70,7 @@ public async Task ResendReceiptCommand_SendsReceiptAndShowsSuccessMessage() new DateTime(2026, 7, 6, 9, 30, 0), "RCPT-10001"); - this.NavigationParameterService.Setup(p => p.GetParameters()).Returns(new Dictionary + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(RecentActivityReceiptItemModel), item } }); @@ -78,9 +78,9 @@ public async Task ResendReceiptCommand_SendsReceiptAndShowsSuccessMessage() await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.EmailAddress = "customer@example.com"; - this.ReportsService.Setup(r => r.ResendRecentActivityReceipt("TXN-10001", + this.ReportsService.ResendRecentActivityReceipt("TXN-10001", "customer@example.com", - It.IsAny())) + Arg.Any()) .ReturnsAsync(Result.Success(new RecentActivityReceiptResendResultModel { Success = true, @@ -90,11 +90,10 @@ public async Task ResendReceiptCommand_SendsReceiptAndShowsSuccessMessage() await this.ViewModel.ResendReceiptCommand.ExecuteAsync(null); - this.ReportsService.Verify(r => r.ResendRecentActivityReceipt("TXN-10001", + this.ReportsService.ResendRecentActivityReceipt("TXN-10001", "customer@example.com", - It.IsAny()), - Times.Once); - this.DialogService.Verify(d => d.ShowSuccessToast("Receipt resend requested. Sent to customer@example.com.", null, "OK", null, It.IsAny()), Times.Once); + Arg.Any()).Called(Count.Once()); + this.DialogService.ShowSuccessToast("Receipt resend requested. Sent to customer@example.com.", Arg.Any(), "OK", Arg.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.EmailAddress.ShouldBe(string.Empty); } @@ -110,7 +109,7 @@ public async Task ResendReceiptCommand_ShowsWarningForInvalidEmail() new DateTime(2026, 7, 6, 9, 30, 0), "RCPT-10001"); - this.NavigationParameterService.Setup(p => p.GetParameters()).Returns(new Dictionary + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(RecentActivityReceiptItemModel), item } }); @@ -121,7 +120,7 @@ public async Task ResendReceiptCommand_ShowsWarningForInvalidEmail() await this.ViewModel.ResendReceiptCommand.ExecuteAsync(null); - this.DialogService.Verify(d => d.ShowWarningToast("Enter a valid email address before resending the receipt.", null, "OK", null, It.IsAny()), Times.Once); + this.DialogService.ShowWarningToast("Enter a valid email address before resending the receipt.", Arg.Any(), "OK", Arg.Any(), Arg.Any()).Called(Count.Once()); } [Fact] @@ -136,7 +135,7 @@ public async Task ResendReceiptCommand_ShowsWarningWhenApiFails() new DateTime(2026, 7, 6, 9, 30, 0), "RCPT-10001"); - this.NavigationParameterService.Setup(p => p.GetParameters()).Returns(new Dictionary + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(RecentActivityReceiptItemModel), item } }); @@ -144,13 +143,13 @@ public async Task ResendReceiptCommand_ShowsWarningWhenApiFails() await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.EmailAddress = "customer@example.com"; - this.ReportsService.Setup(r => r.ResendRecentActivityReceipt("TXN-10001", + this.ReportsService.ResendRecentActivityReceipt("TXN-10001", "customer@example.com", - It.IsAny())) + Arg.Any()) .ReturnsAsync(Result.Failure("Receipt resend failed.")); await this.ViewModel.ResendReceiptCommand.ExecuteAsync(null); - this.DialogService.Verify(d => d.ShowWarningToast("Receipt resend failed.", null, "OK", null, It.IsAny()), Times.Once); + this.DialogService.ShowWarningToast("Receipt resend failed.", Arg.Any(), "OK", Arg.Any(), Arg.Any()).Called(Count.Once()); } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReportPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReportPageViewModelTests.cs index ae6b634c0..d464a4e57 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReportPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/RecentActivityReportPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -13,29 +13,29 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Reports public class RecentActivityReportPageViewModelTests { - private readonly Mock Mediator; - private readonly Mock NavigationService; - private readonly Mock ApplicationCache; - private readonly Mock DialogService; - private readonly Mock DeviceService; - private readonly Mock NavigationParameterService; + private readonly IMediatorImposter Mediator; + private readonly INavigationServiceImposter NavigationService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogService; + private readonly IDeviceServiceImposter DeviceService; + private readonly INavigationParameterServiceImposter NavigationParameterService; private readonly RecentActivityReportPageViewModel ViewModel; public RecentActivityReportPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.NavigationParameterService = new Mock(); - - this.ViewModel = new RecentActivityReportPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + + this.ViewModel = new RecentActivityReportPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] @@ -43,7 +43,7 @@ public async Task Initialise_LoadsMockedResultsForToday() { DateTime reportDate = new(2026, 7, 6); this.Mediator - .Setup(m => m.Send(It.Is(q => q.ReportDate == reportDate && q.SearchText == null && q.PageNumber == 1 && q.PageSize == 5), It.IsAny())) + .Send(Arg>>.Is(q => ((ReportQueries.GetRecentActivityReceiptReportQuery)q).ReportDate == reportDate && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).SearchText == null && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageNumber == 1 && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageSize == 5), Arg.Any()) .ReturnsAsync(Result.Success(RecentActivityReceiptReportModel.CreateMock(reportDate, null))); this.ViewModel.SelectedDate = reportDate; @@ -60,7 +60,7 @@ public async Task SearchCommand_UsesSelectedDateAndSearchText() { DateTime reportDate = new(2026, 7, 6); this.Mediator - .Setup(m => m.Send(It.Is(q => q.ReportDate == reportDate && q.SearchText == "TXN-10001" && q.PageNumber == 1 && q.PageSize == 5), It.IsAny())) + .Send(Arg>>.Is(q => ((ReportQueries.GetRecentActivityReceiptReportQuery)q).ReportDate == reportDate && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).SearchText == "TXN-10001" && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageNumber == 1 && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageSize == 5), Arg.Any()) .ReturnsAsync(Result.Success(RecentActivityReceiptReportModel.CreateMock(reportDate, "TXN-10001"))); this.ViewModel.SelectedDate = reportDate; @@ -69,7 +69,8 @@ public async Task SearchCommand_UsesSelectedDateAndSearchText() await this.ViewModel.SearchCommand.ExecuteAsync(null); this.ViewModel.Items.ShouldContain(item => item.Reference == "TXN-10001"); - this.Mediator.VerifyAll(); + this.Mediator.Send(Arg>>.Is(q => ((ReportQueries.GetRecentActivityReceiptReportQuery)q).ReportDate == reportDate && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).SearchText == "TXN-10001" && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageNumber == 1 && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageSize == 5), Arg.Any()) + .Called(Count.Once()); } [Fact] @@ -77,10 +78,10 @@ public async Task NextPageCommand_RequestsTheNextPage() { DateTime reportDate = new(2026, 7, 6); this.Mediator - .Setup(m => m.Send(It.Is(q => q.ReportDate == reportDate && q.PageNumber == 1 && q.PageSize == 5), It.IsAny())) + .Send(Arg>>.Is(q => ((ReportQueries.GetRecentActivityReceiptReportQuery)q).ReportDate == reportDate && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageNumber == 1 && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageSize == 5), Arg.Any()) .ReturnsAsync(Result.Success(RecentActivityReceiptReportModel.CreateMock(reportDate, null, 1, 5))); this.Mediator - .Setup(m => m.Send(It.Is(q => q.ReportDate == reportDate && q.PageNumber == 2 && q.PageSize == 5), It.IsAny())) + .Send(Arg>>.Is(q => ((ReportQueries.GetRecentActivityReceiptReportQuery)q).ReportDate == reportDate && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageNumber == 2 && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageSize == 5), Arg.Any()) .ReturnsAsync(Result.Success(RecentActivityReceiptReportModel.CreateMock(reportDate, null, 2, 5))); this.ViewModel.SelectedDate = reportDate; @@ -90,6 +91,6 @@ public async Task NextPageCommand_RequestsTheNextPage() this.ViewModel.PageNumber.ShouldBe(2); this.ViewModel.Items.ShouldAllBe(item => item.TransactionDateTime.Date == reportDate); - this.Mediator.Verify(m => m.Send(It.Is(q => q.PageNumber == 2 && q.PageSize == 5), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>.Is(q => ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageNumber == 2 && ((ReportQueries.GetRecentActivityReceiptReportQuery)q).PageSize == 5), Arg.Any()).Called(Count.Once()); } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/ReportsPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/ReportsPageViewModelTests.cs index d8e0c9333..89e3641f3 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/ReportsPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/ReportsPageViewModelTests.cs @@ -1,6 +1,6 @@ -using LiveChartsCore.Measure; +using LiveChartsCore.Measure; using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using TransactionProcessor.Mobile.BusinessLogic.Common; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -12,29 +12,29 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Reports { public class ReportsPageViewModelTests { - private readonly Mock NavigationService; - private readonly Mock NavigationParameterService; - private readonly Mock ApplicationCache; - private readonly Mock DialogService; - private readonly Mock DeviceService; - private readonly Mock Mediator; + private readonly INavigationServiceImposter NavigationService; + private readonly INavigationParameterServiceImposter NavigationParameterService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogService; + private readonly IDeviceServiceImposter DeviceService; + private readonly IMediatorImposter Mediator; private readonly ReportsPageViewModel ViewModel; public ReportsPageViewModelTests(){ - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.Mediator = new Mock(); - - this.ViewModel = new ReportsPageViewModel(this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.Mediator.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.Mediator = new IMediatorImposter(); + + this.ViewModel = new ReportsPageViewModel(this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.Mediator.Instance(), + this.NavigationParameterService.Instance()); } [Theory] @@ -54,10 +54,10 @@ public async Task ReportsPageViewModel_OptionSelectedCommand_Execute_IsExecuted( switch(selectedIndex){ case 0: - this.NavigationService.Verify(v => v.GoToDailyPerformanceSummaryPage(), Times.Once); + this.NavigationService.GoToDailyPerformanceSummaryPage().Called(Count.Once()); break; default: - this.NavigationService.Verify(v => v.GoToDailyPerformanceSummaryPage(), Times.Never); + this.NavigationService.GoToDailyPerformanceSummaryPage().Called(Count.Never()); break; } } @@ -80,7 +80,7 @@ public async Task ReportsPageViewModel_TransactionMixCommand_Execute_IsExecuted( this.ViewModel.OptionSelectedCommand.Execute(itemSelected); - this.NavigationService.Verify(v => v.GoToTransactionMixSummaryPage(), Times.Once); + this.NavigationService.GoToTransactionMixSummaryPage().Called(Count.Once()); } [Fact] @@ -94,7 +94,7 @@ public async Task ReportsPageViewModel_RecentActivityCommand_Execute_IsExecuted( this.ViewModel.OptionSelectedCommand.Execute(itemSelected); - this.NavigationService.Verify(v => v.GoToRecentActivityReportPage(), Times.Once); + this.NavigationService.GoToRecentActivityReportPage().Called(Count.Once()); } [Fact] @@ -102,7 +102,7 @@ public async Task ReportsPageViewModel_BackButtonCommand_HomePageIsShown() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + this.NavigationService.GoToHome().Called(Count.Once()); } } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/TransactionMixPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/TransactionMixPageViewModelTests.cs index ab8a04d42..c987d93f1 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/TransactionMixPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Reports/TransactionMixPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -13,36 +13,36 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Reports public class TransactionMixPageViewModelTests { - private readonly Mock Mediator; - private readonly Mock NavigationService; - private readonly Mock ApplicationCache; - private readonly Mock DialogService; - private readonly Mock DeviceService; - private readonly Mock NavigationParameterService; + private readonly IMediatorImposter Mediator; + private readonly INavigationServiceImposter NavigationService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogService; + private readonly IDeviceServiceImposter DeviceService; + private readonly INavigationParameterServiceImposter NavigationParameterService; private readonly TransactionMixPageViewModel ViewModel; public TransactionMixPageViewModelTests() { - this.Mediator = new Mock(); + this.Mediator = new IMediatorImposter(); this.Mediator - .Setup(m => m.Send(It.IsAny(), It.IsAny())) + .Send(Arg>>.Any(), Arg.Any()) .ReturnsAsync(Result.Success(TransactionMixSummaryModel.CreateMock( merchantReportingId: 12345, breakdown: TransactionMixBreakdown.TransactionType, measure: TransactionMixMeasure.Count))); - this.NavigationService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.NavigationParameterService = new Mock(); + this.NavigationService = new INavigationServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); - this.ViewModel = new TransactionMixPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.ViewModel = new TransactionMixPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/SupportPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/SupportPageViewModelTests.cs index bf2c98079..25e9b6c69 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/SupportPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/SupportPageViewModelTests.cs @@ -1,6 +1,6 @@ -using System.Text; +using System.Text; using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Database; @@ -14,51 +14,52 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Support [Collection("ViewModelTests")] public class SupportPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock DatabaseContext; + private readonly IDatabaseContextImposter DatabaseContext; - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; - private readonly Mock ApplicationInfoService; + private readonly IApplicationInfoServiceImposter ApplicationInfoService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; private readonly SupportPageViewModel ViewModel; public SupportPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.DatabaseContext = new Mock(); - this.Mediator = new Mock(); - this.DeviceService = new Mock(); - this.ApplicationInfoService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.ViewModel = new SupportPageViewModel(this.DeviceService.Object, - this.ApplicationInfoService.Object, - this.DatabaseContext.Object, - this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.DatabaseContext = new IDatabaseContextImposter(); + this.Mediator = new IMediatorImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ApplicationInfoService = new IApplicationInfoServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DialogService.ShowUploadLogsCompleteNotice().Returns(Task.CompletedTask); + this.ViewModel = new SupportPageViewModel(this.DeviceService.Instance(), + this.ApplicationInfoService.Instance(), + this.DatabaseContext.Instance(), + this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task SupportPageViewModel_UploadLogsCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success()); + this.Mediator.Send(Arg>.Any(), Arg.Any()).ReturnsAsync(Result.Success()); await this.ViewModel.UploadLogsCommand.ExecuteAsync(null); - this.Mediator.Verify(m => m.Send(It.IsAny(),It.IsAny()),Times.Once); - this.DialogService.Verify(d => d.ShowUploadLogsCompleteNotice(), Times.Once); - this.NavigationService.Verify(n => n.GoBack(), Times.Never); + this.Mediator.Send(Arg>.Any(), Arg.Any()).Called(Count.Once()); + this.DialogService.ShowUploadLogsCompleteNotice().Called(Count.Once()); + this.NavigationService.GoBack().Called(Count.Never()); } [Fact] @@ -66,14 +67,14 @@ public void SupportPageViewModel_ViewLogsCommand_Execute_IsExecuted() { this.ViewModel.ViewLogsCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToViewLogsPage(), Times.Once); + this.NavigationService.GoToViewLogsPage().Called(Count.Once()); } [Fact] public void SupportPageViewModel_Platform_ValueIsReturned(){ - this.DeviceService.Setup(d => d.GetPlatform()).Returns("Platform"); - this.DeviceService.Setup(d => d.GetManufacturer()).Returns("Manufacturer"); - this.DeviceService.Setup(d => d.GetModel()).Returns("Model"); + this.DeviceService.GetPlatform().Returns("Platform"); + this.DeviceService.GetManufacturer().Returns("Manufacturer"); + this.DeviceService.GetModel().Returns("Model"); String platform = this.ViewModel.Platform; @@ -88,7 +89,7 @@ public void SupportPageViewModel_Platform_ValueIsReturned(){ [Fact] public void SupportPageViewModel_NumberTransactionsStored_ValueIsReturned() { - this.DatabaseContext.Setup(d => d.GetTransactions(It.IsAny())).ReturnsAsync(new List{ + this.DatabaseContext.GetTransactions(Arg.Any()).ReturnsAsync(new List{ new TransactionRecord() }); @@ -102,8 +103,8 @@ public void SupportPageViewModel_NumberTransactionsStored_ValueIsReturned() [Fact] public void SupportPageViewModel_ApplicationName_ValueIsReturned() { - this.ApplicationInfoService.Setup(d => d.ApplicationName).Returns("ApplicationName"); - this.ApplicationInfoService.Setup(d => d.VersionString).Returns("VersionString"); + this.ApplicationInfoService.ApplicationName.Getter().Returns("ApplicationName"); + this.ApplicationInfoService.VersionString.Getter().Returns("VersionString"); String applicationName = this.ViewModel.ApplicationName; @@ -117,7 +118,7 @@ public void SupportPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + this.NavigationService.GoToHome().Called(Count.Once()); } } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/ViewLogsPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/ViewLogsPageViewModelTests.cs index d65fd47dd..09ea6f898 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/ViewLogsPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Support/ViewLogsPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -13,38 +13,38 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Support [Collection("ViewModelTests")] public class ViewLogsPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; private readonly ViewLogsPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public ViewLogsPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.Mediator = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new ViewLogsPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.Mediator = new IMediatorImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new ViewLogsPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), this.NavigationParameterService.Instance()); } [Fact] public async Task SupportPageViewModel_UploadLogsCommand_Execute_IsExecuted(){ - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new List(){ + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new List(){ new LogMessage() })); @@ -54,7 +54,7 @@ public async Task SupportPageViewModel_UploadLogsCommand_Execute_IsExecuted(){ [Fact] public async Task ViewLogsPageViewModel_LoadLogMessages_RaisesPropertyChanged(){ - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new List(){ + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new List(){ new LogMessage() })); String? changedPropertyName = null; @@ -70,6 +70,6 @@ public void ViewLogsPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Admin/AdminPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Admin/AdminPageViewModelTests.cs index 096605f23..c96902030 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Admin/AdminPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Admin/AdminPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Requests; using TransactionProcessor.Mobile.BusinessLogic.Services; @@ -11,49 +11,49 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class AdminPageViewModelTests { - private readonly Mock NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; - private readonly Mock ApplicationInfoService; + private readonly IApplicationInfoServiceImposter ApplicationInfoService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; private readonly AdminPageViewModel ViewModel; public AdminPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.Mediator = new Mock(); - this.DeviceService = new Mock(); - this.ApplicationInfoService = new Mock(); - this.DialogService = new Mock(); - this.ApplicationCache = new Mock(); - this.ViewModel = new AdminPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogService.Object, - this.DeviceService.Object, - this.ApplicationInfoService.Object, this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.Mediator = new IMediatorImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ApplicationInfoService = new IApplicationInfoServiceImposter(); + this.DialogService = new IDialogServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.ViewModel = new AdminPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogService.Instance(), + this.DeviceService.Instance(), + this.ApplicationInfoService.Instance(), this.NavigationParameterService.Instance()); } [Fact] public void AdminPageViewModel_AdminCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success()); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success()); this.ViewModel.ReconciliationCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + this.NavigationService.GoToHome().Called(Count.Once()); } [Fact] public void AdminPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentFailedPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentFailedPageViewModelTests.cs index 04cfcd103..a9d875842 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentFailedPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentFailedPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.Logging; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -10,11 +10,11 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class BillPaymentFailedPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; private readonly BillPaymentFailedPageViewModel ViewModel; public BillPaymentFailedPageViewModelTests() { - this.NavigationService = new Mock(); - this.ViewModel = new BillPaymentFailedPageViewModel(this.NavigationService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.ViewModel = new BillPaymentFailedPageViewModel(this.NavigationService.Instance()); Logger.Initialise(new NullLogger()); } @@ -22,6 +22,6 @@ public BillPaymentFailedPageViewModelTests() { public void BillPaymentFailedPageViewModel_CancelledCommand_Execute_IsExecuted() { this.ViewModel.CancelledCommand.Execute(null); - this.NavigationService.Verify(n => n.PopToRoot(), Times.Once); + this.NavigationService.PopToRoot().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetAccountPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetAccountPageViewModelTests.cs index 494f89d56..933d6bd9e 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetAccountPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetAccountPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Logging; @@ -15,30 +15,30 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class BillPaymentGetAccountPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly BillPaymentGetAccountPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public BillPaymentGetAccountPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new BillPaymentGetAccountPageViewModel(this.NavigationService.Object, this.ApplicationCache.Object, - this.DialogSevice.Object, this.DeviceService.Object, this.Mediator.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new BillPaymentGetAccountPageViewModel(this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), this.DeviceService.Instance(), this.Mediator.Instance(), + this.NavigationParameterService.Instance()); Logger.Initialise(new NullLogger()); } @@ -46,9 +46,9 @@ public BillPaymentGetAccountPageViewModelTests() { [Fact] public async Task BillPaymentGetAccountPageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.ProductDetails.ShouldNotBeNull(); @@ -60,30 +60,30 @@ public async Task BillPaymentGetAccountPageViewModel_ApplyQueryAttributes_QueryA [Fact] public async Task BillPaymentGetAccountPageViewModel_GetAccountCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetAccountResponseModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetAccountResponseModel)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.CustomerAccountNumber = TestData.CustomerAccountNumber; this.ViewModel.GetAccountCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToBillPaymentPayBillPage(It.IsAny(), It.IsAny()), Times.Once); + this.NavigationService.GoToBillPaymentPayBillPage(Arg.Any(), Arg.Any()).Called(Count.Once()); } [Fact] public async Task BillPaymentGetAccountPageViewModel_GetAccountCommand_Failed_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetAccountResponseModelFailed)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetAccountResponseModelFailed)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.CustomerAccountNumber = TestData.CustomerAccountNumber; this.ViewModel.GetAccountCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToBillPaymentFailedPage(), Times.Once); + this.NavigationService.GoToBillPaymentFailedPage().Called(Count.Once()); } @@ -92,6 +92,6 @@ public async Task BillPaymentSelectProductPageViewModel_BackButtonCommand_Execut { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } -} \ No newline at end of file +} diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetMeterPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetMeterPageViewModelTests.cs index 8fb30ce09..2d7a903bf 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetMeterPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentGetMeterPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Logging; @@ -12,31 +12,31 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac public class BillPaymentGetMeterPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private Mock NavigationParameterService; + private INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly BillPaymentGetMeterPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public BillPaymentGetMeterPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new BillPaymentGetMeterPageViewModel(this.NavigationService.Object, this.ApplicationCache.Object, - this.DialogSevice.Object, this.DeviceService.Object, this.Mediator.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new BillPaymentGetMeterPageViewModel(this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), this.DeviceService.Instance(), this.Mediator.Instance(), + this.NavigationParameterService.Instance()); Logger.Initialise(new NullLogger()); } @@ -44,9 +44,9 @@ public BillPaymentGetMeterPageViewModelTests() [Fact] public async Task BillPaymentGetAccountPageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, }); await this.ViewModel.Initialise(CancellationToken.None); @@ -59,9 +59,9 @@ public async Task BillPaymentGetAccountPageViewModel_ApplyQueryAttributes_QueryA [Fact] public async Task BillPaymentGetAccountPageViewModel_GetMeterCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetMeterResponseModel)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetMeterResponseModel)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, }); await this.ViewModel.Initialise(CancellationToken.None); @@ -69,15 +69,15 @@ public async Task BillPaymentGetAccountPageViewModel_GetMeterCommand_Execute_IsE this.ViewModel.GetMeterCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToBillPaymentPayBillPage(It.IsAny(), It.IsAny()), Times.Once); + this.NavigationService.GoToBillPaymentPayBillPage(Arg.Any(), Arg.Any()).Called(Count.Once()); } [Fact] public async Task BillPaymentGetAccountPageViewModel_GetMeterCommand_Failed_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetMeterResponseModelFailed)); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.PerformBillPaymentGetMeterResponseModelFailed)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, }); await this.ViewModel.Initialise(CancellationToken.None); @@ -85,7 +85,7 @@ public async Task BillPaymentGetAccountPageViewModel_GetMeterCommand_Failed_Exec this.ViewModel.GetMeterCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToBillPaymentFailedPage(), Times.Once); + this.NavigationService.GoToBillPaymentFailedPage().Called(Count.Once()); } @@ -94,6 +94,6 @@ public async Task BillPaymentSelectProductPageViewModel_BackButtonCommand_Execut { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs index 725d80c98..290c87e5e 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -16,36 +16,36 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class BillPaymentPayBillPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private Mock NavigationParameterService; + private INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly BillPaymentPayBillPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public BillPaymentPayBillPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new BillPaymentPayBillPageViewModel(this.NavigationService.Object, this.ApplicationCache.Object, - this.DialogSevice.Object, this.Mediator.Object, this.DeviceService.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new BillPaymentPayBillPageViewModel(this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), this.Mediator.Instance(), this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task BillPaymentPayBillPageViewModel_ApplyQueryAttributes_PostPay_QueryAttributesApplied() { - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(BillDetails), TestData.BillDetails_ViewModel} }); @@ -63,7 +63,7 @@ public async Task BillPaymentPayBillPageViewModel_ApplyQueryAttributes_PostPay_Q [Fact] public async Task BillPaymentPayBillPageViewModel_ApplyQueryAttributes_PrePay_QueryAttributesApplied() { - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(MeterDetails), TestData.MeterDetails_ViewModel} }); @@ -85,7 +85,7 @@ public async Task BillPaymentPayBillPageViewModel_CustomerMobileNumberEntryCompl isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(BillDetails), TestData.BillDetails} }); @@ -103,7 +103,7 @@ public async Task BillPaymentPayBillPageViewModel_PaymentAmountEntryCompleted_Ex { isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(BillDetails), TestData.BillDetails} }); @@ -115,70 +115,70 @@ public async Task BillPaymentPayBillPageViewModel_PaymentAmountEntryCompleted_Ex [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_SuccessfulPostPayPayment_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "0000" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(BillDetails), TestData.BillDetails} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.MakeBillPaymentCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToBillPaymentSuccessPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToBillPaymentSuccessPage().Called(Count.Once()); } [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_SuccessfulPrePayPayment_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "0000" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(MeterDetails), TestData.MeterDetails} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.MakeBillPaymentCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny< TransactionCommands.PerformBillPaymentMakePrePaymentCommand>(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToBillPaymentSuccessPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToBillPaymentSuccessPage().Called(Count.Once()); } [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_FailedPostPayPayment_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "1010" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(BillDetails), TestData.BillDetails} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.MakeBillPaymentCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToBillPaymentFailedPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToBillPaymentFailedPage().Called(Count.Once()); } [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_FailedPrePayPayment_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "1010" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(MeterDetails), TestData.MeterDetails} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.MakeBillPaymentCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny< TransactionCommands.PerformBillPaymentMakePrePaymentCommand>(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToBillPaymentFailedPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToBillPaymentFailedPage().Called(Count.Once()); } [Fact] @@ -198,6 +198,6 @@ public void BillPaymentPayBillPageViewModel_SetProperties_ValuesExpected(){ public void MobileTopupPerformTopupPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(v => v.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } -} \ No newline at end of file +} diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectOperatorPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectOperatorPageViewModelTests.cs index 4e5588736..b26304797 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectOperatorPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectOperatorPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -15,42 +15,42 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class BillPaymentSelectOperatorPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly BillPaymentSelectOperatorPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public BillPaymentSelectOperatorPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationParameterService = new Mock(); - this.NavigationService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new BillPaymentSelectOperatorPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogSevice.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new BillPaymentSelectOperatorPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task BillPaymentSelectOperatorPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Operators.Count.ShouldBe(1); } @@ -58,7 +58,7 @@ public async Task BillPaymentSelectOperatorPageViewModel_Initialise_IsInitialise [Fact] public async Task BillPaymentSelectOperatorPageViewModel_OperatorSelectedCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); await this.ViewModel.Initialise(CancellationToken.None); @@ -72,7 +72,7 @@ public async Task BillPaymentSelectOperatorPageViewModel_OperatorSelectedCommand this.ViewModel.OperatorSelectedCommand.Execute(selectedContractOperator); - this.NavigationService.Verify(n => n.GoToBillPaymentSelectProductPage(It.IsAny()), Times.Once); + this.NavigationService.GoToBillPaymentSelectProductPage(Arg.Any()).Called(Count.Once()); } [Fact] @@ -86,7 +86,7 @@ public async Task BillPaymentSelectOperatorPageViewModel_BackButtonCommand_Execu this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } } diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectProductPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectProductPageViewModelTests.cs index d76d8e843..12d265c64 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectProductPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSelectProductPageViewModelTests.cs @@ -1,5 +1,5 @@ -using MediatR; -using Moq; +using MediatR; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -17,43 +17,43 @@ public class BillPaymentSelectProductPageViewModelTests { #region Methods - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly BillPaymentSelectProductPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public BillPaymentSelectProductPageViewModelTests() { - this.Mediator = new Mock(); + this.Mediator = new IMediatorImposter(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new BillPaymentSelectProductPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogSevice.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new BillPaymentSelectProductPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task BillPaymentSelectProductPageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.ProductDetails.OperatorId.ShouldBe(TestData.OperatorId1); } @@ -61,11 +61,11 @@ public async Task BillPaymentSelectProductPageViewModel_ApplyQueryAttributes_Que [Fact] public async Task BillPaymentSelectProductPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); } @@ -73,10 +73,10 @@ public async Task BillPaymentSelectProductPageViewModel_Initialise_IsInitialised [Fact] public async Task BillPaymentSelectProductPageViewModel_ProductSelectedCommand_PostPay_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); @@ -88,17 +88,17 @@ public async Task BillPaymentSelectProductPageViewModel_ProductSelectedCommand_P this.ViewModel.ProductSelectedCommand.Execute(selectedContractProduct); - this.NavigationService.Verify(n => n.GoToBillPaymentGetAccountPage(It.IsAny()), Times.Once); + this.NavigationService.GoToBillPaymentGetAccountPage(Arg.Any()).Called(Count.Once()); } [Fact] public async Task BillPaymentSelectProductPageViewModel_ProductSelectedCommand_PrePay_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { { nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel }, }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); @@ -110,7 +110,7 @@ public async Task BillPaymentSelectProductPageViewModel_ProductSelectedCommand_P this.ViewModel.ProductSelectedCommand.Execute(selectedContractProduct); - this.NavigationService.Verify(n => n.GoToBillPaymentGetMeterPage(It.IsAny()), Times.Once); + this.NavigationService.GoToBillPaymentGetMeterPage(Arg.Any()).Called(Count.Once()); } [Fact] @@ -118,7 +118,7 @@ public async Task BillPaymentSelectProductPageViewModel_BackButtonCommand_Execut { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } #endregion diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSuccessPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSuccessPageViewModelTests.cs index 4f465a748..4e8d5b05d 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSuccessPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentSuccessPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.Logging; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -10,12 +10,12 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class BillPaymentSuccessPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; private readonly BillPaymentSuccessPageViewModel ViewModel; public BillPaymentSuccessPageViewModelTests() { - this.NavigationService = new Mock(); - this.ViewModel = new BillPaymentSuccessPageViewModel(this.NavigationService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.ViewModel = new BillPaymentSuccessPageViewModel(this.NavigationService.Instance()); Logger.Initialise(new NullLogger()); } @@ -23,6 +23,6 @@ public BillPaymentSuccessPageViewModelTests() public void BillPaymentSuccessPageViewModel_CompletedCommand_Execute_IsExecuted() { this.ViewModel.CompletedCommand.Execute(null); - this.NavigationService.Verify(n => n.PopToRoot(), Times.Once); + this.NavigationService.PopToRoot().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupFailedPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupFailedPageViewModelTests.cs index d4075982b..ca78de980 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupFailedPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupFailedPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.Logging; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -10,14 +10,14 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class MobileTopupFailedPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; private readonly MobileTopupFailedPageViewModel ViewModel; public MobileTopupFailedPageViewModelTests() { - this.NavigationService = new Mock(); + this.NavigationService = new INavigationServiceImposter(); - this.ViewModel = new MobileTopupFailedPageViewModel(this.NavigationService.Object); + this.ViewModel = new MobileTopupFailedPageViewModel(this.NavigationService.Instance()); Logger.Initialise(new NullLogger()); } @@ -25,6 +25,6 @@ public MobileTopupFailedPageViewModelTests() public void MobileTopupFailedPageViewModel_CancelledCommand_Execute_IsExecuted() { this.ViewModel.CancelledCommand.Execute(null); - this.NavigationService.Verify(n => n.PopToRoot(), Times.Once); + this.NavigationService.PopToRoot().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupPerformTopupPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupPerformTopupPageViewModelTests.cs index 21959e21c..bbd3b263c 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupPerformTopupPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupPerformTopupPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -14,35 +14,35 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class MobileTopupPerformTopupPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; - private readonly Mock NavigationParameterService; - private readonly Mock ApplicationCache; - private readonly Mock DialogSevice; + private readonly INavigationServiceImposter NavigationService; + private readonly INavigationParameterServiceImposter NavigationParameterService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly IDialogServiceImposter DialogSevice; private readonly MobileTopupPerformTopupPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public MobileTopupPerformTopupPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new MobileTopupPerformTopupPageViewModel(this.Mediator.Object, - this.NavigationService.Object, - this.ApplicationCache.Object, - this.DialogSevice.Object, - this.DeviceService.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new MobileTopupPerformTopupPageViewModel(this.Mediator.Instance(), + this.NavigationService.Instance(), + this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), + this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task MobileTopupPerformTopupPageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.TopupAmount), TestData.Operator1Product_100KES.Value} }); @@ -63,7 +63,7 @@ public async Task MobileTopupPerformTopupPageViewModel_CustomerEmailAddressEntry isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(this.ViewModel.TopupAmount), TestData.Operator1Product_100KES.Value} }); @@ -81,7 +81,7 @@ public async Task MobileTopupPerformTopupPageViewModel_CustomerMobileNumberEntry isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(this.ViewModel.TopupAmount), TestData.Operator1Product_100KES.Value} }); @@ -99,7 +99,7 @@ public async Task MobileTopupPerformTopupPageViewModel_TopupAmountEntryCompleted isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(this.ViewModel.TopupAmount), TestData.Operator1Product_100KES.Value} }); @@ -111,44 +111,44 @@ public async Task MobileTopupPerformTopupPageViewModel_TopupAmountEntryCompleted [Fact] public async Task MobileTopupPerformTopupPageViewModel_PerformTopupCommand_Execute_SuccessfulTopup_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel() { + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel() { ResponseCode = "0000" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.TopupAmount), TestData.Operator1Product_100KES.Value} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.PerformTopupCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToMobileTopupSuccessPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToMobileTopupSuccessPage().Called(Count.Once()); } [Fact] public async Task MobileTopupPerformTopupPageViewModel_PerformTopupCommand_Execute_FailedTopup_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel() + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformMobileTopupResponseModel() { ResponseCode = "0001" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.TopupAmount), TestData.Operator1Product_100KES.Value} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.PerformTopupCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToMobileTopupFailedPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToMobileTopupFailedPage().Called(Count.Once()); } [Fact] public void MobileTopupPerformTopupPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(v => v.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } [Fact] diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectOperatorPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectOperatorPageViewModelTests.cs index 603a00c80..8fec2fe41 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectOperatorPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectOperatorPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -15,30 +15,30 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class MobileTopupSelectOperatorPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly MobileTopupSelectOperatorPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public MobileTopupSelectOperatorPageViewModelTests() { - this.Mediator = new Mock(); + this.Mediator = new IMediatorImposter(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new MobileTopupSelectOperatorPageViewModel(this.Mediator.Object, this.NavigationService.Object, this.DialogSevice.Object, this.ApplicationCache.Object, this.DeviceService.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new MobileTopupSelectOperatorPageViewModel(this.Mediator.Instance(), this.NavigationService.Instance(), this.DialogSevice.Instance(), this.ApplicationCache.Instance(), this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } @@ -46,10 +46,10 @@ public MobileTopupSelectOperatorPageViewModelTests() { [Fact] public async Task MobileTopupSelectOperatorPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Operators.Count.ShouldBe(1); } @@ -57,7 +57,7 @@ public async Task MobileTopupSelectOperatorPageViewModel_Initialise_IsInitialise [Fact] public async Task MobileTopupSelectOperatorPageViewModel_OperatorSelectedCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); await this.ViewModel.Initialise(CancellationToken.None); @@ -71,16 +71,16 @@ public async Task MobileTopupSelectOperatorPageViewModel_OperatorSelectedCommand this.ViewModel.OperatorSelectedCommand.Execute(selectedContractOperator); - this.NavigationService.Verify(n => n.GoToMobileTopupSelectProductPage(It.IsAny()), Times.Once); + this.NavigationService.GoToMobileTopupSelectProductPage(Arg.Any()).Called(Count.Once()); } [Fact] public async Task MobileTopupSelectOperatorPageViewModel_BackButtonCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectProductPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectProductPageViewModelTests.cs index 2c9629850..fcb7aeb75 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectProductPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSelectProductPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -17,36 +17,36 @@ public class MobileTopupSelectProductPageViewModelTests { #region Methods - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; - private Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly MobileTopupSelectProductPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public MobileTopupSelectProductPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new MobileTopupSelectProductPageViewModel(this.Mediator.Object, this.NavigationService.Object, this.ApplicationCache.Object, this.DialogSevice.Object, this.DeviceService.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new MobileTopupSelectProductPageViewModel(this.Mediator.Instance(), this.NavigationService.Instance(), this.ApplicationCache.Instance(), this.DialogSevice.Instance(), this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task MobileTopupSelectProductPageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, }); await this.ViewModel.Initialise(CancellationToken.None); @@ -56,26 +56,26 @@ public async Task MobileTopupSelectProductPageViewModel_ApplyQueryAttributes_Que [Fact] public async Task MobileTopupSelectProductPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); } [Fact] public async Task MobileTopupSelectProductPageViewModel_ProductSelectedCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); @@ -86,17 +86,17 @@ public async Task MobileTopupSelectProductPageViewModel_ProductSelectedCommand_E this.ViewModel.ProductSelectedCommand.Execute(selectedContractProduct); - this.NavigationService.Verify(n => n.GoToMobileTopupPerformTopupPage(It.IsAny(),It.IsAny()), Times.Once); + this.NavigationService.GoToMobileTopupPerformTopupPage(Arg.Any(),Arg.Any()).Called(Count.Once()); } [Fact] public async Task MobileTopupSelectProductPageViewModel_BackButtonCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } #endregion diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSuccessPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSuccessPageViewModelTests.cs index bbdf3257e..195431547 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSuccessPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/MobileTopup/MobileTopupSuccessPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -7,20 +7,20 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class MobileTopupSuccessPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; private readonly MobileTopupSuccessPageViewModel ViewModel; public MobileTopupSuccessPageViewModelTests() { - this.NavigationService = new Mock(); + this.NavigationService = new INavigationServiceImposter(); - this.ViewModel = new MobileTopupSuccessPageViewModel(this.NavigationService.Object); + this.ViewModel = new MobileTopupSuccessPageViewModel(this.NavigationService.Instance()); } [Fact] public void MobileTopupSuccessPageViewModel_CompletedCommand_Execute_IsExecuted() { this.ViewModel.CompletedCommand.Execute(null); - this.NavigationService.Verify(n => n.PopToRoot(), Times.Once); + this.NavigationService.PopToRoot().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/TransactionsPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/TransactionsPageViewModelTests.cs index 5583d6294..1103ce889 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/TransactionsPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/TransactionsPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.Services; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -8,22 +8,22 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class TransactionsPageViewModelTests { - private readonly Mock ApplicationCache; - private readonly Mock NavigationService; - private Mock NavigationParameterService; + private readonly IApplicationCacheImposter ApplicationCache; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; private readonly TransactionsPageViewModel ViewModel; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public TransactionsPageViewModelTests() { - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new TransactionsPageViewModel(this.NavigationService.Object, this.ApplicationCache.Object, this.DialogSevice.Object, this.DeviceService.Object, - this.NavigationParameterService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new TransactionsPageViewModel(this.NavigationService.Instance(), this.ApplicationCache.Instance(), this.DialogSevice.Instance(), this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } @@ -31,41 +31,41 @@ public TransactionsPageViewModelTests() { public void TransactionsPageViewModel_AdminCommand_Execute_IsExecuted() { this.ViewModel.AdminCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToAdminPage(), Times.Once); + this.NavigationService.GoToAdminPage().Called(Count.Once()); } [Fact] public void TransactionsPageViewModel_BillPaymentCommand_Execute_IsExecuted() { this.ViewModel.BillPaymentCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToBillPaymentSelectOperatorPage(), Times.Once); + this.NavigationService.GoToBillPaymentSelectOperatorPage().Called(Count.Once()); } [Fact] public void TransactionsPageViewModel_MobileTopupCommand_Execute_IsExecuted() { this.ViewModel.MobileTopupCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToMobileTopupSelectOperatorPage(), Times.Once); + this.NavigationService.GoToMobileTopupSelectOperatorPage().Called(Count.Once()); } [Fact] public void TransactionsPageViewModel_MobileWalletCommand_Execute_IsExecuted() { this.ViewModel.MobileWalletCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + this.NavigationService.GoToHome().Called(Count.Once()); } [Fact] public void TransactionsPageViewModel_VoucherCommand_Execute_IsExecuted() { this.ViewModel.VoucherCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToVoucherSelectOperatorPage(), Times.Once); + this.NavigationService.GoToVoucherSelectOperatorPage().Called(Count.Once()); } [Fact] public void TransactionsPageViewModel_BackButtonCommand_Execute_IsExecuted() { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoToHome(), Times.Once); + this.NavigationService.GoToHome().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueFailedPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueFailedPageViewModelTests.cs index f825b3df1..00815ee3c 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueFailedPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueFailedPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.Logging; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -10,14 +10,14 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class VoucherIssueFailedPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; private readonly VoucherIssueFailedPageViewModel ViewModel; public VoucherIssueFailedPageViewModelTests() { - this.NavigationService = new Mock(); + this.NavigationService = new INavigationServiceImposter(); - this.ViewModel = new VoucherIssueFailedPageViewModel(this.NavigationService.Object); + this.ViewModel = new VoucherIssueFailedPageViewModel(this.NavigationService.Instance()); Logger.Initialise(new NullLogger()); } @@ -25,6 +25,6 @@ public VoucherIssueFailedPageViewModelTests() { public void VoucherIssueFailedPageViewModel_CancelledCommand_Execute_IsExecuted() { this.ViewModel.CancelledCommand.Execute(null); - this.NavigationService.Verify(n => n.PopToRoot(), Times.Once); + this.NavigationService.PopToRoot().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSelectProductPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSelectProductPageViewModelTests.cs index 8dceb2c5e..9fb465cf4 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSelectProductPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSelectProductPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -17,37 +17,37 @@ public class VoucherIssueSelectProductPageViewModelTests { #region Methods - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; - private Mock NavigationParameterService; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly VoucherSelectProductPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public VoucherIssueSelectProductPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new VoucherSelectProductPageViewModel(this.Mediator.Object, this.NavigationService.Object, - this.ApplicationCache.Object, this.DialogSevice.Object, - this.DeviceService.Object, this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new VoucherSelectProductPageViewModel(this.Mediator.Instance(), this.NavigationService.Instance(), + this.ApplicationCache.Instance(), this.DialogSevice.Instance(), + this.DeviceService.Instance(), this.NavigationParameterService.Instance()); } [Fact] public async Task VoucherIssueSelectProductPageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); @@ -56,26 +56,26 @@ public async Task VoucherIssueSelectProductPageViewModel_ApplyQueryAttributes_Qu [Fact] public async Task VoucherIssueSelectProductPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); } [Fact] public async Task VoucherIssueSelectProductPageViewModel_ProductSelectedCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Products.Count.ShouldBe(3); @@ -86,18 +86,18 @@ public async Task VoucherIssueSelectProductPageViewModel_ProductSelectedCommand_ this.ViewModel.ProductSelectedCommand.Execute(selectedContractProduct); - this.NavigationService.Verify(n => n.GoToVoucherIssueVoucherPage(It.IsAny(),It.IsAny()), Times.Once); + this.NavigationService.GoToVoucherIssueVoucherPage(Arg.Any(),Arg.Any()).Called(Count.Once()); } [Fact] public async Task VoucherIssueSelectProductPageViewModel_BackButtonCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractProductList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractProductList)); this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(n => n.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } #endregion -} \ No newline at end of file +} diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSuccessPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSuccessPageViewModelTests.cs index c4b83f3b1..8b61202a9 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSuccessPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherIssueSuccessPageViewModelTests.cs @@ -1,4 +1,4 @@ -using Moq; +using Imposter.Abstractions; using TransactionProcessor.Mobile.BusinessLogic.UIServices; using TransactionProcessor.Mobile.BusinessLogic.ViewModels.Transactions; @@ -7,19 +7,19 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class VoucherIssueSuccessPageViewModelTests { - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; private readonly VoucherIssueSuccessPageViewModel ViewModel; public VoucherIssueSuccessPageViewModelTests() { - this.NavigationService = new Mock(); - this.ViewModel = new VoucherIssueSuccessPageViewModel(this.NavigationService.Object); + this.NavigationService = new INavigationServiceImposter(); + this.ViewModel = new VoucherIssueSuccessPageViewModel(this.NavigationService.Instance()); } [Fact] public void VoucherIssueSuccessPageViewModel_CompletedCommand_Execute_IsExecuted() { this.ViewModel.CompletedCommand.Execute(null); - this.NavigationService.Verify(n => n.PopToRoot(), Times.Once); + this.NavigationService.PopToRoot().Called(Count.Once()); } } \ No newline at end of file diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherPerformIssuePageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherPerformIssuePageViewModelTests.cs index 0fb425428..e2b8e7e4d 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherPerformIssuePageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherPerformIssuePageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Models; @@ -14,34 +14,34 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class VoucherPerformIssuePageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; + private readonly INavigationServiceImposter NavigationService; - private readonly Mock NavigationParameterService; + private readonly INavigationParameterServiceImposter NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogService; + private readonly IDialogServiceImposter DialogService; private readonly VoucherPerformIssuePageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public VoucherPerformIssuePageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogService = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new VoucherPerformIssuePageViewModel(this.NavigationService.Object, this.ApplicationCache.Object, - this.DialogService.Object, this.DeviceService.Object, this.Mediator.Object, this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogService = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new VoucherPerformIssuePageViewModel(this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DialogService.Instance(), this.DeviceService.Instance(), this.Mediator.Instance(), this.NavigationParameterService.Instance()); } [Fact] public async Task VoucherPerformIssuePageViewModel_ApplyQueryAttributes_QueryAttributesApplied() { - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.VoucherAmount), TestData.Operator1Product_100KES.Value} }); @@ -61,7 +61,7 @@ public void VoucherPerformIssuePageViewModel_CustomerEmailAddressEntryCompletedC { isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.VoucherAmount), TestData.Operator1Product_100KES.Value} }); @@ -77,7 +77,7 @@ public void VoucherPerformIssuePageViewModel_RecipientMobileNumberEntryCompleted { isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.VoucherAmount), TestData.Operator1Product_100KES.Value} }); @@ -113,7 +113,7 @@ public async Task VoucherPerformIssuePageViewModel_VoucherAmountEntryCompletedCo isCompletedCalled = true; }; - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails}, {nameof(this.ViewModel.VoucherAmount), TestData.Operator1Product_100KES.Value} }); @@ -126,38 +126,38 @@ public async Task VoucherPerformIssuePageViewModel_VoucherAmountEntryCompletedCo [Fact] public async Task VoucherPerformIssuePageViewModel_IssueVoucherCommand_Execute_SuccessfulVoucher_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel() { + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel() { ResponseCode = "0000" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.VoucherAmount), TestData.Operator1Product_100KES.Value} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.IssueVoucherCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToVoucherIssueSuccessPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToVoucherIssueSuccessPage().Called(Count.Once()); } [Fact] public async Task VoucherPerformIssuePageViewModel_IssueVoucherCommand_Execute_FailedVoucher_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel() + this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformVoucherIssueResponseModel() { ResponseCode = "1010" })); - this.NavigationParameterService.Setup(n => n.GetParameters()).Returns(new Dictionary { + this.NavigationParameterService.GetParameters().Returns(new Dictionary { {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, {nameof(this.ViewModel.VoucherAmount), TestData.Operator1Product_100KES.Value} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.IssueVoucherCommand.Execute(null); - this.Mediator.Verify(m => m.Send(It.IsAny(), It.IsAny()), Times.Once); - this.NavigationService.Verify(v => v.GoToVoucherIssueFailedPage(), Times.Once); + this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + this.NavigationService.GoToVoucherIssueFailedPage().Called(Count.Once()); } [Fact] @@ -165,7 +165,7 @@ public void VoucherPerformIssuePageViewModel_BackButtonCommand_Execute_IsExecute { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(v => v.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } [Fact] @@ -179,4 +179,4 @@ public void VoucherPerformIssuePageViewModel_Properties_ReturnExpectedValues() this.ViewModel.RecipientEmailAddress.ShouldBe(TestData.RecipientEmailAddress); this.ViewModel.RecipientMobileNumber.ShouldBe(TestData.RecipientMobileNumber); } -} \ No newline at end of file +} diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherSelectOperatorPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherSelectOperatorPageViewModelTests.cs index 6e039039c..7ca8f89c9 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherSelectOperatorPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/Voucher/VoucherSelectOperatorPageViewModelTests.cs @@ -1,5 +1,5 @@ using MediatR; -using Moq; +using Imposter.Abstractions; using Shouldly; using SimpleResults; using TransactionProcessor.Mobile.BusinessLogic.Common; @@ -15,37 +15,37 @@ namespace TransactionProcessor.Mobile.BusinessLogic.Tests.ViewModelTests.Transac [Collection("ViewModelTests")] public class VoucherSelectOperatorPageViewModelTests { - private readonly Mock Mediator; + private readonly IMediatorImposter Mediator; - private readonly Mock NavigationService; - private Mock NavigationParameterService; - private readonly Mock ApplicationCache; + private readonly INavigationServiceImposter NavigationService; + private INavigationParameterServiceImposter NavigationParameterService; + private readonly IApplicationCacheImposter ApplicationCache; - private readonly Mock DialogSevice; + private readonly IDialogServiceImposter DialogSevice; private readonly VoucherSelectOperatorPageViewModel ViewModel; - private readonly Mock DeviceService; + private readonly IDeviceServiceImposter DeviceService; public VoucherSelectOperatorPageViewModelTests() { - this.Mediator = new Mock(); - this.NavigationService = new Mock(); - this.NavigationParameterService = new Mock(); - this.ApplicationCache = new Mock(); - this.DialogSevice = new Mock(); - this.DeviceService = new Mock(); - this.ViewModel = new VoucherSelectOperatorPageViewModel(this.Mediator.Object, this.NavigationService.Object, this.ApplicationCache.Object, - this.DialogSevice.Object, this.DeviceService.Object, - this.NavigationParameterService.Object); + this.Mediator = new IMediatorImposter(); + this.NavigationService = new INavigationServiceImposter(); + this.NavigationParameterService = new INavigationParameterServiceImposter(); + this.ApplicationCache = new IApplicationCacheImposter(); + this.DialogSevice = new IDialogServiceImposter(); + this.DeviceService = new IDeviceServiceImposter(); + this.ViewModel = new VoucherSelectOperatorPageViewModel(this.Mediator.Instance(), this.NavigationService.Instance(), this.ApplicationCache.Instance(), + this.DialogSevice.Instance(), this.DeviceService.Instance(), + this.NavigationParameterService.Instance()); } [Fact] public async Task VoucherSelectOperatorPageViewModel_Initialise_IsInitialised() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); await this.ViewModel.Initialise(CancellationToken.None); - this.Mediator.Verify(x => x.Send(It.IsAny(), It.IsAny()), Times.Once); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).Called(Count.Once()); this.ViewModel.Operators.Count.ShouldBe(1); } @@ -53,7 +53,7 @@ public async Task VoucherSelectOperatorPageViewModel_Initialise_IsInitialised() [Fact] public async Task VoucherSelectOperatorPageViewModel_OperatorSelectedCommand_Execute_IsExecuted() { - this.Mediator.Setup(m => m.Send(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); + this.Mediator.Send(Arg>>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(TestData.ContractOperatorList)); await this.ViewModel.Initialise(CancellationToken.None); @@ -67,7 +67,7 @@ public async Task VoucherSelectOperatorPageViewModel_OperatorSelectedCommand_Exe this.ViewModel.OperatorSelectedCommand.Execute(selectedContractOperator); - this.NavigationService.Verify(n => n.GoToVoucherSelectProductPage(It.IsAny()), Times.Once); + this.NavigationService.GoToVoucherSelectProductPage(Arg.Any()).Called(Count.Once()); } [Fact] @@ -75,6 +75,6 @@ public void VoucherSelectOperatorPageViewModel_BackButtonCommand_Execute_IsExecu { this.ViewModel.BackButtonCommand.Execute(null); - this.NavigationService.Verify(v => v.GoBack(), Times.Once); + this.NavigationService.GoBack().Called(Count.Once()); } } \ No newline at end of file From 593836a5ffe65b73096aa4bc7dd5615336826357 Mon Sep 17 00:00:00 2001 From: StuartFerguson Date: Thu, 3 Sep 2026 16:40:12 +0100 Subject: [PATCH 2/2] Address review feedback for Imposter migration --- .../ViewModelTests/LoginPageViewModelTests.cs | 28 +++++++++ .../BillPaymentPayBillPageViewModelTests.cs | 59 +++++++++++++------ 2 files changed, 68 insertions(+), 19 deletions(-) diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs index 76d2d2374..b50f67e70 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/LoginPageViewModelTests.cs @@ -191,6 +191,34 @@ public async Task LoginPageViewModel_LoginCommand_Execute_UpdateRequired_UpdateL this.warningToastCount.ShouldBe(0); } + [Fact] + public async Task LoginPageViewModel_LoginCommand_Execute_UpdateLauncherFails_WarningToastIsShown_And_AppStaysOpen() + { + this.Mediator.Send(Arg>>.Any(), Arg.Any()) + .ReturnsAsync(Result.Success(new Configuration { EnableAutoUpdates = true })); + this.ApplicationInfoService.VersionString.Getter().Returns(TestData.ApplicationVersion); + this.ApplicationInfoService.PackageName.Getter().Returns("com.transactionprocessor.mobile"); + this.DeviceService.GetPlatform().Returns("Android"); + this.DeviceService.GetIdentifier().Returns(TestData.DeviceIdentifier); + this.UpdateService.CheckForUpdates(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()) + .ReturnsAsync(Result.Success(new ApplicationUpdateCheckResponse + { + DownloadUri = "https://updates.example.com/transactionmobile.apk", + LatestVersion = "1.0.1", + Message = "Install update", + UpdateRequired = true + })); + this.DialogService.ShowDialog(Arg.Any(), Arg.Any(), Arg.Any(), Arg.Any()).ReturnsAsync(true); + this.ApplicationUpdateLauncherService.LaunchUpdateAsync(Arg.Any(), Arg.Any()) + .ThrowsAsync(new ApplicationException("Unable to start the application update installer.")); + + await this.ViewModel.LogonCommand.ExecuteAsync(null); + + this.NavigationService.QuitApplication().Called(Count.Never()); + this.NavigationService.GoToHome().Called(Count.Never()); + this.warningToastCount.ShouldBe(1); + } + [Fact] public void LoginPageViewModel_LoginCommand_Execute_ErrorDuringLogonTransaction_WarningToastIsShown() { diff --git a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs index 290c87e5e..dd4c9d595 100644 --- a/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs +++ b/TransactionProcessor.Mobile.BusinessLogic.Tests/ViewModelTests/Transactions/BillPayment/BillPaymentPayBillPageViewModelTests.cs @@ -86,8 +86,8 @@ public async Task BillPaymentPayBillPageViewModel_CustomerMobileNumberEntryCompl }; this.NavigationParameterService.GetParameters().Returns(new Dictionary { - {nameof(ProductDetails), TestData.Operator1ProductDetails}, - {nameof(BillDetails), TestData.BillDetails} + {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, + {nameof(BillDetails), TestData.BillDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); @@ -104,8 +104,8 @@ public async Task BillPaymentPayBillPageViewModel_PaymentAmountEntryCompleted_Ex isCompletedCalled = true; }; this.NavigationParameterService.GetParameters().Returns(new Dictionary { - {nameof(ProductDetails), TestData.Operator1ProductDetails}, - {nameof(BillDetails), TestData.BillDetails} + {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, + {nameof(BillDetails), TestData.BillDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); this.ViewModel.PaymentAmountEntryCompletedCommand.Execute(null); @@ -115,35 +115,49 @@ public async Task BillPaymentPayBillPageViewModel_PaymentAmountEntryCompleted_Ex [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_SuccessfulPostPayPayment_IsExecuted() { + IRequest> sentCommand = null; this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "0000" - })); + })) + .Callback((IRequest> command, CancellationToken _) => + { + sentCommand = command; + return Task.CompletedTask; + }); this.NavigationParameterService.GetParameters().Returns(new Dictionary { - {nameof(ProductDetails), TestData.Operator1ProductDetails}, - {nameof(BillDetails), TestData.BillDetails} + {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, + {nameof(BillDetails), TestData.BillDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); - this.ViewModel.MakeBillPaymentCommand.Execute(null); + await this.ViewModel.MakeBillPaymentCommand.ExecuteAsync(null); this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + sentCommand.ShouldBeOfType(); this.NavigationService.GoToBillPaymentSuccessPage().Called(Count.Once()); } [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_SuccessfulPrePayPayment_IsExecuted() { + IRequest> sentCommand = null; this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "0000" - })); + })) + .Callback((IRequest> command, CancellationToken _) => + { + sentCommand = command; + return Task.CompletedTask; + }); this.NavigationParameterService.GetParameters().Returns(new Dictionary { - {nameof(ProductDetails), TestData.Operator1ProductDetails}, - {nameof(MeterDetails), TestData.MeterDetails} + {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, + {nameof(MeterDetails), TestData.MeterDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); - this.ViewModel.MakeBillPaymentCommand.Execute(null); + await this.ViewModel.MakeBillPaymentCommand.ExecuteAsync(null); this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + sentCommand.ShouldBeOfType(); this.NavigationService.GoToBillPaymentSuccessPage().Called(Count.Once()); } @@ -154,11 +168,11 @@ public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute ResponseCode = "1010" })); this.NavigationParameterService.GetParameters().Returns(new Dictionary { - {nameof(ProductDetails), TestData.Operator1ProductDetails}, - {nameof(BillDetails), TestData.BillDetails} + {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, + {nameof(BillDetails), TestData.BillDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); - this.ViewModel.MakeBillPaymentCommand.Execute(null); + await this.ViewModel.MakeBillPaymentCommand.ExecuteAsync(null); this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); this.NavigationService.GoToBillPaymentFailedPage().Called(Count.Once()); } @@ -166,18 +180,25 @@ public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute [Fact] public async Task BillPaymentPayBillPageViewModel_MakeBillPaymentCommand_Execute_FailedPrePayPayment_IsExecuted() { + IRequest> sentCommand = null; this.Mediator.Send(Arg>>.Any(), Arg.Any()).ReturnsAsync(Result.Success(new PerformBillPaymentMakePaymentResponseModel() { ResponseCode = "1010" - })); + })) + .Callback((IRequest> command, CancellationToken _) => + { + sentCommand = command; + return Task.CompletedTask; + }); this.NavigationParameterService.GetParameters().Returns(new Dictionary { - {nameof(ProductDetails), TestData.Operator1ProductDetails}, - {nameof(MeterDetails), TestData.MeterDetails} + {nameof(ProductDetails), TestData.Operator1ProductDetails_ViewModel}, + {nameof(MeterDetails), TestData.MeterDetails_ViewModel} }); await this.ViewModel.Initialise(CancellationToken.None); - this.ViewModel.MakeBillPaymentCommand.Execute(null); + await this.ViewModel.MakeBillPaymentCommand.ExecuteAsync(null); this.Mediator.Send(Arg>>.Any(), Arg.Any()).Called(Count.Once()); + sentCommand.ShouldBeOfType(); this.NavigationService.GoToBillPaymentFailedPage().Called(Count.Once()); }