Pruebas unitarias o de integración con NET 5

0 views
Skip to first unread message

Carlos Admirador

unread,
Jun 15, 2021, 2:59:42 AMJun 15
to AltNet-Hispano
Cómo realizar pruebas unitarias o integración con NET 5? algúnejemplo real?


https://andrewlock.net/converting-integration-tests-to-net-core-3/

https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-5.0#inject-mock-services


public class CustomWebApplicationFactory<TStartup>
: WebApplicationFactory<TStartup> where TStartup : class
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
// mocked services here
 });


protected override void ConfigureWebHost(IWebHostBuilder builder)
{
// Don't run IHostedServices when running as a test
builder.ConfigureTestServices((services) =>
{
services.RemoveAll(typeof(IHostedService));
});
}

es setear en el startup un factory method:
services.AddSingleton<IRefDataRepository>(sp =>
{
return new CosmosRefDataRepository(CosmosContainerProvider.Get(cosmosDbConfig.Connection, "RefData"));
});

Experiencias ?
Reply all
Reply to author
Forward
0 new messages