@@ -26,7 +26,6 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services;
2626public class TransactionValidationServiceTests {
2727 private readonly TransactionValidationService TransactionValidationService ;
2828 private readonly Mock < ISecurityServiceClient > SecurityServiceClient ;
29- private readonly Mock < IEventStoreContext > EventStoreContext ;
3029 private readonly Mock < IAggregateService > AggregateService ;
3130 public TransactionValidationServiceTests ( ) {
3231 IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
@@ -35,12 +34,11 @@ public TransactionValidationServiceTests() {
3534 Logger . Initialise ( NullLogger . Instance ) ;
3635
3736 this . SecurityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
38- this . EventStoreContext = new Mock < IEventStoreContext > ( ) ;
3937 this . AggregateService = new Mock < IAggregateService > ( ) ;
4038
4139 this . SecurityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . TokenResponse ( ) ) ) ;
4240
43- this . TransactionValidationService = new TransactionValidationService ( this . EventStoreContext . Object , this . AggregateService . Object ) ;
41+ this . TransactionValidationService = new TransactionValidationService ( this . AggregateService . Object ) ;
4442 }
4543
4644 [ Fact ]
@@ -403,9 +401,6 @@ public async Task TransactionValidationService_ValidateSaleTransaction_InvalidCo
403401 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
404402 . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
405403
406- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
407- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
408-
409404 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
410405 TestData . MerchantId ,
411406 Guid . Empty ,
@@ -428,9 +423,6 @@ public async Task TransactionValidationService_ValidateSaleTransaction_InvalidPr
428423 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
429424 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
430425
431- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
432- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
433-
434426 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
435427 TestData . MerchantId ,
436428 TestData . ContractId ,
@@ -499,10 +491,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_MerchantD
499491 this . AggregateService . Setup ( e => e . Get < EstateAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
500492 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
501493 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
502-
503- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
504- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
505-
494+
506495 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
507496 TestData . MerchantId ,
508497 TestData . ContractId1 ,
@@ -525,11 +514,6 @@ public async Task TransactionValidationService_ValidateSaleTransaction_MerchantH
525514 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
526515 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithNoContracts ( SettlementSchedule . Immediate ) ) ;
527516
528-
529-
530- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
531- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
532-
533517 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
534518 TestData . MerchantId ,
535519 TestData . ContractId ,
@@ -551,9 +535,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_MerchantN
551535 this . AggregateService . Setup ( e => e . Get < EstateAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
552536 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
553537 this . AggregateService . Setup ( m => m . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
554- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
555- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionStateNoCredit ) ) ;
556-
538+ this . AggregateService . Setup ( e => e . GetLatest < MerchantBalanceAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . EmptyMerchantBalanceAggregate ( ) ) ;
557539 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
558540 TestData . MerchantId ,
559541 TestData . ContractId ,
@@ -576,8 +558,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_MerchantN
576558 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
577559 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
578560 . ReturnsAsync ( Result . NotFound ( "Merchant not found" ) ) ;
579-
580-
561+
581562 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
582563 TestData . MerchantId ,
583564 TestData . ContractId ,
@@ -626,9 +607,6 @@ public async Task TransactionValidationService_ValidateSaleTransaction_MerchantN
626607 . ReturnsAsync ( Result . Success ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) )
627608 . ReturnsAsync ( Result . NotFound ( ) ) ;
628609
629- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
630- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
631-
632610 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
633611 TestData . MerchantId ,
634612 TestData . ContractId ,
@@ -652,10 +630,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_FailedGet
652630 this . AggregateService . SetupSequence ( m => m . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
653631 . ReturnsAsync ( Result . Success ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) )
654632 . ReturnsAsync ( Result . NotFound ( ) ) ;
655-
656- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
657- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
658-
633+
659634 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
660635 TestData . MerchantId ,
661636 TestData . ContractId ,
@@ -747,10 +722,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_ProductId
747722 this . AggregateService . Setup ( e => e . Get < EstateAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
748723 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
749724 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
750-
751- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
752- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
753-
725+
754726 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
755727 TestData . MerchantId ,
756728 TestData . ContractId ,
@@ -772,10 +744,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_Successfu
772744 this . AggregateService . Setup ( e => e . Get < EstateAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
773745 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
774746 this . AggregateService . SetupSequence ( m => m . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
775-
776- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
777- . ReturnsAsync ( JsonConvert . SerializeObject ( TestData . MerchantBalanceProjectionState ) ) ;
778-
747+ this . AggregateService . Setup ( e => e . GetLatest < MerchantBalanceAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . Aggregates . MerchantBalanceAggregateWithCredit ( ) ) ;
779748 var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
780749 TestData . MerchantId ,
781750 TestData . ContractId ,
@@ -789,19 +758,16 @@ public async Task TransactionValidationService_ValidateSaleTransaction_Successfu
789758 }
790759
791760 [ Fact ]
792- public async Task TransactionValidationService_ValidateSaleTransaction_FailedGettingMerchantBalance_ResponseIsInvalidMerchantId ( )
761+ public async Task TransactionValidationService_ValidateSaleTransaction_FailedGettingMerchantBalance_ResponseIsErrorGettingMerchantBalance ( )
793762 {
794763 this . SecurityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Success ( TestData . TokenResponse ( ) ) ) ;
795764
796765 this . AggregateService . Setup ( e => e . Get < EstateAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
797766 . ReturnsAsync ( Result . Success ( TestData . Aggregates . EstateAggregateWithOperator ( ) ) ) ;
798767 this . AggregateService . Setup ( e => e . Get < MerchantAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
799768 . ReturnsAsync ( TestData . Aggregates . MerchantAggregateWithEverything ( SettlementSchedule . Immediate ) ) ;
800-
801- this . EventStoreContext . Setup ( e => e . GetPartitionStateFromProjection ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) )
802- . ReturnsAsync ( Result . Failure ( ) ) ;
803-
804- var result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
769+ this . AggregateService . Setup ( e => e . GetLatest < MerchantBalanceAggregate > ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( Result . Failure ( ) ) ;
770+ Result < TransactionValidationResult > result = await this . TransactionValidationService . ValidateSaleTransaction ( TestData . EstateId ,
805771 TestData . MerchantId ,
806772 TestData . ContractId ,
807773 TestData . ProductId ,
@@ -811,7 +777,7 @@ public async Task TransactionValidationService_ValidateSaleTransaction_FailedGet
811777 CancellationToken . None ) ;
812778
813779 result . IsFailed . ShouldBeTrue ( ) ;
814- result . Data . ResponseCode . ShouldBe ( TransactionResponseCode . UnknownFailure ) ;
780+ result . Data . ResponseCode . ShouldBe ( TransactionResponseCode . ErrorGettingMerchantBalance ) ;
815781 }
816782}
817783
0 commit comments