Exemple #1
0
        public override object Generate(ColumnModel model)
        {
            if (model is not RandomPatternModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            var result = specModel.Template;

            while (true)
            {
                var regex = new Regex(UtilDataGeneration.SourceNameExpression);
                var match = regex.Match(result);
                if (!match.Success)
                {
                    break;
                }

                var patternName    = match.Groups[1].Value;
                var currentPattern = specModel.Patterns.ContainsKey(patternName) ? specModel.Patterns[patternName] :
                                     _defaultPatterns.ContainsKey(patternName) ? _defaultPatterns[patternName] : "ABC";
                var c = UtilRandom.GetCharFromString(currentPattern, _rnd);
                result = regex.Replace(result, c.ToString(), 1);
            }

            return(result);
        }
Exemple #2
0
        public override object Generate(ColumnModel model)
        {
            if (model is not RandomCharsModel specModel)
            {
                throw new ApplicationException("Mismatch in model " + model.ColumnDefinitionType +
                                               " inside generator " + GetType().Name);
            }
            var resultLength = UtilRandom.NextInteger(specModel.MinLength, specModel.MaxLength, _rnd);
            var sb           = new StringBuilder();

            for (var i = 0; i < resultLength; i++)
            {
                var c = UtilRandom.GetCharFromString(specModel.AllowedChars, _rnd);
                sb.Append(c);
            }

            return(sb.ToString());
        }