Files
eShopOnWeb/tests/FunctionalTests/Web/WebTestFixture.cs
Steve Smith ce63e38a23 net6conversion (#642)
* Converting to net6 startup and integration test formats

* Update to minimal api and using pagetitle

* Adjust functional test fixtures
Update ApiEndpoints package version

* Finish migration to minimal api startup
2021-12-06 15:14:43 -05:00

47 lines
1.5 KiB
C#

using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopWeb.Infrastructure.Data;
using Microsoft.eShopWeb.Infrastructure.Identity;
using Microsoft.eShopWeb.Web.Interfaces;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Microsoft.eShopWeb.FunctionalTests.Web;
public class TestApplication : WebApplicationFactory<IBasketViewModelService>
{
private readonly string _environment = "Development";
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("InMemoryDbForTesting")
.UseApplicationServiceProvider(sp)
.Options;
});
services.AddScoped(sp =>
{
// Replace SQLite with in-memory database for tests
return new DbContextOptionsBuilder<AppIdentityDbContext>()
.UseInMemoryDatabase("Identity")
.UseApplicationServiceProvider(sp)
.Options;
});
});
return base.CreateHost(builder);
}
}