using NUnit.Framework;
using WatiN.Core;

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

        [SetUp]
        public void SetUp()
        {
            System.Diagnostics.Debug.WriteLine("nowy test");
            _uiHelper.SearchAndClean();
            ie.GoTo(adres);
        }

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

        [Test]
        [Category("UI")]
        public void Status_Returns_False_And_Throws_SqlTypeException_When_Passing_Authtime_Is_Overflow()
        {
            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"));
        }

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

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

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

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

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

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

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

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

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