using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

using NUnit.Framework;
using MvcContrib.TestHelper;
using Platnosci.Controllers;

using Platnosci.Core.Interface;
using Platnosci.Core.Linq;

namespace Platnosci.Tests.Web
{
    [TestFixture]
    class PlatnosciControllerTests
    {
         private string merchantNumber = "123";

         /*[TearDown]
         public void TearDown()
         {
             IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>();
             var potwierdzeniaEcard = _rep.Find(p => p.MERCHANTNUMBER == merchantNumber);

             foreach (var pe in potwierdzeniaEcard)
             {
                 _rep.Delete(pe);
             }
         }
        */
         [Test]
         public void Status_Saves_Correct_Transaction()
         {
            
             var orderNumber = 9999;
             FakeDataContext fake = new FakeDataContext();
             var builder = new TestControllerBuilder();
             var controller = new PlatnoscController(fake);
             builder.InitializeController(controller);
             builder.Form.Add("MERCHANTNUMBER", merchantNumber.ToString());
             builder.Form.Add("AUTHTIME", DateTime.Now.ToString());
             builder.Form.Add("DATATRANSMISJI", DateTime.Now.ToString());
             builder.Form.Add("ORDERNUMBER", orderNumber.ToString());

             var result = controller.Status();

             IRepository<PotwierdzeniaEcard> _rep = new Repository<PotwierdzeniaEcard>(fake);            
             var potwierdzeniaEcard = _rep.Find(p => p.ORDERNUMBER == orderNumber).First();
             Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));            
         } 
        [Test]
        public void NumerFaktury()
        {
             FakeDataContext fake = new FakeDataContext();
             IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);

             vPlatnosciEcard platnosc = new vPlatnosciEcard();
             platnosc = _rep.FindInvoiceById(1).SingleOrDefault();
             Assert.That(platnosc.Faktura_Numer, Is.EqualTo("222/2"));
        }
        [Test]
        public void AddPayment()
        {
            FakeDataContext fake = new FakeDataContext();
            IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake);

            vPlatnosciEcard platnosc = new vPlatnosciEcard();
            platnosc.ID_faktury = 13;
            platnosc.nip = "nipek";
            _rep.Insert(platnosc);

            vPlatnosciEcard pl1 = new vPlatnosciEcard();
            pl1.ID_faktury = 14;
            pl1.nip = "vv";
            _rep.Insert(pl1);

            vPlatnosciEcard pl = _rep.FindInvoiceById(13).SingleOrDefault();
            Assert.That(pl.nip, Is.EqualTo("nipek"));
        }
        
    }
}

