using adMoto.Payments.Core;
using adMoto.Payments.Core.Data;
using adMoto.Payments.Core.Interfaces;
using adMoto.Payments.Test.Fakes;
using adMoto.Payments.Web.Controllers;
using adMoto.Payments.Web.Models;
using NUnit.Framework;
using System.Web.Mvc;

namespace adMoto.Payments.Test.Controllers
{
    [TestFixture]
    public class MerchantControllerTests
    {
        private readonly TestDataHelper _testDataHelper = new TestDataHelper();
        private readonly ITranslateManager _translateManager = new FakeTranslation();

        [Test]
        [Category("Unit")]
        public void Merchant_Action_Returns_Error_When_Passing_Incorrect_User_Identity()
        {
            //Arrange
            IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
            var invoice = _testDataHelper.CreateInvoice(123, "nip1", "", 0, 0);
            repVPayment.Insert(invoice);
            
            var payer = _testDataHelper.CreatePayer(123, "test", "test");
            
            var controller = new MerchantController(repVPayment, null, _translateManager);
            controller.ControllerContext = _testDataHelper.CreateControllerContext("nip2");

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

            //Assert
            Assert.That(error.Error, Is.EqualTo("weryfikacja"));
            Assert.That(result.ViewName, Is.EqualTo("Error1"));
        }

        [Test]
        [Category("Unit")]
        public void Merchant_Action_Returns_Error_When_Payment_Is_Not_Found()
        {
            //Arrange
            IRepository<Invoice> repVPayment = new Repository<Invoice>(new FakeDataContext());
            var invoice = _testDataHelper.CreateInvoice(12, "nip1", "", 0, 0);
            repVPayment.Insert(invoice);

            var payer = _testDataHelper.CreatePayer(123, "test", "test");

            var controller = new MerchantController(repVPayment, null, _translateManager);
            controller.ControllerContext = _testDataHelper.CreateControllerContext("nip2");

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

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