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
3 changes: 3 additions & 0 deletions BtmsGateway.Test/BtmsGateway.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<None Update="EndToEnd\Fixtures\DecisionNotification.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="EndToEnd\Fixtures\TargetRoutingConfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@

namespace BtmsGateway.Test.EndToEnd;

public class ClearanceRequestTests : TargetRoutingTestBase
public class ClearanceRequestFromCdsToAlvsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/clearance-request/path";
private const string GatewayPath = $"/cds{OriginalPath}";
private const string BtmsPath = $"/forked{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "ClearanceRequest.xml"));
private readonly string _originalResponseSoap = File.ReadAllText(Path.Combine(FixturesPath, "AlvsResponse.xml"));
private readonly string _btmsRequestJson = File.ReadAllText(Path.Combine(FixturesPath, "ClearanceRequest.json")).LinuxLineEndings();
private readonly StringContent _originalRequestSoapContent;

public ClearanceRequestTests()
public ClearanceRequestFromCdsToAlvsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(content: _originalResponseSoap, statusFunc: () => HttpStatusCode.Accepted);
Expand All @@ -28,7 +27,7 @@ public async Task When_receiving_request_from_cds_Then_should_forward_to_alvs()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(OriginalPath);
TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://cds{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).Should().Be(_originalRequestSoap);
}

Expand All @@ -46,7 +45,7 @@ public async Task When_receiving_request_from_cds_Then_should_forward_converted_
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(BtmsPath);
TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://btms{OriginalPath}");
(await TestWebServer.ForkedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).LinuxLineEndings().Should().Be(_btmsRequestJson);
}
}
50 changes: 50 additions & 0 deletions BtmsGateway.Test/EndToEnd/ClearanceRequestFromCdsToBtmsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Net;
using System.Net.Mime;
using System.Text;
using BtmsGateway.Test.TestUtils;
using FluentAssertions;

namespace BtmsGateway.Test.EndToEnd;

public class ClearanceRequestFromCdsToBtmsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/clearance-request/path";
private const string GatewayPath = $"/cds_btms{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "ClearanceRequest.xml"));
private readonly string _originalResponseSoap = File.ReadAllText(Path.Combine(FixturesPath, "AlvsResponse.xml"));
private readonly string _btmsRequestJson = File.ReadAllText(Path.Combine(FixturesPath, "ClearanceRequest.json")).LinuxLineEndings();
private readonly StringContent _originalRequestSoapContent;

public ClearanceRequestFromCdsToBtmsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(content: _originalResponseSoap, statusFunc: () => HttpStatusCode.Accepted);
}

[Fact]
public async Task When_receiving_request_from_cds_Then_should_forward_converted_json_to_btms()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://btms{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).LinuxLineEndings().Should().Be(_btmsRequestJson);
}

[Fact]
public async Task When_receiving_request_from_cds_Then_should_respond_with_btms_response()
{
var response = await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

response.StatusCode.Should().Be(HttpStatusCode.Accepted);
(await response.Content.ReadAsStringAsync()).Should().Be(_originalResponseSoap);
}

[Fact]
public async Task When_receiving_request_from_cds_Then_should_not_forward_to_btms()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest.Should().BeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

namespace BtmsGateway.Test.EndToEnd;

public class DecisionNotificationTests : TargetRoutingTestBase
public class DecisionNotificationFromAlvsToCdsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/decision-notification/path";
private const string GatewayPath = $"/alvs-cds{OriginalPath}";
private const string BtmsPath = $"/forked{OriginalPath}";
private const string GatewayPath = $"/alvs_cds{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "DecisionNotification.xml"));
private readonly string _btmsRequestJson = File.ReadAllText(Path.Combine(FixturesPath, "DecisionNotification.json")).LinuxLineEndings();
private readonly StringContent _originalRequestSoapContent;

public DecisionNotificationTests()
public DecisionNotificationFromAlvsToCdsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(statusFunc: () => HttpStatusCode.NoContent);
Expand All @@ -27,7 +26,7 @@ public async Task When_receiving_request_from_alvs_Then_should_forward_to_cds()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(OriginalPath);
TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://alvs_cds{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).Should().Be(_originalRequestSoap);
}

Expand All @@ -45,7 +44,7 @@ public async Task When_receiving_request_from_alvs_Then_should_forward_converted
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(BtmsPath);
TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://btms{OriginalPath}");
(await TestWebServer.ForkedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).LinuxLineEndings().Should().Be(_btmsRequestJson);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Net;
using System.Net.Mime;
using System.Text;
using FluentAssertions;

namespace BtmsGateway.Test.EndToEnd;

public class DecisionNotificationFromBtmsToCdsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/decision-notification/path";
private const string GatewayPath = $"/btms_cds{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "DecisionNotification.xml"));
private readonly StringContent _originalRequestSoapContent;

public DecisionNotificationFromBtmsToCdsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(statusFunc: () => HttpStatusCode.NoContent);
}

[Fact]
public async Task When_receiving_request_from_btms_Then_should_forward_converted_soap_to_cds()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent); // TODO: Should be passing in JSON

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://cds{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).Should().Be(_originalRequestSoap);
}

[Fact]
public async Task When_receiving_request_from_btms_Then_should_respond_with_cds_response()
{
var response = await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent); // TODO: Should be passing in JSON

response.StatusCode.Should().Be(HttpStatusCode.NoContent);
(await response.Content.ReadAsStringAsync()).Should().Be(string.Empty);
}

[Fact]
public async Task When_receiving_request_from_btms_Then_should_not_forward_to_btms()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest.Should().BeNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

namespace BtmsGateway.Test.EndToEnd;

public class AlvsSourceErrorHandlingTests : TargetRoutingTestBase
public class ErrorHandlingFromAlvsToCdsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/alvs-sourced-error-handling/path";
private const string GatewayPath = $"/alvs-cds{OriginalPath}";
private const string BtmsPath = $"/forked{OriginalPath}";
private const string GatewayPath = $"/alvs_cds{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "AlvsErrorHandling.xml"));
private readonly string _btmsRequestJson = File.ReadAllText(Path.Combine(FixturesPath, "AlvsErrorHandling.json")).LinuxLineEndings();
private readonly StringContent _originalRequestSoapContent;

public AlvsSourceErrorHandlingTests()
public ErrorHandlingFromAlvsToCdsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(statusFunc: () => HttpStatusCode.NoContent);
Expand All @@ -27,7 +26,7 @@ public async Task When_receiving_request_from_alvs_Then_should_forward_to_cds()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(OriginalPath);
TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://alvs_cds{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).Should().Be(_originalRequestSoap);
}

Expand All @@ -45,7 +44,7 @@ public async Task When_receiving_request_from_alvs_Then_should_forward_converted
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(BtmsPath);
TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://btms{OriginalPath}");
(await TestWebServer.ForkedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).LinuxLineEndings().Should().Be(_btmsRequestJson);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@

namespace BtmsGateway.Test.EndToEnd;

public class CdsSourcedErrorHandlingTests : TargetRoutingTestBase
public class ErrorHandlingFromCdsToAlvsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/cds-sourced-error-handling/path";
private const string GatewayPath = $"/cds{OriginalPath}";
private const string BtmsPath = $"/forked{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "CdsErrorHandling.xml"));
private readonly string _originalResponseSoap = File.ReadAllText(Path.Combine(FixturesPath, "AlvsResponse.xml"));
private readonly string _btmsRequestJson = File.ReadAllText(Path.Combine(FixturesPath, "CdsErrorHandling.json")).LinuxLineEndings();
private readonly StringContent _originalRequestSoapContent;

public CdsSourcedErrorHandlingTests()
public ErrorHandlingFromCdsToAlvsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(content: _originalResponseSoap, statusFunc: () => HttpStatusCode.Accepted);
Expand All @@ -28,7 +27,7 @@ public async Task When_receiving_request_from_cds_Then_should_forward_to_alvs()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(OriginalPath);
TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://cds{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).Should().Be(_originalRequestSoap);
}

Expand All @@ -46,7 +45,7 @@ public async Task When_receiving_request_from_cds_Then_should_forward_converted_
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(BtmsPath);
TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://btms{OriginalPath}");
(await TestWebServer.ForkedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).LinuxLineEndings().Should().Be(_btmsRequestJson);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@

namespace BtmsGateway.Test.EndToEnd;

public class FinalisationNotificationTests : TargetRoutingTestBase
public class FinalisationNotificationFromCdsToAlvsTests : TargetRoutingTestBase
{
private const string OriginalPath = "/finalisation-notification/path";
private const string GatewayPath = $"/cds{OriginalPath}";
private const string BtmsPath = $"/forked{OriginalPath}";

private readonly string _originalRequestSoap = File.ReadAllText(Path.Combine(FixturesPath, "FinalisationNotification.xml"));
private readonly string _originalResponseSoap = File.ReadAllText(Path.Combine(FixturesPath, "AlvsResponse.xml"));
private readonly string _btmsRequestJson = File.ReadAllText(Path.Combine(FixturesPath, "FinalisationNotification.json")).LinuxLineEndings();
private readonly StringContent _originalRequestSoapContent;

public FinalisationNotificationTests()
public FinalisationNotificationFromCdsToAlvsTests()
{
_originalRequestSoapContent = new StringContent(_originalRequestSoap, Encoding.UTF8, MediaTypeNames.Application.Soap);
TestWebServer.RoutedHttpHandler.SetNextResponse(content: _originalResponseSoap, statusFunc: () => HttpStatusCode.Accepted);
Expand All @@ -28,7 +27,7 @@ public async Task When_receiving_request_from_cds_Then_should_forward_to_alvs()
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(OriginalPath);
TestWebServer.RoutedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://cds{OriginalPath}");
(await TestWebServer.RoutedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).Should().Be(_originalRequestSoap);
}

Expand All @@ -46,7 +45,7 @@ public async Task When_receiving_request_from_cds_Then_should_forward_converted_
{
await HttpClient.PostAsync(GatewayPath, _originalRequestSoapContent);

TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsolutePath.Should().Be(BtmsPath);
TestWebServer.ForkedHttpHandler.LastRequest!.RequestUri!.AbsoluteUri.Should().Be($"http://btms{OriginalPath}");
(await TestWebServer.ForkedHttpHandler.LastRequest!.Content!.ReadAsStringAsync()).LinuxLineEndings().Should().Be(_btmsRequestJson);
}
}
46 changes: 46 additions & 0 deletions BtmsGateway.Test/EndToEnd/Fixtures/TargetRoutingConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"NamedRoutes": {
"cds": {
"LegacyLinkName": "Cds",
"BtmsLinkName": "Btms",
"SendLegacyResponseToBtms": false,
"RouteTo": "Legacy"
},
"alvs_cds": {
"LegacyLinkName": "AlvsCds",
"BtmsLinkName": "Btms",
"SendLegacyResponseToBtms": false,
"RouteTo": "Legacy"
},
"btms_cds": {
"LegacyLinkName": "Cds",
"BtmsLinkName": "None",
"SendLegacyResponseToBtms": false,
"RouteTo": "Legacy"
},
"cds_btms": {
"LegacyLinkName": "None",
"BtmsLinkName": "Btms",
"SendLegacyResponseToBtms": false,
"RouteTo": "Btms"
}
},
"NamedLinks": {
"None": {
"LinkType": "None",
"Link": ""
},
"Cds": {
"LinkType": "Url",
"Link": "http://cds/"
},
"AlvsCds": {
"LinkType": "Url",
"Link": "http://alvs_cds/"
},
"Btms": {
"LinkType": "Url",
"Link": "http://btms/"
}
}
}
4 changes: 2 additions & 2 deletions BtmsGateway.Test/EndToEnd/GeneralEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class GeneralEndToEndTests : IAsyncDisposable
private const string XmlForkedResponse = "<xml>ForkedResponse</xml>";
private const string XmlContent = "<xml>Content</xml>";
private static readonly string JsonContent = $"{{{Environment.NewLine} \"xml\": \"Content\"{Environment.NewLine}}}";
private const string RouteName = "alvs-ipaffs";
private const string RouteName = "alvs_ipaffs";
private const string SubPath = "sub/path";
private const string FullPath = $"{RouteName}/{SubPath}";
private const string RoutedPath = $"/{SubPath}";
Expand All @@ -36,7 +36,7 @@ public GeneralEndToEndTests()
_httpClient.DefaultRequestHeaders.Add(MessageData.CorrelationIdHeaderName, _headerCorrelationId);

var routingConfig = _testWebServer.Services.GetRequiredService<RoutingConfig>();
var expectedRoutUrl = routingConfig.AllRoutes.Single(x => x.Name == RouteName).LegacyLink;
var expectedRoutUrl = routingConfig.AllRoutes.Single(x => x.Name == RouteName).LegacyLink!;
_expectedRoutedUrl = $"{expectedRoutUrl.Trim('/')}/{SubPath}";
_expectedForkedUrl = $"{expectedRoutUrl.Trim('/')}/forked/{SubPath}";
_stringContent = new StringContent(XmlContent, Encoding.UTF8, MediaTypeNames.Application.Xml);
Expand Down
Loading
Loading