using Knoks.Framework.Cryptography;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using System;
using Xunit;

namespace Knoks.Tests.Unit.Framework.Cryptography
{
    [Trait("Category", "Unit.Framework")]
    public class PasswordProcessTest
    {
        readonly PasswordProcess _passwordProcess = new PasswordProcess(new PasswordOptions
        {
            Version = "V1",
            Peper = "abra-kadabra-123#",
            Prf = KeyDerivationPrf.HMACSHA256,
            IterationCount = 20000,
            NumBytesRequested = 256 / 8
        });

        [Theory(DisplayName = "Generate: ValidParams  => Equal")]
        [InlineData("password1", "ms6V+xCA6ctNhGpFyWJvUQ==", "0NiGdCEEdT/BzfXlbC4P9W8OOO+z632XsYoLPVlzT9w=")]
        [InlineData("password2", "d3CZd4ab6Hxaatu09YSDBg==", "gylm3E0WUhXaSmBkPbKDG6585kcf8iH+Hd5o+Su7Nog=")]
        [InlineData("", "qRxaEjPqFTPJfRWCSjFVBA==", "zN3Y9evFsK6WMg7UKw0TAEW51In3vx1xUeWOsbE2juY=")]
        void Generate_ValidParams_Equal(string password, string salt, string result)
        {
            var res = _passwordProcess.Generate(password, Convert.FromBase64String(salt));

            Assert.Equal(_passwordProcess.PasswordOptions.Version, res.Version);
            Assert.Equal(result, Convert.ToBase64String(res.Password));
            Assert.Equal(salt, Convert.ToBase64String(res.Salt));
        }
    }
}
