using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Platnosci.Core.Linq;
using Platnosci.Core.Interface;
using MvcContrib.TestHelper;
using Platnosci.Controllers;
using Platnosci.Models;
using System.Web.Mvc;

namespace Platnosci.Tests.Web
{
    [TestFixture] 
    class MerchantControllerTests
    {
        private Function _f = new Function();
        private ITranslate _t = new FakeTranslate();

        [Test]
        [Category("Unit")]
        public void IncorrectUserIdentity_ReturnErrorView()
        {
            IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
            vPlatnosciEcard platnosc = _f.createInvoice(123, "nip1", "", 0, 0);
            repVPayment.Insert(platnosc);

            Payer payer = _f.createPayer(123, "test", "test");

            var controller = new PlatnoscController(repVPayment, null, null, _t);
            controller.ControllerContext = _f.createControllerContext("nip2");

            var result = controller.Show(payer, "pl") as ViewResult;
            var error = (ErrorViewData)result.ViewData.Model;

            Assert.That(error.error, Is.EqualTo("weryfikacja"));
            Assert.That(result.ViewName, Is.EqualTo("Error1"));
        }
        [Test]
        [Category("Unit")]
        public void PaymentNotFound_ReturnErrorView()
        {
            IRepository<vPlatnosciEcard> repVPayment = new Repository<vPlatnosciEcard>(new FakeDataContext());
            vPlatnosciEcard platnosc = _f.createInvoice(12, "nip1", "", 0, 0);
            repVPayment.Insert(platnosc);

            Payer payer = _f.createPayer(123, "test", "test");

            var controller = new PlatnoscController(repVPayment, null, null, _t);
            controller.ControllerContext = _f.createControllerContext("nip2");

            var result = controller.Show(payer, "pl") as ViewResult;
            var error = (ErrorViewData)result.ViewData.Model;

            Assert.That(error.error, Is.EqualTo("brakdanych"));
            Assert.That(result.ViewName, Is.EqualTo("Error1"));
        }
        
    }
}
