using NUnit.Framework;
using Platnosci.Core.Linq;
using Platnosci.Models;
using System.Linq;
using Platnosci.Core.Interface;

namespace Platnosci.Tests.Web
{
    [TestFixture]
    class TestMethods
    {
        private readonly Function _function = new Function();
        private readonly ITranslateManager _translateManager = new FakeTranslation();

        [Test]
        [Category("Unit")]
        public void TestInsertMethodForPayment()
        {
            var fake = new FakeDataContext();
            var vPlatnosciEcardRepository = new Repository<vPlatnosciEcard>(fake);

            var platnosc = _function.CreateInvoice(123, "nip", "", 0, 0);
            vPlatnosciEcardRepository.Insert(platnosc);

            System.Diagnostics.Debug.WriteLine("rep.Count: " + vPlatnosciEcardRepository.Count());            
            var pl = vPlatnosciEcardRepository.FindOne(123);
            System.Diagnostics.Debug.WriteLine("Wartosc nip ma byc 'nip'. Jest " + pl.nip);
            Assert.That(pl.nip, Is.EqualTo("nip"));
        }
        [Test]
        [Category("Unit")]
        public void TestMethodCreateAndAddNewPaymentOk()
        {
            var idFaktury = 123;
            var repPayment = new Repository<PlatnosciEcard>(new FakeDataContext());
            var funkcjePlatnosci = new FunkcjePlatnosci(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 = "PLN"};
            var result = funkcjePlatnosci.CreateAndAddNewPyment(invoice, waluta ,payer, "sessionId");

            var payment = repPayment.Find(p => p.IDFaktury == 123).SingleOrDefault();
            Assert.That(payment.IDFaktury, Is.EqualTo(idFaktury));
        }

    }
}
