mirror of
https://github.com/Cleanuparr/Cleanuparr.git
synced 2026-03-24 17:13:41 -04:00
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using Cleanuparr.Infrastructure.Features.Auth;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Cleanuparr.Api.Tests.Features.Auth;
|
|
|
|
/// <summary>
|
|
/// Factory variant that replaces <see cref="IPasswordService"/> with a
|
|
/// <see cref="TrackingPasswordService"/> spy so tests can assert that
|
|
/// password verification is always called regardless of username validity.
|
|
/// </summary>
|
|
public class TimingTestWebApplicationFactory : CustomWebApplicationFactory
|
|
{
|
|
public TrackingPasswordService TrackingPasswordService { get; } = new();
|
|
|
|
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
|
{
|
|
base.ConfigureWebHost(builder);
|
|
|
|
builder.ConfigureServices(services =>
|
|
{
|
|
// Replace IPasswordService with our tracking spy
|
|
var descriptor = services.SingleOrDefault(d => d.ServiceType == typeof(IPasswordService));
|
|
if (descriptor != null) services.Remove(descriptor);
|
|
|
|
services.AddSingleton<IPasswordService>(TrackingPasswordService);
|
|
});
|
|
}
|
|
}
|