Adding functional tests (#197)

* Working on login tests

* Testing login with an integration test

Working on login functional test.

* Got functional login test working
This commit is contained in:
Steve Smith
2019-01-25 13:13:01 -05:00
committed by GitHub
parent be06e777a6
commit 1b610dd7a4
7 changed files with 157 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopWeb.Infrastructure.Data;
@@ -17,8 +18,10 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers
{
builder.ConfigureServices(services =>
{
services.AddEntityFrameworkInMemoryDatabase();
// Create a new service provider.
var serviceProvider = new ServiceCollection()
var provider = services
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
@@ -27,15 +30,19 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers
services.AddDbContext<CatalogContext>(options =>
{
options.UseInMemoryDatabase("InMemoryDbForTesting");
options.UseInternalServiceProvider(serviceProvider);
options.UseInternalServiceProvider(provider);
});
services.AddDbContext<AppIdentityDbContext>(options =>
{
options.UseInMemoryDatabase("Identity");
options.UseInternalServiceProvider(serviceProvider);
options.UseInternalServiceProvider(provider);
});
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<AppIdentityDbContext>()
.AddDefaultTokenProviders();
// Build the service provider.
var sp = services.BuildServiceProvider();
@@ -57,6 +64,11 @@ namespace Microsoft.eShopWeb.FunctionalTests.Web.Controllers
{
// Seed the database with test data.
CatalogContextSeed.SeedAsync(db, loggerFactory).Wait();
// seed sample user data
var userManager = scopedServices.GetRequiredService<UserManager<ApplicationUser>>();
AppIdentityDbContextSeed.SeedAsync(userManager).Wait();
}
catch (Exception ex)
{