- Ajoute Testcontainers.PostgreSql v4.13.0\n- PostgreSqlContainerFixture: collection fixture xUnit avec postgres:17-alpine\n- HeimdallWebApplicationFactory: accepte connectionString pour vrai PostgreSQL\n- PostgresTestBase: classe de base pour tous les tests integration\n- Ajoute [Collection("Postgres")] aux 9 classes de test\n- Database:MigrateOnStartup active quand PostgreSQL est utilise\n- Programme le Hangfire (skip en test via isTesting)\n\nAvant: InMemory (pas de contraintes, comportement different)\nApres: Vrai PostgreSQL dans un container temporaire\n\nTests: 226/226 passed (61 integration avec vrai PostgreSQL)
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using System.Net.Http.Json;
|
|
using Heimdall.IntegrationTests.Factories;
|
|
using Shouldly;
|
|
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
|
|
|
public class SitesControllerTests : PostgresTestBase
|
|
{
|
|
public SitesControllerTests(PostgreSqlContainerFixture postgres) : base(postgres) { }
|
|
|
|
[Fact]
|
|
public async Task GetSites_WithoutAuth_ReturnsUnauthorized()
|
|
{
|
|
var client = Factory.CreateClient();
|
|
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateSite_WithAuth_ReturnsOk()
|
|
{
|
|
var client = await Factory.CreateAdminClientAsync();
|
|
var response = await client.PostAsJsonAsync("api/sites", new
|
|
{
|
|
name = "Site Test",
|
|
address = "Paris",
|
|
timezone = "Europe/Paris"
|
|
});
|
|
var body = await response.Content.ReadAsStringAsync();
|
|
await File.WriteAllTextAsync("/tmp/test-response-body.txt", body);
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ListSites_WithAuth_ReturnsOk()
|
|
{
|
|
var client = await Factory.CreateAdminClientAsync();
|
|
var response = await client.GetAsync("api/sites?page=1&pageSize=10");
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
|
}
|
|
}
|