Shady nagy/net6 (#614)
* udated to .net6 * used the .net6 version RC2 * added editconfig. * App core new Scoped Namespaces style. * BlazorAdmin new Scoped Namespaces style. * Blazor Shared new Scoped Namespaces style. * Infra new Scoped Namespaces style. * public api new Scoped Namespaces style. * web new Scoped Namespaces style. * FunctionalTests new Scoped Namespaces style. * Integrational tests new Scoped Namespaces style. * unit tests new Scoped Namespaces style. * update github action. * update github action. * change the global.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -7,38 +8,37 @@ using Microsoft.eShopWeb.Infrastructure.Identity;
|
||||
using Microsoft.eShopWeb.PublicApi;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.PublicApi
|
||||
namespace Microsoft.eShopWeb.FunctionalTests.PublicApi;
|
||||
|
||||
public class ApiTestFixture : WebApplicationFactory<Startup>
|
||||
{
|
||||
public class ApiTestFixture : WebApplicationFactory<Startup>
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.UseEnvironment("Testing");
|
||||
builder.UseEnvironment("Testing");
|
||||
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddEntityFrameworkInMemoryDatabase();
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
services.AddEntityFrameworkInMemoryDatabase();
|
||||
|
||||
// Create a new service provider.
|
||||
var provider = services
|
||||
.AddEntityFrameworkInMemoryDatabase()
|
||||
.BuildServiceProvider();
|
||||
.AddEntityFrameworkInMemoryDatabase()
|
||||
.BuildServiceProvider();
|
||||
|
||||
// Add a database context (ApplicationDbContext) using an in-memory
|
||||
// database for testing.
|
||||
services.AddDbContext<CatalogContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase("InMemoryDbForTesting");
|
||||
options.UseInternalServiceProvider(provider);
|
||||
});
|
||||
{
|
||||
options.UseInMemoryDatabase("InMemoryDbForTesting");
|
||||
options.UseInternalServiceProvider(provider);
|
||||
});
|
||||
|
||||
services.AddDbContext<AppIdentityDbContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase("Identity");
|
||||
options.UseInternalServiceProvider(provider);
|
||||
});
|
||||
services.AddDbContext<AppIdentityDbContext>(options =>
|
||||
{
|
||||
options.UseInMemoryDatabase("Identity");
|
||||
options.UseInternalServiceProvider(provider);
|
||||
});
|
||||
|
||||
// Build the service provider.
|
||||
var sp = services.BuildServiceProvider();
|
||||
@@ -46,34 +46,33 @@ namespace Microsoft.eShopWeb.FunctionalTests.PublicApi
|
||||
// Create a scope to obtain a reference to the database
|
||||
// context (ApplicationDbContext).
|
||||
using (var scope = sp.CreateScope())
|
||||
{
|
||||
var scopedServices = scope.ServiceProvider;
|
||||
var db = scopedServices.GetRequiredService<CatalogContext>();
|
||||
var loggerFactory = scopedServices.GetRequiredService<ILoggerFactory>();
|
||||
{
|
||||
var scopedServices = scope.ServiceProvider;
|
||||
var db = scopedServices.GetRequiredService<CatalogContext>();
|
||||
var loggerFactory = scopedServices.GetRequiredService<ILoggerFactory>();
|
||||
|
||||
var logger = scopedServices
|
||||
.GetRequiredService<ILogger<ApiTestFixture>>();
|
||||
var logger = scopedServices
|
||||
.GetRequiredService<ILogger<ApiTestFixture>>();
|
||||
|
||||
// Ensure the database is created.
|
||||
db.Database.EnsureCreated();
|
||||
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
// Seed the database with test data.
|
||||
CatalogContextSeed.SeedAsync(db, loggerFactory).Wait();
|
||||
|
||||
// seed sample user data
|
||||
var userManager = scopedServices.GetRequiredService<UserManager<ApplicationUser>>();
|
||||
var roleManager = scopedServices.GetRequiredService<RoleManager<IdentityRole>>();
|
||||
AppIdentityDbContextSeed.SeedAsync(userManager, roleManager).Wait();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred seeding the " +
|
||||
"database with test messages. Error: {ex.Message}");
|
||||
}
|
||||
var roleManager = scopedServices.GetRequiredService<RoleManager<IdentityRole>>();
|
||||
AppIdentityDbContextSeed.SeedAsync(userManager, roleManager).Wait();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"An error occurred seeding the " +
|
||||
"database with test messages. Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user