using NUnit.Framework;
using WatiN.Core;

namespace adMoto.Payments.Test.UI
{
    [TestFixture]
    public class MerchantTests : BaseTests
    {
        private readonly UIHelper _uiHelper = new UIHelper();
        private static string adres = UIHelper.LoginSite;
        private UIData uiData;
        private const string test = "test";
       
        [SetUp]
        public void SetUp()
        {
            System.Diagnostics.Debug.WriteLine("nowy test");
            _uiHelper.SearchAndClean();
            ie.GoTo(adres);
        }

        [Test]
        [Category("UI")]
        public void Returns_ZlyHash_When_Invoice_Amount_Is_Zero()
        {
            // wartosc testowej faktury 1/SLJ/1 jest 0 (zero)
            // wowczas eCard powinien zwrocic zlyHash - stala informujaca, ze cos jest nie tak...
            uiData = _uiHelper.CreateAndAddTestRecordToRepository(0);

            ie.TextField(Find.ByName("numerFaktury")).TypeText(uiData.Test_numer_faktury);
            ie.TextField(Find.ByName("nip")).TypeText(uiData.Test_nip);
            ie.Button(Find.ById("loguj")).Click();

            ie.TextField(Find.ByName("Payer.FirstName")).TypeText(test);
            ie.TextField(Find.ByName("Payer.LastName")).TypeText(test);
            ie.Button(Find.ById("place")).Click();
            Assert.IsTrue(ie.ContainsText("Wystąpił nieoczekiwany błąd"));

            //usuniecie rekordu z tabel: FAKTURY, FAKTURA_DETAILS
            _uiHelper.DeleteTestRecordsFromRepository(uiData);
        }

        [Test]
        [Category("UI")]
        public void Redirects_To_Ecard_When_All_Details_Are_Correct()
        {
            //dodanie testowego rekordu do tabel: FAKTURY, FAKTURA_DETAILS
            uiData = _uiHelper.CreateAndAddTestRecordToRepository(2);
            
            ie.TextField(Find.ByName("numerFaktury")).TypeText(uiData.Test_numer_faktury);
            ie.TextField(Find.ByName("nip")).TypeText(uiData.Test_nip);
            ie.Button(Find.ById("loguj")).Click();

            ie.TextField(Find.ByName("Payer.FirstName")).TypeText(test);
            ie.TextField(Find.ByName("Payer.LastName")).TypeText(test);
            ie.Button(Find.ById("place")).Click();
            Assert.IsTrue(ie.ContainsText("Imię i nazwisko:" + test + " " + test));
            Assert.IsTrue(ie.Url.Contains("https://pay.ecard.pl/"));
           
            //usuniecie rekordu z tabel: FAKTURY, FAKTURA_DETAILS
            _uiHelper.DeleteTestRecordsFromRepository(uiData);

            //usuniecie rekordu z tabeli PatnosciEcard
            _uiHelper.DeleteTestPaymentFromRepository(uiData);
        }
        
    }
}