BaseTestd

This commit is contained in:
Michał Zieliński
2025-06-08 14:21:45 +02:00
parent 34c1ba1483
commit 0795850666
5 changed files with 77 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Mvc.Testing;
using Xunit;
using System.Text.Json;
namespace DiunaBI.Tests;
public class ApiConnectionTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
public ApiConnectionTests(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
[Fact]
public async Task PingToApi()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/api/Ping/Ping");
var content = await response.Content.ReadAsStringAsync();
var statusCode = (int)response.StatusCode;
Assert.Equal(200, statusCode);
Assert.Equal("Pong", content);
}
[Fact]
public async Task DatabaseConnectionTest()
{
var client = _factory.CreateClient();
var response = await client.GetAsync("/api/Layers?start=0&limit=1");
var content = await response.Content.ReadAsStringAsync();
var statusCode = (int)response.StatusCode;
Assert.Equal(200, statusCode);
var layers = JsonSerializer.Deserialize<dynamic>(content);
Assert.NotNull(layers);
}
}

View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiunaBI.WebAPI\DiunaBI.WebAPI.csproj" />
</ItemGroup>
</Project>

View File

@@ -20,6 +20,6 @@ public class PingController : Controller
[AllowAnonymous]
public IActionResult Ping()
{
return Ok(_configuration["PONG"]);
return Ok("Pong");
}
}

View File

@@ -159,4 +159,6 @@ app.Run();
if (app.Environment.IsProduction())
{
Log.CloseAndFlush();
}
}
// for testing purposes
public partial class Program { }

View File

@@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
@@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Core", "DiunaBI.Cor
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Plugins.Morska", "DiunaBI.Plugins.Morska\DiunaBI.Plugins.Morska.csproj", "{B5416A3F-550A-468D-852F-20B24243FD68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiunaBI.Tests", "DiunaBI.Tests\DiunaBI.Tests.csproj", "{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -34,5 +36,9 @@ Global
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C346BEA-A209-4E8F-A6BF-70B42D9106C8}.Release|Any CPU.Build.0 = Release|Any CPU
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D99AF7E-1FC7-4EC0-A320-F1A81D396F93}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal