Skip to content

Instantly share code, notes, and snippets.

@pazteddy
Created December 13, 2025 15:18
Show Gist options
  • Select an option

  • Save pazteddy/4eaf70d8b481e227c4bd8fec82ecdb48 to your computer and use it in GitHub Desktop.

Select an option

Save pazteddy/4eaf70d8b481e227c4bd8fec82ecdb48 to your computer and use it in GitHub Desktop.
Creación de nuestro WebApplicationFactory personalizado
public class CustomWebApplicationFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.ConfigureServices(services =>
{
// Aquí podríamos remover o reemplazar servicios si fuera necesario
// Por ejemplo, si tuviéramos una base de datos real, podríamos usar SQLite en memoria para tests
});
builder.UseEnvironment("Testing");
}
public HttpClient GetHttpClient()
{
var client = CreateClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
return client;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment