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

namespace adMoto.Payments.Test.Web
{
    [TestFixture]
    public class MerchantControllerTests
    {
        private readonly Function _function = new Function();
        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 platnosc = _function.CreateInvoice(123, "nip1", "", 0, 0);
            repVPayment.Insert(platnosc);
            
            var payer = _function.CreatePayer(123, "test", "test");
            
            var controller = new MerchantController(repVPayment, null, _translateManager);
            controller.ControllerContext = _function.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 platnosc = _function.CreateInvoice(12, "nip1", "", 0, 0);
            repVPayment.Insert(platnosc);

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

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