using NUnit.Framework;
using WatiN.Core;

namespace adMoto.Payments.Test.UI
{
    [TestFixture]
    public class ValidationTests : 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 Validates_When_Firstname_Is_Too_Long()
        {
            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("12345678901234567890123456");
            ie.TextField(Find.ByName("Payer.LastName")).TypeText(test);
            ie.Button(Find.ById("place")).Click();
            Assert.IsTrue(ie.ContainsText("Zbyt długa nazwa"));

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

        [Test]
        [Category("UI")]
        public void Validates_When_Surname_Is_Too_Long()
        {
            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("1234567890123456789012345678901");
            ie.Button(Find.ById("place")).Click();
            Assert.IsTrue(ie.ContainsText("Zbyt długa nazwa"));

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

        [Test]
        [Category("UI")]
        public void Validates_When_LastName_Is_Empty()
        {
            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("");
            ie.Button(Find.ById("place")).Click();
            Assert.IsTrue(ie.ContainsText("Proszę podać"));

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