diff --git a/.github/workflows/createrelease.yml b/.github/workflows/createrelease.yml
index 24058da7..8335d125 100644
--- a/.github/workflows/createrelease.yml
+++ b/.github/workflows/createrelease.yml
@@ -118,3 +118,9 @@ jobs:
with:
dotnet-version: 3.0.100
+ - name: Build and Publish Nuget Packages
+ run: |
+ dotnet pack "TransactionProcessor.Client\TransactionProcessor.Client.csproj" /p:PackageVersion=${{ steps.get_version.outputs.VERSION }} --output Nugets
+ 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
+
+
diff --git a/TransactionProcessor.Client/ITransactionProcessorClient.cs b/TransactionProcessor.Client/ITransactionProcessorClient.cs
new file mode 100644
index 00000000..38c6bd9a
--- /dev/null
+++ b/TransactionProcessor.Client/ITransactionProcessorClient.cs
@@ -0,0 +1,22 @@
+namespace TransactionProcessor.Client
+{
+ using System.Threading;
+ using System.Threading.Tasks;
+ using DataTransferObjects;
+
+ public interface ITransactionProcessorClient
+ {
+ #region Methods
+
+ ///
+ /// Performs the transaction.
+ ///
+ /// The transaction request.
+ /// The cancellation token.
+ ///
+ Task PerformTransaction(SerialisedMessage transactionRequest,
+ CancellationToken cancellationToken);
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/TransactionProcessor.Client/TransactionProcessor.Client.csproj b/TransactionProcessor.Client/TransactionProcessor.Client.csproj
new file mode 100644
index 00000000..e2b89a4d
--- /dev/null
+++ b/TransactionProcessor.Client/TransactionProcessor.Client.csproj
@@ -0,0 +1,22 @@
+
+
+
+ netstandard2.1
+ $(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TransactionProcessor.Client/TransactionProcessorClient.cs b/TransactionProcessor.Client/TransactionProcessorClient.cs
new file mode 100644
index 00000000..5b547c70
--- /dev/null
+++ b/TransactionProcessor.Client/TransactionProcessorClient.cs
@@ -0,0 +1,92 @@
+namespace TransactionProcessor.Client
+{
+ using System;
+ using System.Net.Http;
+ using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using ClientProxyBase;
+ using DataTransferObjects;
+ using Newtonsoft.Json;
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public class TransactionProcessorClient : ClientProxyBase, ITransactionProcessorClient
+ {
+ #region Fields
+
+ ///
+ /// The base address
+ ///
+ private readonly String BaseAddress;
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The base address resolver.
+ /// The HTTP client.
+ public TransactionProcessorClient(Func baseAddressResolver,
+ HttpClient httpClient) : base(httpClient)
+ {
+ this.BaseAddress = baseAddressResolver("TransactionProcessorApi");
+
+ // Add the API version header
+ this.HttpClient.DefaultRequestHeaders.Add("api-version", "1.0");
+ }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// Performs the transaction.
+ ///
+ /// The transaction request.
+ /// The cancellation token.
+ ///
+ public async Task PerformTransaction(SerialisedMessage transactionRequest,
+ CancellationToken cancellationToken)
+ {
+ SerialisedMessage response = null;
+
+ String requestUri = $"{this.BaseAddress}/api/transactions";
+
+ try
+ {
+ String requestSerialised = JsonConvert.SerializeObject(transactionRequest);
+
+ StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json");
+
+ // Add the access token to the client headers
+ //this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
+
+ // Make the Http Call here
+ HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken);
+
+ // Process the response
+ String content = await this.HandleResponse(httpResponse, cancellationToken);
+
+ // call was successful so now deserialise the body to the response object
+ response = JsonConvert.DeserializeObject(content);
+ }
+ catch(Exception ex)
+ {
+ // An exception has occurred, add some additional information to the message
+ Exception exception = new Exception("Error posting transaction.", ex);
+
+ throw exception;
+ }
+
+ return response;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs
index 16a95dae..8f33df55 100644
--- a/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs
+++ b/TransactionProcessor.IntegrationTests/Common/DockerHelper.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
+ using Client;
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Model.Builders;
using Ductus.FluentDocker.Services;
@@ -23,7 +24,8 @@ public class DockerHelper
protected IContainerService EventStoreContainer;
public IEstateClient EstateClient;
- public HttpClient HttpClient;
+ public ITransactionProcessorClient TransactionProcessorClient;
+ //public HttpClient HttpClient;
protected String EventStoreConnectionString;
@@ -86,10 +88,11 @@ public async Task StartContainersForScenarioRun(String scenarioName)
HttpClient httpClient = new HttpClient();
this.EstateClient = new EstateClient(estateManagementBaseAddressResolver, httpClient);
+ this.TransactionProcessorClient = new TransactionProcessorClient(transactionProcessorBaseAddressResolver, httpClient);
// TODO: Use this to talk to txn processor until we have a client
- this.HttpClient = new HttpClient();
- this.HttpClient.BaseAddress = new Uri(transactionProcessorBaseAddressResolver(String.Empty));
+ //this.HttpClient = new HttpClient();
+ //this.HttpClient.BaseAddress = new Uri(transactionProcessorBaseAddressResolver(String.Empty));
}
public async Task StopContainersForScenarioRun()
diff --git a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs
index 2371aac8..c96e34ea 100644
--- a/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs
+++ b/TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs
@@ -256,18 +256,9 @@ private async Task PerformLogonTransaction(Guid estateId, Guid merchantId, DateT
TypeNameHandling = TypeNameHandling.All
});
- String uri = "api/transactions";
-
- StringContent content = new StringContent(JsonConvert.SerializeObject(serialisedMessage), Encoding.UTF8, "application/json");
-
- HttpResponseMessage response = await this.TestingContext.DockerHelper.HttpClient.PostAsync(uri, content, cancellationToken);
-
- response.IsSuccessStatusCode.ShouldBeTrue();
-
- SerialisedMessage responseSerialisedMessage = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
-
+ SerialisedMessage responseSerialisedMessage = await this.TestingContext.DockerHelper.TransactionProcessorClient.PerformTransaction(serialisedMessage, cancellationToken);
+
this.TestingContext.TransactionResponses.Add(transactionNumber, responseSerialisedMessage);
-
}
[Then(@"transaction response should contain the following information")]
diff --git a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj
index 8efe7a67..cead8750 100644
--- a/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj
+++ b/TransactionProcessor.IntegrationTests/TransactionProcessor.IntegrationTests.csproj
@@ -28,6 +28,7 @@
+
diff --git a/TransactionProcessor.sln b/TransactionProcessor.sln
index 9aeb6eec..297e1530 100644
--- a/TransactionProcessor.sln
+++ b/TransactionProcessor.sln
@@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.Transa
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TransactionProcessor.IntegrationTests", "TransactionProcessor.IntegrationTests\TransactionProcessor.IntegrationTests.csproj", "{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TransactionProcessor.Client", "TransactionProcessor.Client\TransactionProcessor.Client.csproj", "{DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -79,6 +81,10 @@ Global
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DAF20F25-8BD1-4FA5-ADAD-71B068CDF393}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -95,6 +101,7 @@ Global
{AC0E260E-47CC-4DA7-BE62-0714F9266AEA} = {749ADE74-A6F0-4469-A638-8FD7E82A8667}
{69BE1042-5AB9-420B-9A27-E2F1ADFC4E65} = {71B30DC4-AB27-4D30-8481-B4C326D074CB}
{3C40D27B-66B6-4C4A-839C-1E2BD7B4994C} = {71B30DC4-AB27-4D30-8481-B4C326D074CB}
+ {DAF20F25-8BD1-4FA5-ADAD-71B068CDF393} = {749ADE74-A6F0-4469-A638-8FD7E82A8667}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {193D13DE-424B-4D50-B674-01F9E4CC2CA9}