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
6 changes: 6 additions & 0 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


22 changes: 22 additions & 0 deletions TransactionProcessor.Client/ITransactionProcessorClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TransactionProcessor.Client
{
using System.Threading;
using System.Threading.Tasks;
using DataTransferObjects;

public interface ITransactionProcessorClient
{
#region Methods

/// <summary>
/// Performs the transaction.
/// </summary>
/// <param name="transactionRequest">The transaction request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
Task<SerialisedMessage> PerformTransaction(SerialisedMessage transactionRequest,
CancellationToken cancellationToken);

#endregion
}
}
22 changes: 22 additions & 0 deletions TransactionProcessor.Client/TransactionProcessor.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClientProxyBase" Version="0.0.4.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj" />
</ItemGroup>

<Target Name="IncludeP2PAssets">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)TransactionProcessor.DataTransferObjects.dll" />
</ItemGroup>
</Target>

</Project>
92 changes: 92 additions & 0 deletions TransactionProcessor.Client/TransactionProcessorClient.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
///
/// </summary>
/// <seealso cref="ClientProxyBase.ClientProxyBase" />
/// <seealso cref="TransactionProcessor.Client.ITransactionProcessorClient" />
public class TransactionProcessorClient : ClientProxyBase, ITransactionProcessorClient
{
#region Fields

/// <summary>
/// The base address
/// </summary>
private readonly String BaseAddress;

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="TransactionProcessorClient" /> class.
/// </summary>
/// <param name="baseAddressResolver">The base address resolver.</param>
/// <param name="httpClient">The HTTP client.</param>
public TransactionProcessorClient(Func<String, String> 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

/// <summary>
/// Performs the transaction.
/// </summary>
/// <param name="transactionRequest">The transaction request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
public async Task<SerialisedMessage> 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<SerialisedMessage>(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
}
}
9 changes: 6 additions & 3 deletions TransactionProcessor.IntegrationTests/Common/DockerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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()
Expand Down
13 changes: 2 additions & 11 deletions TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SerialisedMessage>(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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TransactionProcessor.Client\TransactionProcessor.Client.csproj" />
<ProjectReference Include="..\TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj" />
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions TransactionProcessor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down