using NUnit.Framework;
using WatiN.Core;

namespace adMoto.Payments.Test.UI
{
    [TestFixture]
    public class eCardValidationTests
    {
        private readonly UIHelper _uiHelper = new UIHelper();
        private static string adres = UIHelper.ConfirmForm;

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_Merchantnumber_Longer_Than_Fifty_Characters()
        {
            var merchantnumberTooLong = "123456789012345678901234567890123456789012345678901234";
            var ie = new IE(adres);
            ie.TextField(Find.ByName("MERCHANTNUMBER")).TypeText(merchantnumberTooLong);
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("MERCHANTNUMBER"));
            _uiHelper.CloseWebBrowser(ie);
        }
                
                
        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_FormatException_When_Passing_OrderNumber_In_Wrong_Format()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("ORDERNUMBER")).TypeText("aaaaaaaa");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("FormatException"));
            _uiHelper.CloseWebBrowser(ie);
        }
        
        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_ValidationCode_Longer_Than_Three_Characters()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("VALIDATIONCODE")).TypeText("1111");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("VALIDATIONCODE"));
            _uiHelper.CloseWebBrowser(ie);
        }
       
        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_FormatException_When_Passing_Authtime_Is_Wrong_Format()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("AUTHTIME")).TypeText("aaaaaa");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("FormatException"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_SqlTypeException_When_Passing_Authtime_Is_Overflow()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("AUTHTIME")).TypeText("0001-01-01 00:00:00");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("SqlTypeException"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_Bin_Longer_Than_Six_Characters()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("BIN")).TypeText("11111111");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("BIN"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_FormatException_When_Passing_EventType_In_Wrong_Format()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("EVENTTYPE")).TypeText("212dsf");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("FormatException"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_FormatException_When_Passing_PaymentNumber_In_Wrong_Format()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("PAYMENTNUMBER")).TypeText("AAAA");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("FormatException"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_PreviousState_Longer_Than_Fifty_Characters()
        {
            var previousstateTooLong = "123456789012345678901234567890123456789012345678901234";
            var ie = new IE(adres);
            ie.TextField(Find.ByName("PREVIOUSSTATE")).TypeText(previousstateTooLong);
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("PREVIOUSSTATE"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_CurrentState_Longer_Than_Fifty_Characters()
        {
            var currentstateTooLong = "123456789012345678901234567890123456789012345678901234";
            var ie = new IE(adres);
            ie.TextField(Find.ByName("CURRENTSTATE")).TypeText(currentstateTooLong);
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("CURRENTSTATE"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_ApprovalCode_Longer_Than_Fifty_Characters()
        {
            var approvalcodeTooLong = "123456789012345678901234567890123456789012345678901234";
            var ie = new IE(adres);
            ie.TextField(Find.ByName("APPROVALCODE")).TypeText(approvalcodeTooLong);
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("APPROVALCODE"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_CommType_Longer_Than_Fifty_Characters()
        {
            var commtypeTooLong = "123456789012345678901234567890123456789012345678901234";
            var ie = new IE(adres);
            ie.TextField(Find.ByName("COMMTYPE")).TypeText(commtypeTooLong);
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("COMMTYPE"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_Type_Longer_Than_Two_Characters()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("TYPE")).TypeText("11222");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("TYPE"));
            _uiHelper.CloseWebBrowser(ie);
        }

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_ArgumentException_When_Passing_WithCvc_Longer_Than_Three_Characters()
        {
            var ie = new IE(adres);
            ie.TextField(Find.ByName("WITHCVC")).TypeText("1112");
            ie.Button(Find.ById("dalej")).Click();
            Assert.IsTrue(ie.ContainsText("FALSE"));
            Assert.IsTrue(ie.ContainsText("WITHCVC"));
            _uiHelper.CloseWebBrowser(ie);
        }      
       
    }
}
