/// <summary>
        /// Extractor nodes are more complicated objects, they needs to be managed differently
        /// because they have a
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static IExtratorNode GetExtractorNode(XElement element)
        {
            String        elementName = element.Name.LocalName;
            IExtratorNode node        = (IExtratorNode)FromXml(element.ToString(), MappedTypes[elementName]);

            return(node);
        }
        /// <summary>
        /// Create the first validator found into configuration file.
        /// </summary>
        /// <returns></returns>
        public Core.Validator CreateValidator()
        {
            Core.Validator validator            = new Core.Validator();
            XElement       validatorNode        = Configuration.Elements("validator").First();
            Type           resourceType         = null;
            XElement       resourceTypeNameNode = validatorNode.Elements("resource").FirstOrDefault();

            if (resourceTypeNameNode != null)
            {
                String resourceTypeName = resourceTypeNameNode.Attribute("name").Value;

                resourceType = Type.GetType(resourceTypeName);
                if (resourceType == null)
                {
                    throw new ConfigurationErrorsException(
                              String.Format("The type {0} specified for resource is not valid", resourceTypeName));
                }
            }
            foreach (XElement typeNode in validatorNode.Elements("type"))
            {
                Type currentType = Type.GetType(typeNode.Attribute("name").Value);
                if (currentType == null)
                {
                    throw new ConfigurationErrorsException("Configuration node " + typeNode.ToString() + " validate type " +
                                                           typeNode.Attribute("name").Value + " that does not exists");
                }
                //A node can have one or more rules, rules are simply extractor with inner validators
                foreach (XElement ruleNode in typeNode.Elements())
                {
                    IExtratorNode node = XmlHelper.GetExtractorNode(ruleNode);
                    node.Configure(resourceType, currentType, validator);
                }
            }
            return(validator);
        }
        public void DeserializationOfExtractorEmpty()
        {
            XElement      element = XElement.Parse("<member name='field'></member>");
            IExtratorNode rule    = XmlHelper.GetExtractorNode(element);

            Assert.That(rule, Is.TypeOf <MemberExtractorNode>());
            MemberExtractorNode extractor = (MemberExtractorNode)rule;

            Assert.That(extractor.RuleNodes, Has.Count.EqualTo(0));
        }
        public void DeserializationOfExtractorDoubledRule()
        {
            XElement      element = XElement.Parse("<member name='field'><required /><range><min>100</min><max>200</max></range></member>");
            IExtratorNode rule    = XmlHelper.GetExtractorNode(element);

            Assert.That(rule, Is.TypeOf <MemberExtractorNode>());
            MemberExtractorNode extractor = (MemberExtractorNode)rule;

            Assert.That(extractor.RuleNodes, Has.Count.EqualTo(2));
            Assert.That(extractor.RuleNodes[0], Is.InstanceOf <RequiredRuleNode>());
            Assert.That(extractor.RuleNodes[1], Is.InstanceOf <RangeRuleNode>());
        }
        public void DeserializationOfExtractorWeird()
        {
            XmlHelper.AddType(typeof(WeirdRuleNode));
            XElement      element = XElement.Parse("<member name='field'><required /><weird /></member>");
            IExtratorNode rule    = XmlHelper.GetExtractorNode(element);

            Assert.That(rule, Is.TypeOf <MemberExtractorNode>());
            MemberExtractorNode extractor = (MemberExtractorNode)rule;

            Assert.That(extractor.RuleNodes, Has.Count.EqualTo(2));
            Assert.That(extractor.RuleNodes[0], Is.InstanceOf <RequiredRuleNode>());
            Assert.That(extractor.RuleNodes[1], Is.InstanceOf <WeirdRuleNode>());
        }