示例#1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- Fill -->
        /// <summary>
        ///      Fill a command from a node's restricitons
        /// </summary>
        /// <param name="restrictions"></param>
        /// <param name="cmd"></param>
        public void Fill(XmlNode node)
        {
            Dictionary <string, List <string> > restrictions = new Dictionary <string, List <string> >();
            RichXmlNode rxNode = new RichXmlNode(node);

            restrictions = rxNode.CollectRestrictions();


            // --------------------------------------------------------------------------
            //  Unpack the restrictions
            // --------------------------------------------------------------------------
            foreach (string item in restrictions.Keys)
            {
                string str = Regex.Replace(item, "^.*:", "");
                switch (item)
                {
                case "xs:enumeration": Enumerations = restrictions[item];                    break;

                case "xs:maxLength": MaxLength = _gen_.Integer(restrictions[item][0], 840); break;

                case "xs:minLength": MinLength = _gen_.Integer(restrictions[item][0], 0);   break;

                case "xs:pattern": RegexPattern = restrictions[item][0];                 break;

                case "xs:whiteSpace": WhiteSpace = restrictions[item][0];                 break;

                case "xs:length":
                default:
                    throw new NotSupportedException("Code not yet written"
                                                    + " to support the string restriction"
                                                    + " " + item + ".");
                }
            }
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- CreateNumElements -->
        /// <summary>
        ///      Comes up with a random number based on the minimum and maximum bounds for a node
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected override int CreateNumElements(RichXmlNode node)
        {
            if (node == null)
            {
                return(-999);
            }


            string minOccurs = node.Attribute("minOccurs");  //  included minBound
            string maxOccurs = node.Attribute("maxOccurs");
            Random r         = RandomSource.New().Random;
            int    minNum    = 1;
            int    maxNum    = 1;
            int    num       = 1;


            if (node.Attribute("name") == "PV2_26")
            {
                Pause();
            }


            // --------------------------------------------------------------------------
            //  Determine number of elements to create
            // --------------------------------------------------------------------------
            if (!string.IsNullOrEmpty(minOccurs))
            {
                minNum = _gen_.Integer(minOccurs, 0);
            }
            if (!string.IsNullOrEmpty(maxOccurs))
            {
                maxNum = _gen_.Integer(maxOccurs, minNum + r.Next(1, 4) * r.Next(0, 5));
            }
            num = r.Next(minNum, maxNum + 1);


            // --------------------------------------------------------------------------
            //  If something strange happened...
            // --------------------------------------------------------------------------
            if (minNum > maxNum)
            {
                throw new ArithmeticException("XmlGenerator.NumElements error - min number greater than max number");
            }

            return(num);
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- CreateNumberOfElements -->
        /// <summary>
        ///      Comes up with a random number based on the minimum and maximum bounds for a node
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected override int CreateNumberOfElements(RichXmlNode node)
        {
            int num = CreateNumElements(node);

            return(num);
        }