Skip to content

Commit 326ae7a

Browse files
committed
Possibility to develop against wiremock server
1 parent 346d0e4 commit 326ae7a

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ ASPNETCORE_ENVIRONMENT=Development
22
ASPNETCORE_HTTP_PORTS=8080
33
KEY_VAULT_NAME=key-vault-name
44
OUTPUT_CACHE=true
5+
MARKET_CLIENT_URL=http://host.docker.internal:9091

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,19 @@ services:
1212
ASPNETCORE_ENVIRONMENT: $ASPNETCORE_ENVIRONMENT
1313
ASPNETCORE_HTTP_PORTS: $ASPNETCORE_HTTP_PORTS
1414
KEY_VAULT_NAME: $KEY_VAULT_NAME
15+
OUTPUT_CACHE: $OUTPUT_CACHE
16+
MARKET_CLIENT_URL: $MARKET_CLIENT_URL
1517
user: app
1618
read_only: true
1719
privileged: false
1820
tmpfs:
1921
- /tmp:rw
22+
wiremock:
23+
image: wiremock/wiremock:3x-alpine
24+
container_name: wiremock
25+
ports:
26+
- 9091:8080
27+
read_only: false
28+
privileged: true
29+
volumes:
30+
- ./wiremock:/home/wiremock/mappings

src/Services/MarketClient.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System.Text.Json;
22
using Microsoft.AspNetCore.WebUtilities;
3+
using Microsoft.Extensions.Configuration;
34
using Microsoft.Extensions.Logging;
45
using Services.Extensions;
56
using Services.Models;
67
using Services.Utility;
78

89
namespace Services;
910

10-
public class MarketClient(ILogger<MarketClient> logger, IHttpClientFactory httpClientFactory) : IMarketClient
11+
public class MarketClient(ILogger<MarketClient> logger, IConfiguration configuration, IHttpClientFactory httpClientFactory) : IMarketClient
1112
{
1213
private readonly ILogger<MarketClient> _logger = logger;
1314
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
@@ -16,13 +17,14 @@ public class MarketClient(ILogger<MarketClient> logger, IHttpClientFactory httpC
1617

1718
public async Task<List<MarketChartPoint>?> GetMarketChartByDateRange(DateOnly fromDate, DateOnly toDate)
1819
{
19-
var baseUrl = $"https://api.coingecko.com/api/v3/coins/{Constants.CryptoCurrency}/market_chart/range";
20-
var parameters = QueryHelper.CreateQueryParams(fromDate, toDate, Constants.Currency);
20+
const string baseUrl = "/api/v3/coins/bitcoin/market_chart/range";
21+
var parameters = QueryHelper.CreateQueryParams(fromDate, toDate, "eur");
2122
var url = QueryHelpers.AddQueryString(baseUrl, parameters);
2223
using var request = new HttpRequestMessage(HttpMethod.Get, url);
2324

2425
using (var httpClient = _httpClientFactory.CreateClient())
2526
{
27+
httpClient.BaseAddress = new Uri(configuration.GetValue("MARKET_CLIENT_URL", "https://api.coingecko.com"));
2628
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
2729
if (response.IsSuccessStatusCode)
2830
{

src/Services/Utility/Constants.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

wiremock/market_client_200_OK.json

Lines changed: 16 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"request": {
3+
"method": "GET",
4+
"urlPath": "/api/v3/coins/bitcoin/market_chart/range",
5+
"queryParameters": {
6+
"vs_currency": { "equalTo": "eur"},
7+
"from": { "equalTo": "1724889600" },
8+
"to": { "equalTo": "1756512000" }
9+
}
10+
},
11+
"response": {
12+
"status": 401,
13+
"headers": { "Content-Type": "application/json" }
14+
}
15+
}

0 commit comments

Comments
 (0)