Files
eShopOnWeb/tests/FunctionalTests/PublicApi/ApiTestFixture.cs
Cédric Michel 1e13733d3d Feature/migrate to minimal api (#662)
* migrate from classic controller to minimal api

* fix all PublicApi integration test

* update all nuget package add forget project

* fix pay now

* Adapt readme use in memory database

* undo AuthenticateEndpoint to use EndpointBaseAsync

* Update README.md

Co-authored-by: Steve Smith <steve@kentsmiths.com>

Co-authored-by: Steve Smith <steve@kentsmiths.com>
2022-01-21 10:13:31 -05:00

44 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopWeb.Infrastructure.Data;
using Microsoft.eShopWeb.Infrastructure.Identity;
using Microsoft.eShopWeb.PublicApi.AuthEndpoints;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Microsoft.eShopWeb.FunctionalTests.PublicApi;
public class TestApiApplication : WebApplicationFactory<AuthenticateEndpoint>
{
private readonly string _environment = "Testing";
protected override IHost CreateHost(IHostBuilder builder)
{
builder.UseEnvironment(_environment);
// Add mock/test services to the builder here
builder.ConfigureServices(services =>
{
services.AddScoped(sp =>
{
// Replace SQLite with in-memory database for tests
return new DbContextOptionsBuilder<CatalogContext>()
.UseInMemoryDatabase("DbForPublicApi")
.UseApplicationServiceProvider(sp)
.Options;
});
services.AddScoped(sp =>
{
// Replace SQLite with in-memory database for tests
return new DbContextOptionsBuilder<AppIdentityDbContext>()
.UseInMemoryDatabase("IdentityDbForPublicApi")
.UseApplicationServiceProvider(sp)
.Options;
});
});
return base.CreateHost(builder);
}
}