using Microsoft.AspNetCore.DataProtection;
using ROLAC.API.Services.Security;
using Xunit;

namespace ROLAC.API.Tests.Services;

public class TinProtectorTests
{
    private static TinProtector Build() =>
        new TinProtector(DataProtectionProvider.Create("ROLAC.Tests"));

    [Fact]
    public void Protect_then_Unprotect_round_trips()
    {
        var p = Build();
        var cipher = p.Protect("123-45-6789");
        Assert.NotEqual("123-45-6789", cipher);
        Assert.Equal("123-45-6789", p.Unprotect(cipher));
    }

    [Theory]
    [InlineData("123-45-6789", "6789")]
    [InlineData("12-3456789",  "6789")]
    [InlineData("7", "7")]
    public void Last4_keeps_only_trailing_digits(string raw, string expected)
        => Assert.Equal(expected, TinProtector.Last4(raw));

    [Fact]
    public void Last4_of_null_is_null() => Assert.Null(TinProtector.Last4(null));
}
