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()
        {
            IRepositoryPT _rep = new RepositoryPotwierdzeniaEcard();
            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;

            var builder = new TestControllerBuilder();
            var controller = new PlatnoscController();
            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();

            IRepositoryPT _rep = new RepositoryPotwierdzeniaEcard();
            var potwierdzeniaEcard = _rep.Find(p => p.ORDERNUMBER == orderNumber).First();
            Assert.That(potwierdzeniaEcard.MERCHANTNUMBER, Is.EqualTo(merchantNumber));
            
        }
    }
}
