using NUnit.Framework;
using Platnosci.Core.Linq;
using Platnosci.Core.Interface;
using Platnosci.Controllers;
using Platnosci.Models;
using System.Web.Mvc;

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

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

            Payer payer = _function.CreatePayer(123, "test", "test");

            var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
            controller.ControllerContext = _function.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 = _function.CreateInvoice(12, "nip1", "", 0, 0);
            repVPayment.Insert(platnosc);

            Payer payer = _function.CreatePayer(123, "test", "test");

            var controller = new PlatnoscController(repVPayment, null, null, _translateManager);
            controller.ControllerContext = _function.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"));
        }
        
    }
}
