Skip to content

Commit b1508aa

Browse files
Merge pull request #295 from TransactionProcessing/task/#280_use_results
project converted to result flows
2 parents b1d3f8b + 79f4588 commit b1508aa

34 files changed

+411
-1116
lines changed

.github/workflows/createrelease.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
zip -r ../transactionprocessoracl.zip ./*
5757
5858
- name: Upload the artifact
59-
uses: actions/upload-artifact@v3
59+
uses: actions/upload-artifact@v4.4.0
6060
with:
6161
name: transactionprocessoracl
6262
path: transactionprocessoracl.zip
@@ -108,7 +108,7 @@ jobs:
108108

109109
steps:
110110
- name: Download the artifact
111-
uses: actions/download-artifact@v3
111+
uses: actions/download-artifact@v4.1.8
112112
with:
113113
name: transactionprocessoracl
114114

.github/workflows/pullrequest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Run Integration Tests
3535
run: dotnet test "TransactionProcessorACL.IntegrationTests\TransactionProcessorACL.IntegrationTests.csproj" --filter Category=PRTest
3636

37-
- uses: actions/upload-artifact@v2
37+
- uses: actions/upload-artifact@v4.4.0
3838
if: ${{ failure() }}
3939
with:
4040
name: tracelogs

TransactionProcessorACL.BusinessLogic.Tests/MediatorTests.cs

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Linq;
1111
using System.Text;
1212
using System.Threading.Tasks;
13+
using SimpleResults;
1314
using TransactionProcessorACL.Testing;
1415
using Xunit;
1516

@@ -26,12 +27,12 @@ public class MediatorTests
2627

2728
public MediatorTests()
2829
{
29-
this.Requests.Add(TestData.ProcessLogonTransactionRequest);
30-
this.Requests.Add(TestData.ProcessReconciliationRequest);
31-
this.Requests.Add(TestData.ProcessSaleTransactionRequest);
32-
this.Requests.Add(TestData.VersionCheckRequest);
33-
this.Requests.Add(TestData.GetVoucherRequest);
34-
this.Requests.Add(TestData.RedeemVoucherRequest);
30+
this.Requests.Add(TestData.ProcessLogonTransactionCommand);
31+
this.Requests.Add(TestData.ProcessReconciliationCommand);
32+
this.Requests.Add(TestData.ProcessSaleTransactionCommand);
33+
this.Requests.Add(TestData.VersionCheckCommand);
34+
this.Requests.Add(TestData.GetVoucherQuery);
35+
this.Requests.Add(TestData.RedeemVoucherCommand);
3536
}
3637

3738
[Fact]
@@ -99,38 +100,32 @@ private void AddTestRegistrations(ServiceRegistry services,
99100

100101
public class DummyTransactionProcessorACLApplicationService : ITransactionProcessorACLApplicationService
101102
{
102-
public async Task<ProcessLogonTransactionResponse> ProcessLogonTransaction(Guid estateId,
103-
Guid merchantId,
104-
DateTime transactionDateTime,
105-
String transactionNumber,
106-
String deviceIdentifier,
107-
CancellationToken cancellationToken) {
108-
return new ProcessLogonTransactionResponse();
109-
}
110-
111-
public async Task<ProcessSaleTransactionResponse> ProcessSaleTransaction(Guid estateId,
112-
Guid merchantId,
113-
DateTime transactionDateTime,
114-
String transactionNumber,
115-
String deviceIdentifier,
116-
Guid operatorId,
117-
String customerEmailAddress,
118-
Guid contractId,
119-
Guid productId,
120-
Dictionary<String, String> additionalRequestMetadata,
121-
CancellationToken cancellationToken) {
122-
return new ProcessSaleTransactionResponse();
123-
}
124-
125-
public async Task<ProcessReconciliationResponse> ProcessReconciliation(Guid estateId,
126-
Guid merchantId,
127-
DateTime transactionDateTime,
128-
String deviceIdentifier,
129-
Int32 transactionCount,
130-
Decimal transactionValue,
131-
CancellationToken cancellationToken) {
132-
return new ProcessReconciliationResponse();
133-
}
103+
public async Task<Result<ProcessLogonTransactionResponse>> ProcessLogonTransaction(Guid estateId,
104+
Guid merchantId,
105+
DateTime transactionDateTime,
106+
String transactionNumber,
107+
String deviceIdentifier,
108+
CancellationToken cancellationToken) => Result.Success(new ProcessLogonTransactionResponse());
109+
110+
public async Task<Result<ProcessSaleTransactionResponse>> ProcessSaleTransaction(Guid estateId,
111+
Guid merchantId,
112+
DateTime transactionDateTime,
113+
String transactionNumber,
114+
String deviceIdentifier,
115+
Guid operatorId,
116+
String customerEmailAddress,
117+
Guid contractId,
118+
Guid productId,
119+
Dictionary<String, String> additionalRequestMetadata,
120+
CancellationToken cancellationToken) => Result.Success(new ProcessSaleTransactionResponse());
121+
122+
public async Task<Result<ProcessReconciliationResponse>> ProcessReconciliation(Guid estateId,
123+
Guid merchantId,
124+
DateTime transactionDateTime,
125+
String deviceIdentifier,
126+
Int32 transactionCount,
127+
Decimal transactionValue,
128+
CancellationToken cancellationToken) => Result.Success(new ProcessReconciliationResponse());
134129

135130
public async Task<GetVoucherResponse> GetVoucher(Guid estateId,
136131
Guid contractId,

TransactionProcessorACL.BusinessLogic.Tests/RequestHandlerTests.cs

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using SimpleResults;
2+
13
namespace TransactionProcessorACL.BusinesssLogic.Tests
24
{
35
using System;
@@ -15,6 +17,7 @@ namespace TransactionProcessorACL.BusinesssLogic.Tests
1517
using Shouldly;
1618
using Testing;
1719
using Xunit;
20+
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
1821

1922
/// <summary>
2023
///
@@ -51,16 +54,17 @@ public async Task ProcessLogonTransactionRequestHandler_Handle_RequestIsHandled(
5154
It.IsAny<String>(),
5255
It.IsAny<String>(),
5356
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ProcessLogonTransactionResponse);
54-
ProcessLogonTransactionRequestHandler requestHandler = new ProcessLogonTransactionRequestHandler(applicationService.Object);
57+
TransactionRequestHandler requestHandler = new TransactionRequestHandler(applicationService.Object);
5558

56-
ProcessLogonTransactionRequest request = TestData.ProcessLogonTransactionRequest;
57-
ProcessLogonTransactionResponse response = await requestHandler.Handle(request, CancellationToken.None);
59+
TransactionCommands.ProcessLogonTransactionCommand command = TestData.ProcessLogonTransactionCommand;
60+
Result<ProcessLogonTransactionResponse> result = await requestHandler.Handle(command, CancellationToken.None);
5861

59-
response.ShouldNotBeNull();
60-
response.ResponseCode.ShouldBe(TestData.ResponseCode);
61-
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
62-
response.EstateId.ShouldBe(TestData.EstateId);
63-
response.MerchantId.ShouldBe(TestData.MerchantId);
62+
result.IsSuccess.ShouldBeTrue();
63+
result.Data.ShouldNotBeNull();
64+
result.Data.ResponseCode.ShouldBe(TestData.ResponseCode);
65+
result.Data.ResponseMessage.ShouldBe(TestData.ResponseMessage);
66+
result.Data.EstateId.ShouldBe(TestData.EstateId);
67+
result.Data.MerchantId.ShouldBe(TestData.MerchantId);
6468
}
6569

6670
[Fact]
@@ -80,14 +84,15 @@ public async Task ProcessSaleTransactionRequestHandler_Handle_RequestIsHandled()
8084
It.IsAny<Dictionary<String,String>>(),
8185
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ProcessSaleTransactionResponse);
8286

83-
ProcessSaleTransactionRequestHandler requestHandler = new ProcessSaleTransactionRequestHandler(applicationService.Object);
87+
TransactionRequestHandler requestHandler = new TransactionRequestHandler(applicationService.Object);
8488

85-
ProcessSaleTransactionRequest request = TestData.ProcessSaleTransactionRequest;
86-
ProcessSaleTransactionResponse response = await requestHandler.Handle(request, CancellationToken.None);
89+
TransactionCommands.ProcessSaleTransactionCommand command = TestData.ProcessSaleTransactionCommand;
90+
Result<ProcessSaleTransactionResponse> result = await requestHandler.Handle(command, CancellationToken.None);
8791

88-
response.ShouldNotBeNull();
89-
response.ResponseCode.ShouldBe(TestData.ResponseCode);
90-
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
92+
result.IsSuccess.ShouldBeTrue();
93+
result.Data.ShouldNotBeNull();
94+
result.Data.ResponseCode.ShouldBe(TestData.ResponseCode);
95+
result.Data.ResponseMessage.ShouldBe(TestData.ResponseMessage);
9196
}
9297

9398
[Fact]
@@ -102,52 +107,48 @@ public async Task ProcessReconciliationRequestHandler_Handle_RequestIsHandled()
102107
It.IsAny<Int32>(),
103108
It.IsAny<Decimal>(),
104109
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ProcessReconciliationResponse);
105-
ProcessReconciliationRequestHandler requestHandler = new ProcessReconciliationRequestHandler(applicationService.Object);
110+
TransactionRequestHandler requestHandler = new TransactionRequestHandler(applicationService.Object);
106111

107-
ProcessReconciliationRequest request = TestData.ProcessReconciliationRequest;
108-
ProcessReconciliationResponse response = await requestHandler.Handle(request, CancellationToken.None);
112+
TransactionCommands.ProcessReconciliationCommand command = TestData.ProcessReconciliationCommand;
113+
Result<ProcessReconciliationResponse> result = await requestHandler.Handle(command, CancellationToken.None);
109114

110-
response.ShouldNotBeNull();
111-
response.ResponseCode.ShouldBe(TestData.ResponseCode);
112-
response.ResponseMessage.ShouldBe(TestData.ResponseMessage);
113-
response.EstateId.ShouldBe(TestData.EstateId);
114-
response.MerchantId.ShouldBe(TestData.MerchantId);
115+
result.IsSuccess.ShouldBeTrue();
116+
result.Data.ShouldNotBeNull();
117+
result.Data.ResponseCode.ShouldBe(TestData.ResponseCode);
118+
result.Data.ResponseMessage.ShouldBe(TestData.ResponseMessage);
119+
result.Data.EstateId.ShouldBe(TestData.EstateId);
120+
result.Data.MerchantId.ShouldBe(TestData.MerchantId);
115121
}
116122

117123
[Fact]
118124
public async Task VersionCheckRequestHandler_Handle_RequestIsHandled()
119125
{
120126
VersionCheckRequestHandler requestHandler = new VersionCheckRequestHandler();
121127

122-
VersionCheckRequest request = TestData.VersionCheckRequest;
123-
Should.NotThrow(async () =>
124-
{
125-
await requestHandler.Handle(request, CancellationToken.None);
126-
});
128+
VersionCheckCommands.VersionCheckCommand command = TestData.VersionCheckCommand;
129+
var result = await requestHandler.Handle(command, CancellationToken.None);
130+
result.IsSuccess.ShouldBeTrue();
127131
}
128132

129133
[Fact]
130134
public async Task VersionCheckRequestHandler_Handle_OldVersion_ErrorThrown()
131135
{
132136
VersionCheckRequestHandler requestHandler = new VersionCheckRequestHandler();
133-
134-
VersionCheckRequest request = VersionCheckRequest.Create(TestData.OldApplicationVersion);
135-
Should.Throw<VersionIncompatibleException>(async () =>
136-
{
137-
await requestHandler.Handle(request, CancellationToken.None);
138-
});
137+
138+
VersionCheckCommands.VersionCheckCommand command = new(TestData.OldApplicationVersion);
139+
var result = await requestHandler.Handle(command, CancellationToken.None);
140+
result.IsFailed.ShouldBeTrue();
141+
result.Status.ShouldBe(ResultStatus.Conflict);
139142
}
140143

141144
[Fact]
142145
public async Task VersionCheckRequestHandler_Handle_NewerVersionBuildNumber_RequestIsHandled()
143146
{
144147
VersionCheckRequestHandler requestHandler = new VersionCheckRequestHandler();
145-
146-
VersionCheckRequest request = VersionCheckRequest.Create(TestData.NewerApplicationVersion);
147-
Should.NotThrow(async () =>
148-
{
149-
await requestHandler.Handle(request, CancellationToken.None);
150-
});
148+
149+
VersionCheckCommands.VersionCheckCommand command = new(TestData.NewerApplicationVersion);
150+
var result = await requestHandler.Handle(command, CancellationToken.None);
151+
result.IsSuccess.ShouldBeTrue(); ;
151152
}
152153

153154
[Fact]
@@ -158,7 +159,7 @@ public async Task VoucherRequestHandler_GetVoucherRequest_Handle_RequestIsHandle
158159

159160
Should.NotThrow(async () =>
160161
{
161-
await requestHandler.Handle(TestData.GetVoucherRequest, CancellationToken.None);
162+
await requestHandler.Handle(TestData.GetVoucherQuery, CancellationToken.None);
162163
});
163164
}
164165

@@ -170,7 +171,7 @@ public async Task VoucherRequestHandler_RedeemVoucherRequest_Handle_RequestIsHan
170171

171172
Should.NotThrow(async () =>
172173
{
173-
await requestHandler.Handle(TestData.RedeemVoucherRequest, CancellationToken.None);
174+
await requestHandler.Handle(TestData.RedeemVoucherCommand, CancellationToken.None);
174175
});
175176
}
176177

0 commit comments

Comments
 (0)