Skip to content

Commit 822e7d7

Browse files
Add Tax API client and smoke tests; enhance ERP client
Added `TaxApiClient` to interact with the Tax API, including a `HomeController` for handling root endpoint requests and validating responses. Updated `ClientFactory` with `CreateTaxApiClient` method and added `TaxApiBaseUrl` to `TestConfiguration` and `appsettings.json`. Enhanced `ErpApiClient` with a `HomeController` for root endpoint handling. Introduced `ErpApiSmokeTest` and `TaxApiSmokeTest` classes to verify root endpoint responses for ERP and Tax APIs, respectively.
1 parent 48a81fe commit 822e7d7

File tree

9 files changed

+153
-0
lines changed

9 files changed

+153
-0
lines changed

system-test/Core/Clients/ClientFactory.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Erp;
2+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Tax;
23
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.System.Api;
34
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.System.Ui;
45

@@ -20,4 +21,9 @@ public static ErpApiClient CreateErpApiClient()
2021
{
2122
return new ErpApiClient(TestConfiguration.ErpApiBaseUrl);
2223
}
24+
25+
public static TaxApiClient CreateTaxApiClient()
26+
{
27+
return new TaxApiClient(TestConfiguration.TaxApiBaseUrl);
28+
}
2329
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.Commons;
2+
3+
namespace Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Erp.Controllers;
4+
5+
public class HomeController
6+
{
7+
private const string Endpoint = "/";
8+
9+
private readonly TestHttpClient _httpClient;
10+
11+
public HomeController(TestHttpClient httpClient)
12+
{
13+
_httpClient = httpClient;
14+
}
15+
16+
public async Task<HttpResponseMessage> HomeAsync()
17+
{
18+
return await _httpClient.GetAsync(Endpoint);
19+
}
20+
21+
public void AssertHomeSuccessful(HttpResponseMessage httpResponse)
22+
{
23+
_httpClient.AssertOk(httpResponse);
24+
}
25+
}

system-test/Core/Clients/External/Erp/ErpApiClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ public class ErpApiClient : IAsyncDisposable
77
{
88
private readonly HttpClient _client;
99
private readonly TestHttpClient _testHttpClient;
10+
private readonly HomeController _homeController;
1011
private readonly ProductController _productController;
1112

1213
public ErpApiClient(string baseUrl)
1314
{
1415
_client = new HttpClient();
1516
_testHttpClient = new TestHttpClient(_client, baseUrl);
17+
_homeController = new HomeController(_testHttpClient);
1618
_productController = new ProductController(_testHttpClient);
1719
}
1820

21+
public HomeController Home() => _homeController;
1922
public ProductController Products() => _productController;
2023

2124
public async ValueTask DisposeAsync()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.Commons;
2+
3+
namespace Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Tax.Controllers;
4+
5+
public class HomeController
6+
{
7+
private const string Endpoint = "/";
8+
9+
private readonly TestHttpClient _httpClient;
10+
11+
public HomeController(TestHttpClient httpClient)
12+
{
13+
_httpClient = httpClient;
14+
}
15+
16+
public async Task<HttpResponseMessage> HomeAsync()
17+
{
18+
return await _httpClient.GetAsync(Endpoint);
19+
}
20+
21+
public void AssertHomeSuccessful(HttpResponseMessage httpResponse)
22+
{
23+
_httpClient.AssertOk(httpResponse);
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.Commons;
2+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Tax.Controllers;
3+
4+
namespace Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Tax;
5+
6+
public class TaxApiClient : IAsyncDisposable
7+
{
8+
private readonly HttpClient _client;
9+
private readonly TestHttpClient _testHttpClient;
10+
private readonly HomeController _homeController;
11+
12+
public TaxApiClient(string baseUrl)
13+
{
14+
_client = new HttpClient();
15+
_testHttpClient = new TestHttpClient(_client, baseUrl);
16+
_homeController = new HomeController(_testHttpClient);
17+
}
18+
19+
public HomeController Home() => _homeController;
20+
21+
public async ValueTask DisposeAsync()
22+
{
23+
_client.Dispose();
24+
await Task.CompletedTask;
25+
}
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients;
2+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Erp;
3+
4+
namespace Optivem.AtddAccelerator.EShop.SystemTest.SmokeTests.External;
5+
6+
public class ErpApiSmokeTest : IAsyncLifetime
7+
{
8+
private ErpApiClient _erpApiClient = default!;
9+
10+
public Task InitializeAsync()
11+
{
12+
_erpApiClient = ClientFactory.CreateErpApiClient();
13+
return Task.CompletedTask;
14+
}
15+
16+
public async Task DisposeAsync()
17+
{
18+
await ClientCloser.CloseAsync(_erpApiClient);
19+
}
20+
21+
[Fact]
22+
public async Task Home_ShouldReturn200OK()
23+
{
24+
// Act
25+
var httpResponse = await _erpApiClient.Home().HomeAsync();
26+
27+
// Assert
28+
_erpApiClient.Home().AssertHomeSuccessful(httpResponse);
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients;
2+
using Optivem.AtddAccelerator.EShop.SystemTest.Core.Clients.External.Tax;
3+
4+
namespace Optivem.AtddAccelerator.EShop.SystemTest.SmokeTests.External;
5+
6+
public class TaxApiSmokeTest : IAsyncLifetime
7+
{
8+
private TaxApiClient _taxApiClient = default!;
9+
10+
public Task InitializeAsync()
11+
{
12+
_taxApiClient = ClientFactory.CreateTaxApiClient();
13+
return Task.CompletedTask;
14+
}
15+
16+
public async Task DisposeAsync()
17+
{
18+
await ClientCloser.CloseAsync(_taxApiClient);
19+
}
20+
21+
[Fact]
22+
public async Task Home_ShouldReturn200OK()
23+
{
24+
// Act
25+
var httpResponse = await _taxApiClient.Home().HomeAsync();
26+
27+
// Assert
28+
_taxApiClient.Home().AssertHomeSuccessful(httpResponse);
29+
}
30+
}

system-test/TestConfiguration.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ static TestConfiguration()
2323

2424
// ERP configuration
2525
public static string ErpApiBaseUrl => _configuration["Test:Erp:Api:BaseUrl"] ?? "http://localhost:3100";
26+
27+
// Tax configuration
28+
public static string TaxApiBaseUrl => _configuration["Test:Tax:Api:BaseUrl"] ?? "http://localhost:3101";
2629
}

system-test/appsettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"Api": {
1313
"BaseUrl": "http://localhost:3100"
1414
}
15+
},
16+
"Tax": {
17+
"Api": {
18+
"BaseUrl": "http://localhost:3101"
19+
}
1520
}
1621
},
1722
"WaitSeconds": 10

0 commit comments

Comments
 (0)