using Microsoft.Extensions.DependencyInjection;

namespace ZB.MOM.WW.Audit.Tests;

public class AuditServiceCollectionExtensionsTests
{
    [Fact]
    public void Registers_null_redactor_and_noop_writer_by_default()
    {
        var sp = new ServiceCollection().AddZbAudit().BuildServiceProvider();
        Assert.IsType<NullAuditRedactor>(sp.GetRequiredService<IAuditRedactor>());
        Assert.IsType<NoOpAuditWriter>(sp.GetRequiredService<IAuditWriter>());
    }

    [Fact]
    public void Does_not_override_a_preregistered_writer()
    {
        var services = new ServiceCollection();
        services.AddSingleton<IAuditWriter>(new CompositeAuditWriter(System.Array.Empty<IAuditWriter>()));
        var sp = services.AddZbAudit().BuildServiceProvider();
        Assert.IsType<CompositeAuditWriter>(sp.GetRequiredService<IAuditWriter>());
    }

    [Fact]
    public void Does_not_override_a_preregistered_redactor()
    {
        var services = new ServiceCollection();
        services.AddSingleton<IAuditRedactor>(new TruncatingAuditRedactor());
        var sp = services.AddZbAudit().BuildServiceProvider();
        Assert.IsType<TruncatingAuditRedactor>(sp.GetRequiredService<IAuditRedactor>());
    }
}
