Exemple #1
0
        public void TestGetValidator()
        {
            XType     t = new XType("t");
            Field     f = new Field("f");
            Field     g = new Field("g");
            Validator v = Validator_int.Get(0);

            t.PutValidator(f, v);

            Assert.AreEqual(v, t.GetValidator(f));
            Assert.IsNull(t.GetValidator(g));
        }
Exemple #2
0
        /// <summary>
        /// Overriding Dictionary's Add(key, value) function
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void Add(Field key, Object value)
        {
            if (value == null)
            {
                fields.Remove(key);
                return;
            }

            if (level != Validator.Level.NONE)
            {
                Validator v = type.GetValidator(key);

                if (v == null && level == Validator.Level.FULL)
                {
                    throw new ArgumentException(String.Format(
                                                    "validator missing for type {0} field {1}", type, key));
                }

                if (v != null && !v.Validate(value))
                {
                    throw new ArgumentException(String.Format(
                                                    "validator {0} failed for type {1} field {2} : value {3}",
                                                    v, type, key, value));
                }
            }

            fields[key] = value;
        }
Exemple #3
0
        public void TestPutValidatorNull()
        {
            XType     t = new XType("t");
            Field     f = new Field("f");
            Validator v = Validator_int.Get(0);

            Assert.IsNull(t.GetValidator(f));

            t.PutValidator(f, null);
            Assert.IsNull(t.GetValidator(f));

            t.PutValidator(f, v);
            Assert.AreEqual(v, t.GetValidator(f));

            t.PutValidator(f, v);
            Assert.AreEqual(typeof(ComboValidator), (t.GetValidator(f)).GetType());

            t.ClearValidator(f);
            Assert.IsNull(t.GetValidator(f));
        }