private IEnumerable <IDictionary <string, string> > GetMinimumTestingScenarioCombinations( ScenarioBuilderType scenarioType = ScenarioBuilderType.All) { if (scenarioType == ScenarioBuilderType.All) { yield return(null); yield return(new Dictionary <string, string>()); } // You should test all known scenarios foreach (var knownCombination in this.scenarioContexts.KnownCombinations) { if (scenarioType == ScenarioBuilderType.All || (scenarioType == ScenarioBuilderType.ValidOnly && knownCombination.CombinationType == ScenarioCombinationType.AlwaysValid) || (scenarioType == ScenarioBuilderType.InvalidOnly && knownCombination.CombinationType == ScenarioCombinationType.AlwaysInvalid)) { yield return(knownCombination.ScenariosKeys.ToDictionary( kv => kv.ContextName, kv => kv.ScenarioName)); } } }
private IDictionary <string, string> ValidateScenarioBuilderConfiguration( ScenarioBuilderType scenarioBuilderType, IDictionary <string, string> scenarioCombinationConfiguration) { if (!EnumExtensions.AllowedScenarioBuilderTypes.Contains((int)scenarioBuilderType)) { throw new ArgumentException( Errors.ScenarioBuilderTypeInvalid); } if (scenarioBuilderType == ScenarioBuilderType.ValidOnly && !this.scenarioContexts.HasAlwaysValidKnownScenario) { throw new ArgumentException( Errors.ScenarioBuilderDoesnotContainAlwaysValidKnownScenario); } if (scenarioBuilderType == ScenarioBuilderType.InvalidOnly && !this.scenarioContexts.HasAlwaysInvalidKnownScenario) { throw new ArgumentException( Errors.ScenarioBuilderDoesnotContainAlwaysInvalidKnownScenario); } return(this.scenarioContexts.ValidateScenarioConfigurationBuilder( scenarioBuilderType, scenarioCombinationConfiguration)); }
private T Generate( ScenarioBuilderType scenarioBuilderType, IDictionary <string, string> scenarioCombinationConfiguration, bool validateBuilderConfiguration) { if (scenarioCombinationConfiguration == null) { scenarioCombinationConfiguration = new Dictionary <string, string>(); } if (validateBuilderConfiguration) { scenarioCombinationConfiguration = this.ValidateScenarioBuilderConfiguration( scenarioBuilderType, scenarioCombinationConfiguration); } var fullScenarioBuilderRules = this.scenarioContexts.GetFullScenarioBuilderRules( scenarioCombinationConfiguration); var scenarioFaker = this.GetOrCreateFakerScenario( fullScenarioBuilderRules); return(scenarioFaker.Generate()); }
private IDictionary <string, string> ValidateCombinationConfigurationBuilderValues( ScenarioBuilderType scenarioCombinationType, IDictionary <string, string> scenarioCombinationConfiguration) { var parentGroupsRegex = string.Empty; this.ValidateScenarioCombinationConfigurationValues( scenarioCombinationConfiguration, (builderScenarioKey) => { if (scenarioCombinationType != ScenarioBuilderType.All) { parentGroupsRegex += Keys.GetScenarioContextKeyValueRegexValue( builderScenarioKey.ContextIndex, builderScenarioKey.ScenarioName); } }); if (scenarioCombinationType == ScenarioBuilderType.All) { return(scenarioCombinationConfiguration); } var compatiblesCombinations = this.ValidateParentScenarioCombinationBuilderConfiguration( scenarioCombinationType, parentGroupsRegex); return(this.GetCompatibleScenarioCombinationConfiguration( compatiblesCombinations, scenarioCombinationConfiguration)); }
public T Generate( ScenarioBuilderType scenarioBuilderType = ScenarioBuilderType.All, IDictionary <string, string> scenarioCombinationConfiguration = null) { return(this.Generate( scenarioBuilderType, scenarioCombinationConfiguration, true)); }
internal IDictionary <string, string> ValidateScenarioConfigurationBuilder( ScenarioBuilderType builderType, IDictionary <string, string> scenarioCombinationConfiguration) { this.ValidateScenarioCombinationConfigurationKeys( scenarioCombinationConfiguration); return(this.ValidateCombinationConfigurationBuilderValues( builderType, scenarioCombinationConfiguration)); }
public IEnumerable <T> GenerateMinimumTestingScenarios( ScenarioBuilderType scenarioBuilderType = ScenarioBuilderType.All) { foreach (var scenarioCombinationConfiguration in this.GetMinimumTestingScenarioCombinations( scenarioBuilderType)) { yield return(this.Generate( scenarioBuilderType, scenarioCombinationConfiguration, false)); } }
private List <KnownCombination> ValidateParentScenarioCombinationBuilderConfiguration( ScenarioBuilderType scenarioCombinationType, string parentGroupsRegex) { var compatiblesCombinations = new List <KnownCombination>(); var parentsRegex = Keys.GetKeyRegex(parentGroupsRegex); var allowedCombinationType = scenarioCombinationType == ScenarioBuilderType.ValidOnly ? ScenarioCombinationType.AlwaysValid : ScenarioCombinationType.AlwaysInvalid; var disallowedCombinationType = scenarioCombinationType == ScenarioBuilderType.ValidOnly ? ScenarioCombinationType.AlwaysInvalid : ScenarioCombinationType.AlwaysValid; foreach (var knownCombination in this.knownCombinations .Where(kv => (string.IsNullOrWhiteSpace(parentGroupsRegex) && kv.Value.CombinationType == allowedCombinationType) || (parentsRegex.IsMatch(kv.Key) && kv.Value.CombinationType != ScenarioCombinationType.Unknown))) { if (knownCombination.Value.CombinationType == disallowedCombinationType) { throw new ArgumentException( string.Format( Errors.ScenarioCombinationConfigHasConflictWithKnownScenarioCombinationConfig, scenarioCombinationType, knownCombination.Key, knownCombination.Value.CombinationType)); } else { compatiblesCombinations.Add(knownCombination.Value); } } if (compatiblesCombinations.Count == 0) { throw new ArgumentException( string.Format( Errors.ScenarioCombinationConfigHasNoCompatibleKnownScenarioCombinationConfig, scenarioCombinationType)); } return(compatiblesCombinations); }
public IEnumerable <T> Generate( int count, ScenarioBuilderType scenarioBuilderType = ScenarioBuilderType.All, IDictionary <string, string> scenarioCombinationConfiguration = null) { if (count <= 0) { throw new ArgumentException( Errors.InvalidNumberOfRows); } return(Enumerable .Range(1, count) .Select(_ => this.Generate( scenarioBuilderType, scenarioCombinationConfiguration))); }