Skip to content

Commit ced77fb

Browse files
Merge pull request #19 from StuartFerguson/task/#18_transactionprocessorclient
Task/#18 transactionprocessorclient
2 parents edf2573 + 5e36870 commit ced77fb

File tree

8 files changed

+158
-14
lines changed

8 files changed

+158
-14
lines changed

.github/workflows/createrelease.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,9 @@ jobs:
118118
with:
119119
dotnet-version: 3.0.100
120120

121+
- name: Build and Publish Nuget Packages
122+
run: |
123+
dotnet pack "TransactionProcessor.Client\TransactionProcessor.Client.csproj" /p:PackageVersion=${{ steps.get_version.outputs.VERSION }} --output Nugets
124+
dotnet nuget push Nugets/TransactionProcessor.Client.${{ steps.get_version.outputs.VERSION }}.nupkg --api-key ${{ secrets.MYGET_APIKEY }} --source https://www.myget.org/F/transactionprocessing/api/v2/package
125+
126+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace TransactionProcessor.Client
2+
{
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using DataTransferObjects;
6+
7+
public interface ITransactionProcessorClient
8+
{
9+
#region Methods
10+
11+
/// <summary>
12+
/// Performs the transaction.
13+
/// </summary>
14+
/// <param name="transactionRequest">The transaction request.</param>
15+
/// <param name="cancellationToken">The cancellation token.</param>
16+
/// <returns></returns>
17+
Task<SerialisedMessage> PerformTransaction(SerialisedMessage transactionRequest,
18+
CancellationToken cancellationToken);
19+
20+
#endregion
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="ClientProxyBase" Version="0.0.4.1" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj" />
14+
</ItemGroup>
15+
16+
<Target Name="IncludeP2PAssets">
17+
<ItemGroup>
18+
<BuildOutputInPackage Include="$(OutputPath)TransactionProcessor.DataTransferObjects.dll" />
19+
</ItemGroup>
20+
</Target>
21+
22+
</Project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
namespace TransactionProcessor.Client
2+
{
3+
using System;
4+
using System.Net.Http;
5+
using System.Text;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using ClientProxyBase;
9+
using DataTransferObjects;
10+
using Newtonsoft.Json;
11+
12+
/// <summary>
13+
///
14+
/// </summary>
15+
/// <seealso cref="ClientProxyBase.ClientProxyBase" />
16+
/// <seealso cref="TransactionProcessor.Client.ITransactionProcessorClient" />
17+
public class TransactionProcessorClient : ClientProxyBase, ITransactionProcessorClient
18+
{
19+
#region Fields
20+
21+
/// <summary>
22+
/// The base address
23+
/// </summary>
24+
private readonly String BaseAddress;
25+
26+
#endregion
27+
28+
#region Constructors
29+
30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="TransactionProcessorClient" /> class.
32+
/// </summary>
33+
/// <param name="baseAddressResolver">The base address resolver.</param>
34+
/// <param name="httpClient">The HTTP client.</param>
35+
public TransactionProcessorClient(Func<String, String> baseAddressResolver,
36+
HttpClient httpClient) : base(httpClient)
37+
{
38+
this.BaseAddress = baseAddressResolver("TransactionProcessorApi");
39+
40+
// Add the API version header
41+
this.HttpClient.DefaultRequestHeaders.Add("api-version", "1.0");
42+
}
43+
44+
#endregion
45+
46+
#region Methods
47+
48+
/// <summary>
49+
/// Performs the transaction.
50+
/// </summary>
51+
/// <param name="transactionRequest">The transaction request.</param>
52+
/// <param name="cancellationToken">The cancellation token.</param>
53+
/// <returns></returns>
54+
public async Task<SerialisedMessage> PerformTransaction(SerialisedMessage transactionRequest,
55+
CancellationToken cancellationToken)
56+
{
57+
SerialisedMessage response = null;
58+
59+
String requestUri = $"{this.BaseAddress}/api/transactions";
60+
61+
try
62+
{
63+
String requestSerialised = JsonConvert.SerializeObject(transactionRequest);
64+
65+
StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
66+
67+
// Add the access token to the client headers
68+
//this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
69+
70+
// Make the Http Call here
71+
HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);
72+
73+
// Process the response
74+
String content = await this.HandleResponse(httpResponse, cancellationToken);
75+
76+
// call was successful so now deserialise the body to the response object
77+
response = JsonConvert.DeserializeObject<SerialisedMessage>(content);
78+
}
79+
catch(Exception ex)
80+
{
81+
// An exception has occurred, add some additional information to the message
82+
Exception exception = new Exception("Error posting transaction.", ex);
83+
84+
throw exception;
85+
}
86+
87+
return response;
88+
}
89+
90+
#endregion
91+
}
92+
}

TransactionProcessor.IntegrationTests/Common/DockerHelper.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Net.Http;
66
using System.Threading.Tasks;
7+
using Client;
78
using Ductus.FluentDocker.Builders;
89
using Ductus.FluentDocker.Model.Builders;
910
using Ductus.FluentDocker.Services;
@@ -23,7 +24,8 @@ public class DockerHelper
2324
protected IContainerService EventStoreContainer;
2425

2526
public IEstateClient EstateClient;
26-
public HttpClient HttpClient;
27+
public ITransactionProcessorClient TransactionProcessorClient;
28+
//public HttpClient HttpClient;
2729

2830
protected String EventStoreConnectionString;
2931

@@ -86,10 +88,11 @@ public async Task StartContainersForScenarioRun(String scenarioName)
8688

8789
HttpClient httpClient = new HttpClient();
8890
this.EstateClient = new EstateClient(estateManagementBaseAddressResolver, httpClient);
91+
this.TransactionProcessorClient = new TransactionProcessorClient(transactionProcessorBaseAddressResolver, httpClient);
8992

9093
// TODO: Use this to talk to txn processor until we have a client
91-
this.HttpClient = new HttpClient();
92-
this.HttpClient.BaseAddress = new Uri(transactionProcessorBaseAddressResolver(String.Empty));
94+
//this.HttpClient = new HttpClient();
95+
//this.HttpClient.BaseAddress = new Uri(transactionProcessorBaseAddressResolver(String.Empty));
9396
}
9497

9598
public async Task StopContainersForScenarioRun()

TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,9 @@ private async Task PerformLogonTransaction(Guid estateId, Guid merchantId, DateT
256256
TypeNameHandling = TypeNameHandling.All
257257
});
258258

259-
String uri = "api/transactions";
260-
261-
StringContent content = new StringContent(JsonConvert.SerializeObject(serialisedMessage), Encoding.UTF8, "application/json");
262-
263-
HttpResponseMessage response = await this.TestingContext.DockerHelper.HttpClient.PostAsync(uri, content, cancellationToken);
264-
265-
response.IsSuccessStatusCode.ShouldBeTrue();
266-
267-
SerialisedMessage responseSerialisedMessage = JsonConvert.DeserializeObject<SerialisedMessage>(await response.Content.ReadAsStringAsync());
268-
259+
SerialisedMessage responseSerialisedMessage = await this.TestingContext.DockerHelper.TransactionProcessorClient.PerformTransaction(serialisedMessage, cancellationToken);
260+
269261
this.TestingContext.TransactionResponses.Add(transactionNumber, responseSerialisedMessage);
270-
271262
}
272263

273264
[Then(@"transaction response should contain the following information")]

TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31+
<ProjectReference Include="..\TransactionProcessor.Client\TransactionProcessor.Client.csproj" />
3132
<ProjectReference Include="..\TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj" />
3233
</ItemGroup>
3334

TransactionProcessor.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.Transa
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.IntegrationTests", "TransactionProcessor.IntegrationTests\TransactionProcessor.IntegrationTests.csproj", "{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}"
3131
EndProject
32+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.Client", "TransactionProcessor.Client\TransactionProcessor.Client.csproj", "{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}"
33+
EndProject
3234
Global
3335
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3436
Debug|Any CPU = Debug|Any CPU
@@ -79,6 +81,10 @@ Global
7981
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}.Debug|Any CPU.Build.0 = Debug|Any CPU
8082
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}.Release|Any CPU.ActiveCfg = Release|Any CPU
8183
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}.Release|Any CPU.Build.0 = Release|Any CPU
84+
{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
85+
{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Debug|Any CPU.Build.0 = Debug|Any CPU
86+
{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Release|Any CPU.ActiveCfg = Release|Any CPU
87+
{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Release|Any CPU.Build.0 = Release|Any CPU
8288
EndGlobalSection
8389
GlobalSection(SolutionProperties) = preSolution
8490
HideSolutionNode = FALSE
@@ -95,6 +101,7 @@ Global
95101
{AC0E260E-47CC-4DA7-BE62-0714F9266AEA} = {749ADE74-A6F0-4469-A638-8FD7E82A8667}
96102
{69BE1042-5AB9-420B-9A27-E2F1ADFC4E65} = {71B30DC4-AB27-4D30-8481-B4C326D074CB}
97103
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C} = {71B30DC4-AB27-4D30-8481-B4C326D074CB}
104+
{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393} = {749ADE74-A6F0-4469-A638-8FD7E82A8667}
98105
EndGlobalSection
99106
GlobalSection(ExtensibilityGlobals) = postSolution
100107
SolutionGuid = {193D13DE-424B-4D50-B674-01F9E4CC2CA9}

0 commit comments

Comments
 (0)