using NUnit.Framework;
using WatiN.Core;

namespace adMoto.Payments.Test.UI
{
    [TestFixture]
    public class AuthenticationTests
    {
        private readonly UIHelper _uiHelper = new UIHelper();
        private static string adres = UIHelper.LoginSite;
        
        [Test]
        [Category("UI")]
        public void Can_Not_Login_When_Using_InValid_Login_Information()
        {
            var ie = new IE(adres);
            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ę"));
            _uiHelper.CloseWebBrowser(ie);
        }
        
        [Test]
        [Category("UI")]
        public void Can_Login_When_Using_Correct_Login_Information()
        {
            var uiData = _uiHelper.CreateAndAddTestRecordToRepository(0);

            var ie = new IE(adres);
            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.CloseWebBrowser(ie);
            _uiHelper.DeleteTestRecordsFromRepository(uiData);
        }
    }
}