using NUnit.Framework;
using WatiN.Core;

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

        [Test]
        [Category("UI")]
        public void Can_Not_Login_When_Using_InValid_Login_Information()
        {
            ie.TextField(Find.ByName("numerFaktury")).TypeText("");
            ie.TextField(Find.ByName("nip")).TypeText("");
            ie.Button(Find.ById("loguj")).Click();
            Assert.IsTrue(ie.ContainsText("Logowanie nie powiodło się"));
        }
        
        [Test]
        [Category("UI")]
        public void Can_Login_When_Using_Correct_Login_Information()
        {
            var uiData = _uiHelper.CreateAndAddTestRecordToRepository(10);
            
            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();
            Assert.IsTrue(ie.ContainsText("Szczegóły zlecenia"));
            
            _uiHelper.DeleteTestRecordsFromRepository(uiData);
        }
    }
}