Created
December 13, 2025 15:18
-
-
Save pazteddy/4eaf70d8b481e227c4bd8fec82ecdb48 to your computer and use it in GitHub Desktop.
Creación de nuestro WebApplicationFactory personalizado
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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