diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs index ee303f23..f79ec732 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs @@ -195,7 +195,7 @@ public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorNotFoun // TODO: Reintroduce when we have an Operator Aggregate // https://github.com/TransactionProcessing/EstateManagement/issues/558 - [Theory(Skip = "Needs Operator Aggregate")] + [Theory] [InlineData(null)] [InlineData("")] public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorRequiresMerchantNumber_MerchantNumberNotSet_ErrorThrown( @@ -205,6 +205,8 @@ public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorRequire this.AggregateService .Setup(m => m.Save(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); @@ -222,7 +224,7 @@ public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorRequire // TODO: Reintroduce when we have an Operator Aggregate // https://github.com/TransactionProcessing/EstateManagement/issues/558 - [Theory(Skip = "Needs Operator Aggregate")] + [Theory] [InlineData(null)] [InlineData("")] public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorRequiresTerminalNumber_TerminalNumberNotSet_ErrorThrown( @@ -232,6 +234,8 @@ public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorRequire this.AggregateService .Setup(m => m.Save(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); @@ -444,20 +448,17 @@ public async Task MerchantDomainService_MakeMerchantDeposit_DepositIsMade() } [Fact] - public async Task MerchantDomainService_MakeMerchantDeposit_GetDepositListFailed_ResultIsFailed() + public async Task MerchantDomainService_MakeMerchantDeposit_DuplicateDeposit_ResultIsFailed() { this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); this.AggregateService .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Failure()); + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantDepositListAggregateWithDeposit())); this.AggregateService .Setup(m => m.Save(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success()); @@ -467,16 +468,30 @@ public async Task MerchantDomainService_MakeMerchantDeposit_GetDepositListFailed } [Fact] - public async Task MerchantDomainService_MakeMerchantDeposit_DepositListSaveFailed_ResultIsFailed() + public async Task MerchantDomainService_MakeMerchantDeposit_GetDepositListFailed_ResultIsFailed() { this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); + .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantDeposit(TestData.Commands.MakeMerchantDepositCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantDeposit_DepositListSaveFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); this.AggregateService .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) @@ -494,11 +509,8 @@ public async Task MerchantDomainService_MakeMerchantDeposit_EstateNotCreated_Err this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.EmptyEstateAggregate); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); var result = await this.DomainService.MakeMerchantDeposit(TestData.Commands.MakeMerchantDepositCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); @@ -509,11 +521,8 @@ public async Task MerchantDomainService_MakeMerchantDeposit_MerchantNotCreated_E this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); var result = await this.DomainService.MakeMerchantDeposit(TestData.Commands.MakeMerchantDepositCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); @@ -609,50 +618,55 @@ public async Task MerchantDomainService_MakeMerchantWithdrawal_WithdrawalIsMade( } [Fact] - public async Task MerchantDomainService_MakeMerchantWithdrawal_GetDepositListFailed_ResultIsFailed() + public async Task MerchantDomainService_MakeMerchantWithdrawal_DuplicateWithdrawal_ResultIsFailed() { this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); this.AggregateService .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Failure()); + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantDepositListAggregateWithWithdrawal())); + this.AggregateService + .Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success()); this.SecurityServiceClient .Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.TokenResponse())); + this.EventStoreContext.Setup(e => e.GetPartitionStateFromProjection(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(JsonConvert.SerializeObject(TestData.MerchantBalanceProjectionState))); + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); } [Fact] - public async Task MerchantDomainService_MakeMerchantWithdrawal_EstateNotCreated_ErrorThrown() { + public async Task MerchantDomainService_MakeMerchantWithdrawal_GetDepositListFailed_ResultIsFailed() + { this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) - .ReturnsAsync(TestData.Aggregates.EmptyEstateAggregate); + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); this.AggregateService .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantDepositListAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success()); + .ReturnsAsync(Result.Failure()); - this.SecurityServiceClient - .Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(TestData.TokenResponse())); + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantWithdrawal_EstateNotCreated_ErrorThrown() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EmptyEstateAggregate); + + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); @@ -663,22 +677,8 @@ public async Task MerchantDomainService_MakeMerchantWithdrawal_MerchantNotCreate this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); - - this.AggregateService - .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantDepositListAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success()); - - this.SecurityServiceClient - .Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(TestData.TokenResponse())); var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); @@ -689,22 +689,12 @@ public async Task MerchantDomainService_MakeMerchantWithdrawal_MerchantDepositLi this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); this.AggregateService .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantDepositListAggregate)); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success()); - - this.SecurityServiceClient - .Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(TestData.TokenResponse())); var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); @@ -715,11 +705,8 @@ public async Task MerchantDomainService_MakeMerchantWithdrawal_NotEnoughFundsToW this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); - this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); - this.AggregateService - .Setup(m => m.Save(It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success); this.AggregateService .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) @@ -728,9 +715,8 @@ public async Task MerchantDomainService_MakeMerchantWithdrawal_NotEnoughFundsToW .Setup(m => m.Save(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success()); - this.SecurityServiceClient - .Setup(s => s.GetToken(It.IsAny(), It.IsAny(), It.IsAny())) - .ReturnsAsync(Result.Success(TestData.TokenResponse())); + this.EventStoreContext.Setup(e => e.GetPartitionStateFromProjection(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(JsonConvert.SerializeObject(TestData.MerchantBalanceProjectionStateNoCredit))); var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); @@ -1052,4 +1038,875 @@ public async Task MerchantDomainService_RemoveContractFromMerchant_ValidationFai var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); } + + [Fact] + public async Task MerchantDomainService_CreateMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.CreateMerchant(TestData.Commands.CreateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.CreateMerchant(TestData.Commands.CreateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.CreateMerchant(TestData.Commands.CreateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AssignOperatorToMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AssignOperatorToMerchant(TestData.Commands.AssignOperatorToMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AssignOperatorToMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AssignOperatorToMerchant(TestData.Commands.AssignOperatorToMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AssignOperatorToMerchant_GetOperatorFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AssignOperatorToMerchant(TestData.Commands.AssignOperatorToMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AssignOperatorToMerchant_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithEverything(SettlementSchedule.Immediate))); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AssignOperatorToMerchant(TestData.Commands.AssignOperatorToMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AssignOperatorToMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.EstateAggregateWithOperator()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedOperatorAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AssignOperatorToMerchant(TestData.Commands.AssignOperatorToMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchantUser_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.CreateMerchantUser(TestData.Commands.CreateMerchantUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchantUser_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.CreateMerchantUser(TestData.Commands.CreateMerchantUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchantUser_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.SecurityServiceClient.Setup(s => s.CreateUser(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success()); + this.SecurityServiceClient.Setup(s => s.GetUsers(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(new List { new UserDetails { UserId = Guid.NewGuid() } })); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.CreateMerchantUser(TestData.Commands.CreateMerchantUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddDeviceToMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddDeviceToMerchant(TestData.Commands.AddMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddDeviceToMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddDeviceToMerchant(TestData.Commands.AddMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddDeviceToMerchant_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithEverything(SettlementSchedule.Immediate))); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddDeviceToMerchant(TestData.Commands.AddMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddDeviceToMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddDeviceToMerchant(TestData.Commands.AddMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantDeposit_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantDeposit(TestData.Commands.MakeMerchantDepositCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantDeposit_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantDeposit(TestData.Commands.MakeMerchantDepositCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.SwapMerchantDevice(TestData.Commands.SwapMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.SwapMerchantDevice(TestData.Commands.SwapMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_StateChangedFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithDevice())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var command = TestData.Commands.SwapMerchantDeviceCommand with { + DeviceIdentifier = String.Empty + }; + + var result = await this.DomainService.SwapMerchantDevice(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithDevice())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.SwapMerchantDevice(TestData.Commands.SwapMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantWithdrawal_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantWithdrawal_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantWithdrawal_GetBalanceFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService + .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantDepositListAggregate())); + this.EventStoreContext.Setup(e => e.GetPartitionStateFromProjection(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantWithdrawal_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService + .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantDepositListAggregate())); + this.EventStoreContext.Setup(e => e.GetPartitionStateFromProjection(It.IsAny(), It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(JsonConvert.SerializeObject(TestData.MerchantBalanceProjectionState))); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddContractToMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddContractToMerchant(TestData.Commands.AddMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddContractToMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddContractToMerchant(TestData.Commands.AddMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddContractToMerchant_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithEverything(SettlementSchedule.Immediate))); + this.AggregateService.Setup(c => c.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(CalculationType.Fixed, FeeType.Merchant)); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddContractToMerchant(TestData.Commands.AddMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddContractToMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(c => c.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedContractAggregateWithAProductAndTransactionFee(CalculationType.Fixed, FeeType.Merchant)); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddContractToMerchant(TestData.Commands.AddMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchant(TestData.Commands.UpdateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchant(TestData.Commands.UpdateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchant_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.UpdateMerchant(TestData.Commands.UpdateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + MerchantCommands.UpdateMerchantCommand command = TestData.Commands.UpdateMerchantCommand; + command.RequestDto.SettlementSchedule = DataTransferObjects.Responses.Merchant.SettlementSchedule.Immediate; + + var result = await this.DomainService.UpdateMerchant(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantAddress_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddMerchantAddress(TestData.Commands.AddMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantAddress_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddMerchantAddress(TestData.Commands.AddMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantAddress_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.AddMerchantAddress(TestData.Commands.AddMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantAddress_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddMerchantAddress(TestData.Commands.AddMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantAddress_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchantAddress(TestData.Commands.UpdateMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantAddress_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchantAddress(TestData.Commands.UpdateMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantAddress_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.UpdateMerchantAddress(TestData.Commands.UpdateMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantAddress_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchantAddress(TestData.Commands.UpdateMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantContact_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddMerchantContact(TestData.Commands.AddMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantContact_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddMerchantContact(TestData.Commands.AddMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantContact_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.AddMerchantContact(TestData.Commands.AddMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantContact_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.AddMerchantContact(TestData.Commands.AddMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantContact_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchantContact(TestData.Commands.UpdateMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantContact_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchantContact(TestData.Commands.UpdateMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantContact_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.UpdateMerchantContact(TestData.Commands.UpdateMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantContact_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.UpdateMerchantContact(TestData.Commands.UpdateMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveOperatorFromMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.RemoveOperatorFromMerchant(TestData.Commands.RemoveOperatorFromMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveOperatorFromMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.RemoveOperatorFromMerchant(TestData.Commands.RemoveOperatorFromMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveOperatorFromMerchant_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.RemoveOperatorFromMerchant(TestData.Commands.RemoveOperatorFromMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveOperatorFromMerchant_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithOperator())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var command = TestData.Commands.RemoveOperatorFromMerchantCommand with { OperatorId = Guid.NewGuid() }; + + var result = await this.DomainService.RemoveOperatorFromMerchant(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveOperatorFromMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithOperator())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.RemoveOperatorFromMerchant(TestData.Commands.RemoveOperatorFromMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveContractFromMerchant_GetEstateFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveContractFromMerchant_GetMerchantFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveContractFromMerchant_MerchantNotCreated_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + + var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveContractFromMerchant_StateChangeFailed_ResultIsFailed() + { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithEverything(SettlementSchedule.Immediate))); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var command = TestData.Commands.RemoveMerchantContractCommand with { ContractId = Guid.NewGuid() }; + + var result = await this.DomainService.RemoveContractFromMerchant(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveContractFromMerchant_SaveFailed_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.MerchantAggregateWithEverything(SettlementSchedule.Immediate))); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Failure()); + + var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchant_NotSetSettlementSchedule_ResultIsFailed() { + this.AggregateService.Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.EmptyMerchantAggregate())); + this.AggregateService.Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success()); + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + + MerchantCommands.CreateMerchantCommand command = TestData.Commands.CreateMerchantCommand; + command.RequestDto.SettlementSchedule = DataTransferObjects.Responses.Merchant.SettlementSchedule.NotSet; + + var result = await this.DomainService.CreateMerchant(command, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantDeposit_AutomaticDepositSource_DepositIsMade() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(TestData.Aggregates.CreatedEstateAggregate()); + this.AggregateService.Setup(m => m.Get(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantAggregate())); + this.AggregateService + .Setup(m => m.GetLatest(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success(TestData.Aggregates.CreatedMerchantDepositListAggregate())); + this.AggregateService + .Setup(m => m.Save(It.IsAny(), It.IsAny())) + .ReturnsAsync(Result.Success()); + + MerchantCommands.MakeMerchantDepositCommand command = new(TestData.EstateId, TestData.MerchantId, + TestData.MerchantDepositSourceAutomaticDTO, TestData.MakeMerchantDepositRequest); + + var result = await this.DomainService.MakeMerchantDeposit(command, CancellationToken.None); + result.IsSuccess.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.CreateMerchant(TestData.Commands.CreateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AssignOperatorToMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.AssignOperatorToMerchant(TestData.Commands.AssignOperatorToMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_CreateMerchantUser_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.CreateMerchantUser(TestData.Commands.CreateMerchantUserCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddDeviceToMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.AddDeviceToMerchant(TestData.Commands.AddMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantDeposit_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.MakeMerchantDeposit(TestData.Commands.MakeMerchantDepositCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_SwapMerchantDevice_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.SwapMerchantDevice(TestData.Commands.SwapMerchantDeviceCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_MakeMerchantWithdrawal_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.MakeMerchantWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddContractToMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.AddContractToMerchant(TestData.Commands.AddMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.UpdateMerchant(TestData.Commands.UpdateMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantAddress_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.AddMerchantAddress(TestData.Commands.AddMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantAddress_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.UpdateMerchantAddress(TestData.Commands.UpdateMerchantAddressCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_AddMerchantContact_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.AddMerchantContact(TestData.Commands.AddMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_UpdateMerchantContact_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.UpdateMerchantContact(TestData.Commands.UpdateMerchantContactCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveOperatorFromMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.RemoveOperatorFromMerchant(TestData.Commands.RemoveOperatorFromMerchantCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } + + [Fact] + public async Task MerchantDomainService_RemoveContractFromMerchant_ExceptionThrown_ResultIsFailed() { + this.AggregateService.Setup(e => e.Get(It.IsAny(), It.IsAny())) + .ThrowsAsync(new Exception("Test exception")); + + var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); + result.IsFailed.ShouldBeTrue(); + } } \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs index facccb11..95dc0c15 100644 --- a/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/MerchantDomainService.cs @@ -79,7 +79,7 @@ public async Task AddDeviceToMerchant(MerchantCommands.AddMerchantDevice return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -193,7 +193,7 @@ public async Task CreateMerchant(MerchantCommands.CreateMerchantCommand } Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(merchantId, ct), merchantId, cancellationToken, false); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); MerchantAggregate merchantAggregate = merchantResult.Data; @@ -245,7 +245,7 @@ public async Task CreateMerchantUser(MerchantCommands.CreateMerchantUser return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -294,7 +294,7 @@ public async Task MakeMerchantDeposit(MerchantCommands.MakeMerchantDepos return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -350,7 +350,7 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.Get(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -375,7 +375,7 @@ public async Task MakeMerchantWithdrawal(MerchantCommands.MakeMerchantWi Result getBalanceResult = await this.EventStoreContext.GetPartitionStateFromProjection("MerchantBalanceProjection", $"MerchantBalance-{command.MerchantId:N}", cancellationToken); if (getBalanceResult.IsFailed) { - Result.Invalid($"Failed to get Merchant Balance."); + return Result.Invalid($"Failed to get Merchant Balance."); } MerchantBalanceProjectionState1 projectionState = JsonConvert.DeserializeObject(getBalanceResult.Data); @@ -412,7 +412,7 @@ public async Task AddContractToMerchant(MerchantCommands.AddMerchantCont return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -455,7 +455,7 @@ public async Task UpdateMerchant(MerchantCommands.UpdateMerchantCommand return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -493,7 +493,7 @@ public async Task AddMerchantAddress(MerchantCommands.AddMerchantAddress return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -531,7 +531,7 @@ public async Task UpdateMerchantAddress(MerchantCommands.UpdateMerchantA return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -569,7 +569,7 @@ public async Task AddMerchantContact(MerchantCommands.AddMerchantContact return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -606,7 +606,7 @@ public async Task UpdateMerchantContact(MerchantCommands.UpdateMerchantC return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -639,7 +639,7 @@ public async Task RemoveOperatorFromMerchant(MerchantCommands.RemoveOper return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -673,7 +673,7 @@ public async Task RemoveContractFromMerchant(MerchantCommands.RemoveMerc return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; @@ -726,7 +726,7 @@ public async Task SwapMerchantDevice(MerchantCommands.SwapMerchantDevice return ResultHelpers.CreateFailure(estateResult); Result merchantResult = await DomainServiceHelper.GetAggregateOrFailure(ct => this.AggregateService.GetLatest(command.MerchantId, ct), command.MerchantId, cancellationToken); - if (estateResult.IsFailed) + if (merchantResult.IsFailed) return ResultHelpers.CreateFailure(merchantResult); EstateAggregate estateAggregate = estateResult.Data; diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs index eaaf52a6..35805e39 100644 --- a/TransactionProcessor.Testing/TestData.cs +++ b/TransactionProcessor.Testing/TestData.cs @@ -2328,6 +2328,33 @@ public static MerchantDepositListAggregate CreatedMerchantDepositListAggregate() return merchantDepositListAggregate; } + + public static MerchantDepositListAggregate MerchantDepositListAggregateWithDeposit() + { + MerchantAggregate merchantAggregate = MerchantAggregate.Create(TestData.MerchantId); + + merchantAggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated, TestData.AddressModel, TestData.ContactModel, + TestData.SettlementScheduleModel); + + MerchantDepositListAggregate merchantDepositListAggregate = MerchantDepositListAggregate.Create(TestData.MerchantId); + merchantDepositListAggregate.Create(merchantAggregate, TestData.DateMerchantCreated); + merchantDepositListAggregate.MakeDeposit(Models.Merchant.MerchantDepositSource.Manual, TestData.Commands.MakeMerchantDepositCommand.RequestDto.Reference, TestData.Commands.MakeMerchantDepositCommand.RequestDto.DepositDateTime, PositiveMoney.Create(Money.Create(TestData.Commands.MakeMerchantDepositCommand.RequestDto.Amount))); + return merchantDepositListAggregate; + } + + public static MerchantDepositListAggregate MerchantDepositListAggregateWithWithdrawal() + { + MerchantAggregate merchantAggregate = MerchantAggregate.Create(TestData.MerchantId); + + merchantAggregate.Create(TestData.EstateId, TestData.MerchantName, TestData.DateMerchantCreated, TestData.AddressModel, TestData.ContactModel, + TestData.SettlementScheduleModel); + + MerchantDepositListAggregate merchantDepositListAggregate = MerchantDepositListAggregate.Create(TestData.MerchantId); + merchantDepositListAggregate.Create(merchantAggregate, TestData.DateMerchantCreated); + merchantDepositListAggregate.MakeWithdrawal(TestData.Commands.MakeMerchantWithdrawalCommand.RequestDto.WithdrawalDateTime, PositiveMoney.Create(Money.Create(TestData.Commands.MakeMerchantWithdrawalCommand.RequestDto.Amount))); + return merchantDepositListAggregate; + } + public static MerchantAggregate MerchantAggregateWithDevice() { MerchantAggregate merchantAggregate = MerchantAggregate.Create(TestData.MerchantId);