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 @@ -62,9 +62,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_TransactionIs
TestData.DeviceIdentifier,
CancellationToken.None);

response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.ResponseCode);
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
this.ValidateLogonResponse(response, TransactionResponseCode.Success);
}

[Fact]
Expand Down Expand Up @@ -105,9 +103,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithN
TestData.DeviceIdentifier,
CancellationToken.None);

response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.ResponseCode);
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
this.ValidateLogonResponse(response, TransactionResponseCode.Success);
}

[Fact]
Expand Down Expand Up @@ -148,9 +144,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithN
TestData.DeviceIdentifier,
CancellationToken.None);

response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.ResponseCode);
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
this.ValidateLogonResponse(response, TransactionResponseCode.Success);
}

[Fact]
Expand All @@ -168,7 +162,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_IncorrectDevi
transactionAggregateRepository.SetupSequence(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEmptyTransactionAggregate)
.ReturnsAsync(TestData.GetStartedTransactionAggregate)
.ReturnsAsync(TestData.GetLocallyAuthorisedTransactionAggregate)
.ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidDeviceIdentifier))
.ReturnsAsync(TestData.GetCompletedTransactionAggregate);
transactionAggregateRepository.Setup(t => t.SaveChanges(It.IsAny<TransactionAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

Expand All @@ -191,13 +185,11 @@ public async Task TransactionDomainService_ProcessLogonTransaction_IncorrectDevi
TestData.DeviceIdentifier1,
CancellationToken.None);

response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.ResponseCode);
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
this.ValidateLogonResponse(response, TransactionResponseCode.InvalidDeviceIdentifier);
}

[Fact]
public async Task TransactionDomainService_ProcessLogonTransaction_InvlaidEstate_TransactionIsProcessed()
public async Task TransactionDomainService_ProcessLogonTransaction_InvalidEstate_TransactionIsProcessed()
{
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);
Expand All @@ -211,7 +203,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_InvlaidEstate
transactionAggregateRepository.SetupSequence(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEmptyTransactionAggregate)
.ReturnsAsync(TestData.GetStartedTransactionAggregate)
.ReturnsAsync(TestData.GetLocallyAuthorisedTransactionAggregate)
.ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidEstateId))
.ReturnsAsync(TestData.GetCompletedTransactionAggregate);
transactionAggregateRepository.Setup(t => t.SaveChanges(It.IsAny<TransactionAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

Expand All @@ -234,10 +226,63 @@ public async Task TransactionDomainService_ProcessLogonTransaction_InvlaidEstate
TestData.DeviceIdentifier1,
CancellationToken.None);

response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.ResponseCode);
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
this.ValidateLogonResponse(response, TransactionResponseCode.InvalidEstateId);
}

[Fact]
public async Task TransactionDomainService_ProcessLogonTransaction_InvalidMerchant_TransactionIsProcessed()
{
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);

Logger.Initialise(NullLogger.Instance);

Mock<IAggregateRepositoryManager> aggregateRepositoryManager = new Mock<IAggregateRepositoryManager>();
Mock<IAggregateRepository<TransactionAggregate>> transactionAggregateRepository = new Mock<IAggregateRepository<TransactionAggregate>>();

aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<TransactionAggregate>(It.IsAny<Guid>())).Returns(transactionAggregateRepository.Object);
transactionAggregateRepository.SetupSequence(t => t.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEmptyTransactionAggregate)
.ReturnsAsync(TestData.GetStartedTransactionAggregate)
.ReturnsAsync(TestData.GetLocallyDeclinedTransactionAggregate(TransactionResponseCode.InvalidMerchantId))
.ReturnsAsync(TestData.GetCompletedTransactionAggregate);
transactionAggregateRepository.Setup(t => t.SaveChanges(It.IsAny<TransactionAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

securityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.TokenResponse);
estateClient.Setup(e => e.GetEstate(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.GetEstateResponse);
estateClient.Setup(e => e.GetMerchant(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEmptyMerchantResponse);

TransactionDomainService transactionDomainService =
new TransactionDomainService(aggregateRepositoryManager.Object, estateClient.Object, securityServiceClient.Object);

ProcessLogonTransactionResponse response = await transactionDomainService.ProcessLogonTransaction(TestData.TransactionId,
TestData.EstateId,
TestData.MerchantId,
TestData.TransactionDateTime,
TestData.TransactionNumber,
TestData.DeviceIdentifier1,
CancellationToken.None);

this.ValidateLogonResponse(response, TransactionResponseCode.InvalidMerchantId);
}

private void ValidateLogonResponse(ProcessLogonTransactionResponse response,
TransactionResponseCode transactionResponseCode)
{
response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.GetResponseCodeAsString(transactionResponseCode));

String messageToValidate = TestData.GetResponseCodeMessage(transactionResponseCode);
if (transactionResponseCode == TransactionResponseCode.Success)
{
messageToValidate = messageToValidate.ToUpper();
}

response.ResponseMessage.ShouldBe(messageToValidate);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DebugType>None</DebugType>
<DebugType>Full</DebugType>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,19 @@ public async Task<ProcessLogonTransactionResponse> ProcessLogonTransaction(Guid
// TODO: Remove this once GetEstate returns correct response when estate not found
if (estate.EstateName == null)
{






throw new TransactionValidationException($"Estate Id [{estateId}] is not a valid estate", TransactionResponseCode.InvalidEstateId);
}

// get the merchant record and validate the device
// TODO: Token
MerchantResponse merchant = await this.EstateClient.GetMerchant(token.AccessToken, estateId, merchantId, cancellationToken);

// TODO: Remove this once GetMerchant returns correct response when merchant not found
if (merchant.MerchantName == null)
{
throw new TransactionValidationException($"Merchant Id [{merchantId}] is not a valid merchant for estate [{estate.EstateName}]", TransactionResponseCode.InvalidMerchantId);
}

if (merchant.Devices == null || merchant.Devices.Any() == false)
{
// Add the device to the merchant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum TransactionResponseCode
Success = 0,

InvalidDeviceIdentifier = 1000,
InvalidEstateId = 1001
InvalidEstateId = 1001,
InvalidMerchantId = 1002
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public void AddMerchant(Guid merchantId,

public Guid GetMerchantId(String merchantName)
{
if (merchantName == "InvalidMerchant")
{
return Guid.Parse("D59320FA-4C3E-4900-A999-483F6A10C69A");
}

return this.Merchants.Single(m => m.Key == merchantName).Value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,17 @@ Scenario: Logon Transaction with Invalid Estate
| 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 |

When I perform the following transactions
| DateTime | TransactionNumber | TransactionType | MerchantName | DeviceIdentifier | EstateName |
| Today | 1 | Logon | InvalidMerchant | 123456781 | 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] |

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading