public override object ReadJson(JsonReader reader,
                                        Type objectType, object existingValue, JsonSerializer serializer)
        {
            var jo = JObject.Load(reader);

            var type = jo["Type"]?.Value <string>();

            ValidationRule item = null;

            switch (type)
            {
            case nameof(CheckBoxCheckedValidationRule):
                item = new CheckBoxCheckedValidationRule();
                break;

            case nameof(ComboBoxSelectionRequiredValidationRule):
                item = new ComboBoxSelectionRequiredValidationRule();
                break;

            case nameof(TextFieldLengthValidationRule):
                item = new TextFieldLengthValidationRule();
                break;

            default:
                return(null);
            }

            serializer.Populate(jo.CreateReader(), item);

            return(item);
        }
Exemplo n.º 2
0
        public void TextField_IsValid_SingleValidRuleShouldReturnTrue()
        {
            var test_content = "test content";

            _testRulesList.Clear();
            var _newRule = new TextFieldLengthValidationRule(EqualityOperator.EqualTo, test_content.Length);

            _testRulesList.Add(_newRule);

            _textField         = new TextField(_testName, LabelPosition.AboveElement, _testLabel, _testRulesList);
            _textField.Content = test_content;

            var allRulesPass = _textField.IsValid();

            Assert.IsTrue(allRulesPass, "A TextField with one passing rule should be valid");
        }