private void Generate(World world) { var dataProvider = world.CurrentData == null?new GeneratorDataProvider():new GeneratorDataProvider(world.CurrentData.DataLists); var generatedData = new List <IRuleValue>(); foreach (var globalRule in _ruleSet.GetGlobalRules()) { globalRule.Execute(world); } foreach (var rule in _ruleSet.GetRules()) { var inputParameters = rule.GetRuleInputs(world).ToList(); var inputDataList = inputParameters.Select(p => dataProvider.GetAll(p).ToList()).ToList(); if (inputDataList.Count <= 0) { continue; } foreach (var parameterValues in inputDataList) { parameterValues.Randomize(_random); } var count = inputDataList.Any(inputData => inputData.Count <= 0) ? 0 : inputDataList.Select(inputData => inputData.Count).Max(); var executionCount = (int)Math.Round(rule.GetExecutionProbability(world) * count); var inputList = new List <CompoundRuleInput>(); for (var i = 0; i < count; i++) { if (inputList.Count >= executionCount) { break; } var compoundRuleInput = new CompoundRuleInput(); inputDataList.ForEach(values => compoundRuleInput.AddParameterValue(values[i % values.Count])); if (compoundRuleInput.IsValidFor(inputParameters)) { inputList.Add(compoundRuleInput); } } //TODO: Use plinq here... but never give them the same value foreach (var inputValues in inputList.Where(ruleInput => ruleInput.Count == inputDataList.Count)) { generatedData.AddRange(rule.Execute(new CompoundRuleExecutionContext(inputValues, TestDataGenerator, world))); } } foreach (var result in generatedData) { dataProvider.Add(result); } world.CurrentData = new GeneratorResult(dataProvider.DataLists); }
internal CompoundRuleExecutionContext(CompoundRuleInput inputData, ITestDataGenerator testDataGenerator, IReadableWorld world) : base(testDataGenerator, world) { InputData = inputData; }
int[] IRuleParameter.ParameterPredicate(IRuleValue arg, CompoundRuleInput targetInput) { return(_getUnwantedParameterIndices?.Invoke((RuleValue <T>)arg, targetInput)); }