- Added endpoints for sending and confirming email verification, enhancing user account security. - Integrated two-factor authentication (2FA) with TOTP support, including enabling, verifying, and disabling 2FA. - Implemented social login functionality for Google and Facebook, allowing users to authenticate using their existing accounts. - Updated dependency injection to include services for email, 2FA, and social login. - Enhanced documentation to reflect new features and usage examples for email verification and 2FA.
57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Mvc.Testing;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using StorageService.Infrastructure;
|
|
|
|
namespace StorageService.FunctionalTests;
|
|
|
|
/// <summary>
|
|
/// EN: Custom WebApplicationFactory for functional tests.
|
|
/// VI: WebApplicationFactory tùy chỉnh cho functional tests.
|
|
/// </summary>
|
|
public class CustomWebApplicationFactory : WebApplicationFactory<Program>
|
|
{
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
builder.UseEnvironment("Testing");
|
|
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
// EN: Remove the existing DbContext registration
|
|
// VI: Xóa đăng ký DbContext hiện tại
|
|
var descriptor = services.SingleOrDefault(
|
|
d => d.ServiceType == typeof(DbContextOptions<StorageServiceContext>));
|
|
|
|
if (descriptor != null)
|
|
{
|
|
services.Remove(descriptor);
|
|
}
|
|
|
|
// EN: Remove DbContext service
|
|
// VI: Xóa DbContext service
|
|
var dbContextDescriptor = services.SingleOrDefault(
|
|
d => d.ServiceType == typeof(StorageServiceContext));
|
|
|
|
if (dbContextDescriptor != null)
|
|
{
|
|
services.Remove(dbContextDescriptor);
|
|
}
|
|
|
|
// EN: Add in-memory database for testing
|
|
// VI: Thêm in-memory database để test
|
|
services.AddDbContext<StorageServiceContext>(options =>
|
|
{
|
|
options.UseInMemoryDatabase("TestDatabase_" + Guid.NewGuid().ToString());
|
|
});
|
|
|
|
// EN: Ensure database is created with seed data
|
|
// VI: Đảm bảo database được tạo với seed data
|
|
var sp = services.BuildServiceProvider();
|
|
using var scope = sp.CreateScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<StorageServiceContext>();
|
|
db.Database.EnsureCreated();
|
|
});
|
|
}
|
|
}
|