Skip to content

Commit ff39f56

Browse files
committed
Integration testing against mock server
1 parent 0dc1cb2 commit ff39f56

20 files changed

+206
-18
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
run: |
3838
dotnet test -c Release --no-restore --no-build -- \
3939
--coverage --coverage-output-format xml --coverage-output ${{ github.workspace }}/coverage.xml
40+
env:
41+
USE_MOCKING: ${{ vars.USE_MOCKING }}
4042
- name: Find coverage files and generate report
4143
run: |
4244
reportgenerator -reports:"${{ github.workspace }}/**/coverage.xml" \

app.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Solution>
22
<Folder Name="/src/">
33
<Project Path="src/Api/Api.csproj" />
4+
<Project Path="src/Common/Common.csproj" />
45
<Project Path="src/Services/Services.csproj" />
56
</Folder>
67
<Folder Name="/tests/">

src/Api/Api.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<ItemGroup>
3+
<ProjectReference Include="..\Common\Common.csproj" />
34
<ProjectReference Include="..\Services\Services.csproj" />
5+
</ItemGroup>
6+
<ItemGroup>
47
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" />
58
<PackageReference Include="Azure.Identity" />
69
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" />

src/Api/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Globalization;
22
using Api.Setup;
33
using Azure.Identity;
4+
using Common;
45
using Serilog;
56

67
DotNetEnv.Env.TraversePath().Load();
@@ -24,7 +25,7 @@
2425

2526
var builder = WebApplication.CreateBuilder(args);
2627

27-
var keyVaultName = builder.Configuration.GetValue<string>("KEY_VAULT_NAME");
28+
var keyVaultName = builder.Configuration.GetValue<string>(EnvironmentVariable.KeyVaultName);
2829
if (builder.Environment.IsProduction() && !string.IsNullOrEmpty(keyVaultName))
2930
{
3031
var keyVaultUri = new Uri($"https://{keyVaultName}.vault.azure.net/");

src/Api/packages.lock.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,9 +1589,13 @@
15891589
"System.Xml.ReaderWriter": "4.3.0"
15901590
}
15911591
},
1592+
"common": {
1593+
"type": "Project"
1594+
},
15921595
"services": {
15931596
"type": "Project",
15941597
"dependencies": {
1598+
"Common": "[1.0.0, )",
15951599
"Microsoft.AspNetCore.WebUtilities": "[9.0.8, )",
15961600
"Microsoft.Extensions.Http": "[9.0.8, )",
15971601
"Microsoft.Extensions.Logging": "[9.0.8, )"

src/Common/Common.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

src/Common/EnvironmentVariable.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Common;
2+
3+
public static class EnvironmentVariable
4+
{
5+
public const string KeyVaultName = "KEY_VAULT_NAME";
6+
public const string MarketClientUrl = "MARKET_CLIENT_URL";
7+
public const string UseMocking = "USE_MOCKING";
8+
}

src/Common/packages.lock.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 2,
3+
"dependencies": {
4+
"net9.0": {
5+
"SonarAnalyzer.CSharp": {
6+
"type": "Direct",
7+
"requested": "[10.15.0.120848, )",
8+
"resolved": "10.15.0.120848",
9+
"contentHash": "1hM3HVRl5jdC/ZBDu+G7CCYLXRGe/QaP01Zy+c9ETPhY7lWD8g8HiefY6sGaH0T3CJ4wAy0/waGgQTh0TYy0oQ=="
10+
}
11+
}
12+
}
13+
}

src/Services/MarketClient.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json;
2+
using Common;
23
using Microsoft.AspNetCore.WebUtilities;
34
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.Logging;
@@ -24,7 +25,7 @@ public class MarketClient(ILogger<MarketClient> logger, IConfiguration configura
2425

2526
using (var httpClient = _httpClientFactory.CreateClient())
2627
{
27-
httpClient.BaseAddress = new Uri(configuration.GetValue("MARKET_CLIENT_URL", "https://api.coingecko.com"));
28+
httpClient.BaseAddress = new Uri(configuration.GetValue(EnvironmentVariable.MarketClientUrl, "https://api.coingecko.com"));
2829
var response = await httpClient.SendAsync(request).ConfigureAwait(false);
2930
if (response.IsSuccessStatusCode)
3031
{

src/Services/Services.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<ProjectReference Include="..\Common\Common.csproj" />
4+
</ItemGroup>
25
<ItemGroup>
36
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" />
47
<PackageReference Include="Microsoft.Extensions.Http" />

0 commit comments

Comments
 (0)