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
25 changes: 25 additions & 0 deletions TransactionProcessorACL.BusinessLogic.Tests/RequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ public async Task ProcessLogonTransactionRequestHandler_Handle_RequestIsHandled(
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
}

[Fact]
public async Task ProcessSaleTransactionRequestHandler_Handle_RequestIsHandled()
{
Mock<ITransactionProcessorACLApplicationService> applicationService = new Mock<ITransactionProcessorACLApplicationService>();
applicationService
.Setup(a => a.ProcessSaleTransaction(It.IsAny<Guid>(),
It.IsAny<Guid>(),
It.IsAny<DateTime>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Decimal>(),
It.IsAny<String>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ProcessSaleTransactionResponse);

ProcessSaleTransactionRequestHandler requestHandler = new ProcessSaleTransactionRequestHandler(applicationService.Object);

ProcessSaleTransactionRequest request = TestData.ProcessSaleTransactionRequest;
ProcessSaleTransactionResponse response = await requestHandler.Handle(request, CancellationToken.None);

response.ShouldNotBeNull();
response.ResponseCode.ShouldBe(TestData.ResponseCode);
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
}

#endregion
}
}
22 changes: 22 additions & 0 deletions TransactionProcessorACL.BusinessLogic.Tests/RequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ public void ProcessLogonTransactionRequest_CanBeCreated_IsCreated()
request.RequireConfigurationInResponse.ShouldBe(TestData.RequireConfigurationInResponseTrue);
}

[Fact]
public void ProcessSaleTransactionRequest_CanBeCreated_IsCreated()
{
ProcessSaleTransactionRequest request = ProcessSaleTransactionRequest.Create(TestData.EstateId,
TestData.MerchantId,
TestData.TransactionDateTime,
TestData.TransactionNumber,
TestData.DeviceIdentifier,
TestData.OperatorIdentifier,
TestData.SaleAmount,
TestData.CustomerAccountNumber);

request.EstateId.ShouldBe(TestData.EstateId);
request.MerchantId.ShouldBe(TestData.MerchantId);
request.TransactionDateTime.ShouldBe(TestData.TransactionDateTime);
request.TransactionNumber.ShouldBe(TestData.TransactionNumber);
request.DeviceIdentifier.ShouldBe(TestData.DeviceIdentifier);
request.OperatorIdentifier.ShouldBe(TestData.OperatorIdentifier);
request.Amount.ShouldBe(TestData.SaleAmount);
request.CustomerAccountNumber.ShouldBe(TestData.CustomerAccountNumber);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,92 @@ public async Task TransactionProcessorACLApplicationService_ProcessLogonTransact
logonResponse.ResponseMessage.ShouldBe(TestData.ResponseMessage);
logonResponse.ResponseCode.ShouldBe(TestData.ResponseCode);
}

[Fact]
public async Task TransactionProcessorACLApplicationService_ProcessLogonTransaction_ErrorInLogon_TransactionIsNotSuccessful()
{
IConfigurationRoot configuration = this.SetupMemoryConfiguration();
ConfigurationReader.Initialise(configuration);

Mock<ITransactionProcessorClient> transactionProcessorClient = new Mock<ITransactionProcessorClient>();
transactionProcessorClient.Setup(t => t.PerformTransaction(It.IsAny<String>(), It.IsAny<SerialisedMessage>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception("Error", new InvalidOperationException(TestData.ErrorResponseMessage)));
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
securityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.TokenResponse);

ITransactionProcessorACLApplicationService applicationService =
new TransactionProcessorACLApplicationService(transactionProcessorClient.Object, securityServiceClient.Object);

ProcessLogonTransactionResponse logonResponse = await applicationService.ProcessLogonTransaction(TestData.EstateId,
TestData.MerchantId,
TestData.TransactionDateTime,
TestData.TransactionNumber,
TestData.DeviceIdentifier,
CancellationToken.None);

logonResponse.ShouldNotBeNull();
logonResponse.ResponseMessage.ShouldBe(TestData.ErrorResponseMessage);
logonResponse.ResponseCode.ShouldBe(TestData.ErrorResponseCode);
}

[Fact]
public async Task TransactionProcessorACLApplicationService_ProcessSaleTransaction_TransactionIsSuccessful()
{
IConfigurationRoot configuration = this.SetupMemoryConfiguration();
ConfigurationReader.Initialise(configuration);

Mock<ITransactionProcessorClient> transactionProcessorClient = new Mock<ITransactionProcessorClient>();
transactionProcessorClient.Setup(t => t.PerformTransaction(It.IsAny<String>(), It.IsAny<SerialisedMessage>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.SerialisedMessageResponse);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
securityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.TokenResponse);

ITransactionProcessorACLApplicationService applicationService =
new TransactionProcessorACLApplicationService(transactionProcessorClient.Object, securityServiceClient.Object);

ProcessSaleTransactionResponse saleResponse = await applicationService.ProcessSaleTransaction(TestData.EstateId,
TestData.MerchantId,
TestData.TransactionDateTime,
TestData.TransactionNumber,
TestData.DeviceIdentifier,
TestData.OperatorIdentifier,
TestData.SaleAmount,
TestData.CustomerAccountNumber,
CancellationToken.None);

saleResponse.ShouldNotBeNull();
saleResponse.ResponseMessage.ShouldBe(TestData.ResponseMessage);
saleResponse.ResponseCode.ShouldBe(TestData.ResponseCode);
}

[Fact]
public async Task TransactionProcessorACLApplicationService_ProcessSaleTransaction_ErrorInSale_TransactionIsNotSuccessful()
{
IConfigurationRoot configuration = this.SetupMemoryConfiguration();
ConfigurationReader.Initialise(configuration);

Mock<ITransactionProcessorClient> transactionProcessorClient = new Mock<ITransactionProcessorClient>();
transactionProcessorClient.Setup(t => t.PerformTransaction(It.IsAny<String>(), It.IsAny<SerialisedMessage>(), It.IsAny<CancellationToken>()))
.ThrowsAsync(new Exception("Error", new InvalidOperationException(TestData.ErrorResponseMessage)));
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
securityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.TokenResponse);

ITransactionProcessorACLApplicationService applicationService =
new TransactionProcessorACLApplicationService(transactionProcessorClient.Object, securityServiceClient.Object);

ProcessSaleTransactionResponse saleResponse = await applicationService.ProcessSaleTransaction(TestData.EstateId,
TestData.MerchantId,
TestData.TransactionDateTime,
TestData.TransactionNumber,
TestData.DeviceIdentifier,
TestData.OperatorIdentifier,
TestData.SaleAmount,
TestData.CustomerAccountNumber,
CancellationToken.None);

saleResponse.ShouldNotBeNull();
saleResponse.ResponseMessage.ShouldBe(TestData.ErrorResponseMessage);
saleResponse.ResponseCode.ShouldBe(TestData.ErrorResponseCode);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ private ProcessLogonTransactionRequest(Guid estateId,
this.TransactionDateTime = transactionDateTime;
this.TransactionNumber = transactionNumber;
}

public ProcessLogonTransactionRequest()
{
// This constructor is only required for IoC tests :|
}

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ private ProcessSaleTransactionRequest(Guid estateId,
this.TransactionDateTime = transactionDateTime;
this.TransactionNumber = transactionNumber;
}

public ProcessSaleTransactionRequest()
{
// This constructor is only required for IoC tests :|
}


#endregion

#region Properties
Expand Down
25 changes: 23 additions & 2 deletions TransactionProcessorACL.Testing/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public class TestData
TestData.RequireConfigurationInResponseTrue);

public static String ResponseCode = "0000";
public static String ErrorResponseCode = "0001";

public static String ResponseMessage = "SUCCESS";
public static String ErrorResponseMessage = "ERROR";

public static ProcessLogonTransactionResponse ProcessLogonTransactionResponse = new ProcessLogonTransactionResponse
{
Expand All @@ -96,7 +98,26 @@ public class TestData
public static String Token = "{\"access_token\": \"eyJhbGciOiJSUzI1NiIsImtpZCI6IjA4NGZlNTIwZmIzZmVhM2M0MmNmMjBiZWM2OGY1NDg2IiwidHlwIjoiYXQrand0In0.eyJuYmYiOjE1Nzc1NTIyMTQsImV4cCI6MTU3NzU1NTgxNCwiaXNzIjoiaHR0cDovLzE5Mi4xNjguMS4xMzM6NTAwMSIsImF1ZCI6WyJlc3RhdGVNYW5hZ2VtZW50IiwidHJhbnNhY3Rpb25Qcm9jZXNzb3IiLCJ0cmFuc2FjdGlvblByb2Nlc3NvckFDTCJdLCJjbGllbnRfaWQiOiJzZXJ2aWNlQ2xpZW50Iiwic2NvcGUiOlsiZXN0YXRlTWFuYWdlbWVudCIsInRyYW5zYWN0aW9uUHJvY2Vzc29yIiwidHJhbnNhY3Rpb25Qcm9jZXNzb3JBQ0wiXX0.JxK6kEvmvuMnL7ktgvv6N52fjqnFG-NSjPcQORIcFb4ravZAk5oNgsnEtjPcOHTXiktcr8i361GlYO1yiSGdfLKtCTaH3lihcbOb1wfQh3bYM_xmlqJUdirerR8ql9lxqBqm2_Q__PDFuFhMd9lAz-iFr3svuOXeQJB5HQ2rtA3xBDDked5SaEs1dMfbBJA6svRq831WCQSJgap2Db7XN7ais7AQhPYUcFOTGs9Qk33rF_k-2dnAzkEITjvgPwim-8YsEQfsbRYgZmIXfjOXcD81Y0G2_grugvc0SOj_hKXd4d62T-zU-mC4opuYauWKYFqV4UB4sf4V4rtLWeDWrA\",\"expires_in\": 3600,\"token_type\": \"Bearer\",\"scope\": \"estateManagement transactionProcessor transactionProcessorACL\"}";

public static TokenResponse TokenResponse = TokenResponse.Create(TestData.Token);



public static ProcessSaleTransactionResponse ProcessSaleTransactionResponse = new ProcessSaleTransactionResponse
{
ResponseMessage = TestData.ResponseMessage,
ResponseCode = TestData.ResponseCode
};

public static String OperatorIdentifier = "Operator1";

public static Decimal SaleAmount = 1000.00m;

public static String CustomerAccountNumber = "123456789";

public static ProcessSaleTransactionRequest ProcessSaleTransactionRequest = ProcessSaleTransactionRequest.Create(TestData.EstateId,
TestData.MerchantId,
TestData.TransactionDateTime,
TestData.TransactionNumber,
TestData.DeviceIdentifier,
TestData.OperatorIdentifier,
TestData.SaleAmount,
TestData.CustomerAccountNumber);
}
}
26 changes: 26 additions & 0 deletions TransactionProcessorACL.Tests/General/ModelFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,31 @@ public void ModelFactory_ConvertFrom_ProcessLogonTransactionResponse_NullValue_I

response.ShouldBeNull();
}

[Fact]
public void ModelFactory_ConvertFrom_ProcessSaleTransactionResponse_IsConverted()
{
ModelFactory modelFactory = new ModelFactory();

ProcessSaleTransactionResponse processSaleTransactionResponse = TestData.ProcessSaleTransactionResponse;

SaleTransactionResponseMessage response = modelFactory.ConvertFrom(processSaleTransactionResponse);

response.ShouldNotBeNull();
response.ResponseMessage.ShouldBe(processSaleTransactionResponse.ResponseMessage);
response.ResponseCode.ShouldBe(processSaleTransactionResponse.ResponseCode);
}

[Fact]
public void ModelFactory_ConvertFrom_ProcessSaleTransactionResponse_NullValue_IsConverted()
{
ModelFactory modelFactory = new ModelFactory();

ProcessSaleTransactionResponse processSaleTransactionResponse = null;

SaleTransactionResponseMessage response = modelFactory.ConvertFrom(processSaleTransactionResponse);

response.ShouldBeNull();
}
}
}