2025-06-08 14:21:45 +02:00
|
|
|
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();
|
|
|
|
|
|
2025-06-08 14:48:33 +02:00
|
|
|
var response = await client.GetAsync("/api/Tests/Ping");
|
2025-06-08 14:21:45 +02:00
|
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var statusCode = (int)response.StatusCode;
|
|
|
|
|
|
2025-06-08 14:48:33 +02:00
|
|
|
Assert.Equal(200, statusCode);
|
2025-06-08 14:21:45 +02:00
|
|
|
Assert.Equal("Pong", content);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2025-06-08 14:48:33 +02:00
|
|
|
[Trait("Category", "LocalOnly")]
|
2025-06-08 14:21:45 +02:00
|
|
|
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);
|
|
|
|
|
}
|
2025-06-08 14:48:33 +02:00
|
|
|
[Fact]
|
|
|
|
|
public async Task LoadPLuginsTest()
|
|
|
|
|
{
|
|
|
|
|
var client = _factory.CreateClient();
|
|
|
|
|
|
|
|
|
|
var response = await client.GetAsync("/api/Tests/Plugins");
|
|
|
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
|
|
|
var statusCode = (int)response.StatusCode;
|
|
|
|
|
|
|
|
|
|
Assert.Equal(200, statusCode);
|
|
|
|
|
var pluginsCount = JsonSerializer.Deserialize<int>(content);
|
|
|
|
|
Assert.True(pluginsCount > 0, "Expected plugins count to be greater than 0");
|
|
|
|
|
}
|
2025-06-08 14:21:45 +02:00
|
|
|
}
|