예제 #1
0
        public void MaxLengthConstraintWillFailValidation(int count)
        {
            // setup
            var textField   = new Field(XDocumentFactory.XmlWithOneForm().Element("forms").Element("form").Element("fields").Element("field"));
            var textControl = new TextControl(textField);

            // Act
            textControl.Value = new string('a', count);

            // Verify
            Assert.IsFalse(textControl.IsValid());
            Assert.AreEqual("First Name must be less than 100 characters", textControl.ErrorMessage);
        }
예제 #2
0
        public void CanCreateValidRequiredTextField()
        {
            // setup
            var textField   = new Field(XDocumentFactory.XmlWithOneForm().Element("forms").Element("form").Element("fields").Element("field"));
            var textControl = new TextControl(textField);

            // Act
            textControl.Value = "some value";

            // Verify
            Assert.IsTrue(textControl.IsValid());
            Assert.IsNull(textControl.ErrorMessage);
        }
예제 #3
0
        public void CanCreateTextControl()
        {
            // setup
            var textField = new Field(XDocumentFactory.XmlWithOneForm().Element("forms").Element("form").Element("fields").Element("field"));

            // Act
            var textControl = new TextControl(textField);

            // Verify
            Assert.IsNotNull(textControl.Field);
            Assert.AreEqual("text", textControl.Type);
            Assert.IsNull(textControl.ErrorMessage);
            Assert.IsNull(textControl.Value);
            Assert.IsFalse(textControl.IsValid());
        }
예제 #4
0
        public void MaxLengthConstraintWillPassWhenLenghtIsSame()
        {
            // setup
            var textField = new Field(XDocumentFactory.XmlWithOneForm()
                                      .Element("forms")
                                      .Element("form")
                                      .Element("fields")
                                      .Element("field"));

            var textControl = new TextControl(textField);

            // Act
            textControl.Value = new string('a', 100);

            // Verify
            Assert.IsTrue(textControl.IsValid());
            Assert.IsNull(textControl.ErrorMessage);
        }
예제 #5
0
        public void TooManyDecimalPlacesConstraintWillFire()
        {
            // setup
            var grossSalaryField = XDocumentFactory.XmlWithOneForm()
                                   .Element("forms")
                                   .Element("form")
                                   .Element("fields")
                                   .Elements("field")
                                   .ToList()[10];

            var textField   = new Field(grossSalaryField);
            var textControl = new TextControl(textField);

            // Act
            textControl.Value = "11.0000";

            // Verify
            Assert.IsFalse(textControl.IsValid());
            Assert.AreEqual("Gross Salary has too many decimal places (max 2)", textControl.ErrorMessage);
        }
예제 #6
0
        public void DecimalPlacesConstraintWillPass(string validValues)
        {
            // setup
            // get field with decimal place constraint
            var grossSalaryField = XDocumentFactory.XmlWithOneForm()
                                   .Element("forms")
                                   .Element("form")
                                   .Element("fields")
                                   .Elements("field")
                                   .ToList()[10];

            var textField   = new Field(grossSalaryField);
            var textControl = new TextControl(textField);

            // Act
            textControl.Value = validValues;

            // Verify
            Assert.IsTrue(textControl.IsValid());
            Assert.IsNull(textControl.ErrorMessage);
        }