using System.Linq;
using adMoto.Payments.Core;
using adMoto.Payments.Core.Data;
using adMoto.Payments.Core.Interfaces;
using adMoto.Payments.Web.Models;
using NUnit.Framework;

namespace adMoto.Payments.Test.Web
{
    [TestFixture]
    public class PaymentUtilsTests
    {
        private readonly Function _function = new Function();
        private readonly ITranslateManager _translateManager = new FakeTranslation();

        [Test, Sequential]
        [Category("Unit")]
        public void GetCurrency_Returns_Correct_Currency(
            [Values(null, "", "eur", "usd", "gbp", "GBP")] string input,
            [Values(PaymentsUtils.PLN, PaymentsUtils.PLN, PaymentsUtils.EUR, PaymentsUtils.USD, PaymentsUtils.GBP, PaymentsUtils.GBP)] string output
            )
        {
            //Arrange
            var funkcjePlantosi = new PaymentsUtils();

            //Act
            var result = funkcjePlantosi.GetCurrency(input);

            //Assert
            Assert.That(result, Is.EqualTo(output));
        }

        [Test]
        [Category("Unit")]
        public void CreateAndAddNewPayment_Creates_PlatnosciEcard()
        {
            //Arrange
            var idFaktury = 123;
            var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
            var paymentsUtils = new PaymentsUtils(repPayment, _translateManager);
            var invoice = _function.CreateInvoice(idFaktury, "nip", "abc/2009", 200, 2);
            var payer = _function.CreatePayer(idFaktury, "test", "test");
            var waluta = new Waluta { Amount = 200, Currency = PaymentsUtils.PLN };

            //Act
            paymentsUtils.CreateAndAddNewPyment(invoice, waluta, payer, "sessionId");
            var payment = repPayment.Find(p => p.IDFaktury == 123).SingleOrDefault();

            //Act
            Assert.That(payment.AMOUNT, Is.EqualTo(200));
        }

        [Test, Sequential]
        [Category("Unit")]
        public void BruttoToString_Returns_Correct_Amount(
            [Values(null, "", "pln", "PLN", "GBP", "gbp", "xx")] string input,
            [Values("100 PLN ", "100 PLN ", "100 PLN ", "100 PLN ", "100 PLN (1 GBP)", "100 PLN (1 GBP)", "100 PLN (1 XX)")] string output
            )
        {
            //Arrange
            var funkcjePlantosi = new PaymentsUtils();

            //Act
            var result = funkcjePlantosi.BruttoToString(100, 1, input);

            //Act
            System.Diagnostics.Debug.WriteLine(result);
            Assert.That(result, Is.EqualTo(output));
        }
        
    }
}
