public void AddValidatable(TValidator validator)
        {
            ValidatorNode node = new ValidatorNode(validator, this);

            InsertInTable(node);
            validator.UniqueDeterminingPropertyUpdated += node.UpdateNodeInTable;
        }
        public void RemoveValidatable(TValidator validator)
        {
            ValidatorNode node = FindNode(validator);

            node.UpdateHashCode();
            RemoveFromTable(node);
            validator.UniqueDeterminingPropertyUpdated -= node.UpdateNodeInTable;
        }
Example #3
0
        public void Validate (ValidatorNode node, Validator validator)
        {
            // must have zero or more saucers
            if (node.AsInt32("Saucers") < 0) {
                validator.SetErrorMessage(node, "must have zero or more saucers");
            }

            // must have positive time value
            if (node.AsInt32("Time") <= 0) {
                validator.SetErrorMessage(node, "time must be greater than zero");
            }
        }
        private void InsertInTable(ValidatorNode validatorNode)
        {
            int hash = validatorNode.HashCode;

            if (m_HashTable[hash] == null)
            {
                m_HashTable[hash] = new List <ValidatorNode>();
            }

            m_HashTable[hash].Add(validatorNode);
            CheckListForUniqueness(m_HashTable[hash]);
        }
Example #5
0
    public void SetErrorMessage()
    {
        Validator validator = new Validator();

        ValidatorNode node = new ValidatorNode();
        node.lineNumber = 1;


        validator.SetErrorMessage(node, "foo bar baz");

        Assert.AreEqual(false, node.valid, "node should be false");
        Assert.AreEqual("error line: 1: foo bar baz", node.message, "node should have error set");
    }
        private void RemoveFromTable(ValidatorNode validatorNode)
        {
            int hash = validatorNode.HashCode;

            if (m_HashTable[hash] == null || m_HashTable[hash].Count == 0)
            {
                return;
            }

            if (m_HashTable[hash].Remove(validatorNode))
            {
                CheckListForUniqueness(m_HashTable[hash]);
            }

            if (m_HashTable[hash].Count == 0)
            {
                m_HashTable[hash] = null;
            }
        }