Spaces:
Runtime error
Runtime error
Download tests/SCM.IntegrationTests/ScmApiFactory.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/tests/SCM.IntegrationTests/ScmApiFactory.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/tests/SCM.IntegrationTests/ScmApiFactory.cs
-
curl -L -o ScmApiFactory.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/tests/SCM.IntegrationTests/ScmApiFactory.cs
1.37 kB
| using Microsoft.AspNetCore.Hosting; | |
| using Microsoft.AspNetCore.Mvc.Testing; | |
| using Microsoft.Extensions.Configuration; | |
| using Testcontainers.PostgreSql; | |
| using Xunit; | |
| namespace SCM.IntegrationTests; | |
| /// <summary> | |
| /// Sobe a API inteira (TestServer) apontando para um PostgreSQL descartável (Testcontainers). | |
| /// As migrations rodam no startup (ambiente Development), criando schema + seed do admin. | |
| /// </summary> | |
| public sealed class ScmApiFactory : WebApplicationFactory<Program>, IAsyncLifetime | |
| { | |
| private readonly PostgreSqlContainer _postgres = new PostgreSqlBuilder() | |
| .WithImage("postgres:16") | |
| .Build(); | |
| public string ConnectionString => _postgres.GetConnectionString(); | |
| protected override void ConfigureWebHost(IWebHostBuilder builder) | |
| { | |
| builder.UseEnvironment("Development"); | |
| builder.ConfigureAppConfiguration((_, config) => | |
| { | |
| config.AddInMemoryCollection(new Dictionary<string, string?> | |
| { | |
| ["ConnectionStrings:Postgres"] = _postgres.GetConnectionString(), | |
| ["Migrations:RunOnStartup"] = "true", | |
| }); | |
| }); | |
| } | |
| async Task IAsyncLifetime.InitializeAsync() => await _postgres.StartAsync(); | |
| async Task IAsyncLifetime.DisposeAsync() | |
| { | |
| await _postgres.DisposeAsync(); | |
| await base.DisposeAsync(); | |
| } | |
| } | |