Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ public async Task TransactionValidationService_ValidateSaleTransaction_InvalidTr
.ReturnsAsync(TestData.GetEstateResponseWithOperator1);
this.EstateClient.Setup(e => e.GetMerchant(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetMerchantResponseWithOperator1);
this.EstateClient.Setup(e => e.GetMerchantContracts(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.MerchantContractResponses);

(String responseMessage, TransactionResponseCode responseCode) response = await this.TransactionValidationService.ValidateSaleTransaction(TestData.EstateId,
TestData.MerchantId,
Expand Down Expand Up @@ -659,7 +661,8 @@ public async Task TransactionValidationService_ValidateSaleTransaction_MerchantN
.ReturnsAsync(TestData.GetEstateResponseWithOperator1);
this.EstateClient.Setup(e => e.GetMerchant(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetMerchantResponseWithOperator1);

this.EstateClient.Setup(e => e.GetMerchantContracts(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.MerchantContractResponses);
this.StateRepository.Setup(p => p.Load(It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.MerchantBalanceProjectionStateNoCredit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,12 @@ public TransactionValidationService(IEstateClient estateClient,
}
}

// Check the amount
if (transactionAmount.HasValue){
if (transactionAmount <= 0){
throw new TransactionValidationException("Transaction Amount must be greater than 0", TransactionResponseCode.InvalidSaleTransactionAmount);
}

MerchantBalanceState merchantBalanceState = await this.MerchantBalanceStateRepository.Load(estateId, merchantId, cancellationToken);

// Check the merchant has enough balance to perform the sale
if (merchantBalanceState.AvailableBalance < transactionAmount){
throw new
TransactionValidationException($"Merchant [{merchant.MerchantName}] does not have enough credit available [{merchantBalanceState.AvailableBalance}] to perform transaction amount [{transactionAmount}]",
TransactionResponseCode.MerchantDoesNotHaveEnoughCredit);
}
}

// Contract and Product Validation
if (contractId == Guid.Empty){
throw new TransactionValidationException($"Contract Id [{contractId}] must be set for a sale transaction",
TransactionResponseCode.InvalidContractIdValue);
}

List<ContractResponse> merchantContracts = null;
try{
merchantContracts = await this.GetMerchantContracts(estateId, merchantId, cancellationToken);
Expand Down Expand Up @@ -217,6 +201,22 @@ public TransactionValidationService(IEstateClient estateClient,
TransactionResponseCode.ProductNotValidForMerchant);
}

// Check the amount
if (transactionAmount.HasValue){
if (transactionAmount <= 0){
throw new TransactionValidationException("Transaction Amount must be greater than 0", TransactionResponseCode.InvalidSaleTransactionAmount);
}

MerchantBalanceState merchantBalanceState = await this.MerchantBalanceStateRepository.Load(estateId, merchantId, cancellationToken);

// Check the merchant has enough balance to perform the sale
if (merchantBalanceState.AvailableBalance < transactionAmount){
throw new
TransactionValidationException($"Merchant [{merchant.MerchantName}] does not have enough credit available [{merchantBalanceState.AvailableBalance}] to perform transaction amount [{transactionAmount}]",
TransactionResponseCode.MerchantDoesNotHaveEnoughCredit);
}
}

// If we get here everything is good
return ("SUCCESS", TransactionResponseCode.Success);
}
Expand Down
6 changes: 4 additions & 2 deletions TransactionProcessor.IntegrationTests/Common/DockerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Client;
using EstateManagement.Client;
using EstateManagement.Database.Contexts;
using global::Shared.IntegrationTesting;
using SecurityService.Client;
using Retry = IntegrationTests.Retry;

/// <summary>
///
Expand Down Expand Up @@ -59,9 +61,9 @@ public DockerHelper() {
/// Starts the containers for scenario run.
/// </summary>
/// <param name="scenarioName">Name of the scenario.</param>
public override async Task StartContainersForScenarioRun(String scenarioName)
public override async Task StartContainersForScenarioRun(String scenarioName, DockerServices dockerServices)
{
await base.StartContainersForScenarioRun(scenarioName);
await base.StartContainersForScenarioRun(scenarioName, dockerServices);

// Setup the base address resolvers
String EstateManagementBaseAddressResolver(String api) => $"http://127.0.0.1:{this.EstateManagementPort}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public Contract GetContract(Guid contractId)
/// <returns></returns>
public Guid GetMerchantId(String merchantName)
{
if (merchantName == "InvalidMerchant")
if (merchantName == "InvalidMerchant" || this.EstateName == "InvalidEstate")
{
return Guid.Parse("D59320FA-4C3E-4900-A999-483F6A10C69A");
}
Expand Down
8 changes: 7 additions & 1 deletion TransactionProcessor.IntegrationTests/Common/GenericSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public async Task StartSystem()

this.TestingContext.Logger = logger;
this.TestingContext.Logger.LogInformation("About to Start Containers for Scenario Run");
await this.TestingContext.DockerHelper.StartContainersForScenarioRun(scenarioName).ConfigureAwait(false);

DockerServices dockerServices = DockerServices.CallbackHandler | DockerServices.EstateManagement | DockerServices.EventStore |
DockerServices.FileProcessor | DockerServices.MessagingService | DockerServices.SecurityService |
DockerServices.SqlServer | DockerServices.TestHost | DockerServices.TransactionProcessor |
DockerServices.TransactionProcessorAcl;

await this.TestingContext.DockerHelper.StartContainersForScenarioRun(scenarioName, dockerServices).ConfigureAwait(false);
this.TestingContext.Logger.LogInformation("Containers for Scenario Run Started");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Background:
Given I have created the following estates
| EstateName |
| Test Estate 1 |
| Test Estate 2 |

Given I have created the following operators
| EstateName | OperatorName | RequireCustomMerchantNumber | RequireCustomTerminalNumber |
Expand All @@ -34,17 +33,28 @@ Background:
| MerchantName | AddressLine1 | Town | Region | Country | ContactName | EmailAddress | EstateName |
| Test Merchant 1 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 1 | testcontact1@merchant1.co.uk | Test Estate 1 |
| Test Merchant 2 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 2 | testcontact2@merchant2.co.uk | Test Estate 1 |
| Test Merchant 3 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 3 | testcontact3@merchant2.co.uk | Test Estate 2 |
| Test Merchant 3 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 3 | testcontact3@merchant2.co.uk | Test Estate 1 |
| Test Merchant 4 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 4 | testcontact4@merchant2.co.uk | Test Estate 1 |
| Test Merchant 5 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 5 | testcontact5@merchant2.co.uk | Test Estate 1 |
| Test Merchant 6 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 6 | testcontact6@merchant2.co.uk | Test Estate 1 |
| Test Merchant 7 | Address Line 1 | TestTown | Test Region | United Kingdom | Test Contact 7 | testcontact7@merchant2.co.uk | Test Estate 1 |

Given I have assigned the following operator to the merchants
| OperatorName | MerchantName | MerchantNumber | TerminalNumber | EstateName |
| Test Operator 1 | Test Merchant 1 | 00000001 | 10000001 | Test Estate 1 |

Given I make the following manual merchant deposits
| Reference | Amount | DateTime | MerchantName | EstateName |
| Deposit1 | 2000.00 | Today | Test Merchant 1 | Test Estate 1 |
| Deposit1 | 1000.00 | Today | Test Merchant 2 | Test Estate 1 |
| Deposit1 | 1000.00 | Today | Test Merchant 3 | Test Estate 2 |
| Test Operator 1 | Test Merchant 2 | 00000001 | 10000001 | Test Estate 1 |
| Test Operator 1 | Test Merchant 3 | 00000001 | 10000001 | Test Estate 1 |
| Test Operator 1 | Test Merchant 4 | 00000001 | 10000001 | Test Estate 1 |
| Test Operator 1 | Test Merchant 5 | 00000001 | 10000001 | Test Estate 1 |
| Test Operator 1 | Test Merchant 6 | 00000001 | 10000001 | Test Estate 1 |
| Test Operator 1 | Test Merchant 7 | 00000001 | 10000001 | Test Estate 1 |

#Given I make the following manual merchant deposits
#| Reference | Amount | DateTime | MerchantName | EstateName |
#| Deposit1 | 2000.00 | Today | Test Merchant 1 | Test Estate 1 |
#| Deposit1 | 1000.00 | Today | Test Merchant 2 | Test Estate 1 |
#| Deposit1 | 1000.00 | Today | Test Merchant 3 | Test Estate 1 |
#| Deposit1 | 1000.00 | Today | Test Merchant 4 | Test Estate 1 |

@PRTest
Scenario: Logon Transactions
Expand All @@ -53,67 +63,46 @@ Scenario: Logon Transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName |
| Today | 1 | Logon | Test Merchant 1 | 123456780 | Test Estate 1 |
| Today | 2 | Logon | Test Merchant 2 | 123456781 | Test Estate 1 |
| Today | 3 | Logon | Test Merchant 3 | 123456782 | Test Estate 2 |
| Today | 3 | Logon | Test Merchant 3 | 123456782 | Test Estate 1 |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
| Test Estate 1 | Test Merchant 1 | 1 | 0001 | SUCCESS |
| Test Estate 1 | Test Merchant 2 | 2 | 0001 | SUCCESS |
| Test Estate 2 | Test Merchant 3 | 3 | 0001 | SUCCESS |

Scenario: Logon Transaction with Existing Device
| Test Estate 1 | Test Merchant 3 | 3 | 0001 | SUCCESS |

Given I have assigned the following devices to the merchants
| DeviceIdentifier | MerchantName | MerchantNumber | EstateName |
| 123456780 | Test Merchant 1 | 00000001 | Test Estate 1 |
| 123456783 | Test Merchant 4 | 00000001 | Test Estate 1 |

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName |
| Today | 1 | Logon | Test Merchant 1 | 123456780 | Test Estate 1 |
| Today | 4 | Logon | Test Merchant 4 | 123456783 | Test Estate 1 |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
| Test Estate 1 | Test Merchant 1 | 1 | 0000 | SUCCESS |

Scenario: Logon Transaction with Invalid Device

Given I have assigned the following devices to the merchants
| DeviceIdentifier | MerchantName | MerchantNumber | EstateName |
| 123456780 | Test Merchant 1 | 00000001 | Test Estate 1 |
| Test Estate 1 | Test Merchant 4 | 4 | 0000 | SUCCESS |

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName |
| Today | 1 | Logon | Test Merchant 1 | 123456781 | Test Estate 1 |
| Today | 5 | Logon | Test Merchant 1 | 13579135 | Test Estate 1 |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
| Test Estate 1 | Test Merchant 1 | 1 | 1000 | Device Identifier 123456781 not valid for Merchant Test Merchant 1 |

Scenario: Logon Transaction with Invalid Estate

Given I have assigned the following devices to the merchants
| DeviceIdentifier | MerchantName | MerchantNumber | EstateName |
| 123456780 | Test Merchant 1 | 00000001 | Test Estate 1 |
| Test Estate 1 | Test Merchant 1 | 5 | 1000 | Device Identifier 13579135 not valid for Merchant Test Merchant 1 |

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName |
| Today | 1 | Logon | Test Merchant 1 | 123456781 | InvalidEstate |
| Today | 6 | Logon | Test Merchant 1 | 123456785 | InvalidEstate |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
| InvalidEstate | Test Merchant 1 | 1 | 1001 | Estate Id [79902550-64df-4491-b0c1-4e78943928a3] is not a valid estate |

Scenario: Logon Transaction with Invalid Merchant

Given I have assigned the following devices to the merchants
| DeviceIdentifier | MerchantName | MerchantNumber | EstateName |
| 123456780 | Test Merchant 1 | 00000001 | Test Estate 1 |
| InvalidEstate | Test Merchant 1 | 6 | 1001 | Estate Id [79902550-64df-4491-b0c1-4e78943928a3] is not a valid estate |

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName |
| Today | 1 | Logon | InvalidMerchant | 123456781 | Test Estate 1 |
| Today | 7 | Logon | InvalidMerchant | 123456786 | Test Estate 1 |

Then transaction response should contain the following information
| EstateName | MerchantName | TransactionNumber | ResponseCode | ResponseMessage |
| Test Estate 1 | InvalidMerchant | 1 | 1002 | Merchant Id [d59320fa-4c3e-4900-a999-483f6a10c69a] is not a valid merchant for estate [Test Estate 1] |

| Test Estate 1 | InvalidMerchant | 7 | 1002 | Merchant Id [d59320fa-4c3e-4900-a999-483f6a10c69a] is not a valid merchant for estate [Test Estate 1] |
Loading