public List <ScenarioModel> UngroupingByParameter <TParameterType>( [NotNull] ModelContainer container, [NotNull] string parameterName, [NotNull] Func <IEnumerable <MethodActionModel>, IEnumerable <IGrouping <TParameterType, MethodActionModel> > > groupMethod) { var scenarios = container.GetAll <ScenarioModel>().Where(s => s.HasSequence); var newScenarios = new List <ScenarioModel>(); var names = new HashSet <string>(container.GetAll <ScenarioModel>().Select(s => s.Name)); foreach (var scenario in scenarios) { var scenarioParameterValue = scenario.Definitions.Where(d => d.Name == parameterName).Single().Expression.ToString(); var methods = scenario.Actions.OfType <MethodActionModel>(); var groups = groupMethod(methods); if (groups.All(g => g.Key.ToString() == scenarioParameterValue.Trim('"'))) { continue; } if (groups.Count() == 1) { UpdateScenarioDefinitionModel(scenario, parameterName, groups.First().Key); continue; } names.Remove(scenario.Name); foreach (var group in groups) { var newScenario = CreateScenarioWithMethods(scenario, group, container); PrepareName(newScenario, names); UpdateScenarioDefinitionModel(newScenario, parameterName, group.Key); newScenarios.Add(newScenario); } Remove(scenario); container.Remove(scenario.Id); } return(newScenarios); }
private void DeleteAllSceanriosPostfix([NotNull] ModelContainer container) { var scenarios = container.GetAll <ScenarioModel>(); foreach (var scenario in scenarios) { var postfixStartIndex = scenario.Name.LastIndexOf('-'); if (postfixStartIndex < 0) { continue; } scenario.Name = scenario.Name.Substring(0, postfixStartIndex); } }
public List <ScenarioModel> Ungrouping([NotNull] ModelContainer container, [CanBeNull] Func <ScenarioModel, bool> isIdoneous) => Ungrouping(container.GetAll <ScenarioModel>(), container, isIdoneous);