internal void AddKnownCombination(
            ScenarioCombinationType combinationType,
            ScenarioKey scenarioKey)
        {
            var knownCombination = new KnownCombination(combinationType, scenarioKey);

            this.AddKnownCombination(knownCombination);
        }
Пример #2
0
 internal KnownCombination(
     ScenarioCombinationType combinationType,
     params ScenarioKey[] scenariosKeys)
 {
     this.CombinationType = combinationType;
     this.CombinationKey  = string.Concat(scenariosKeys.Select(kv => kv.KeyValue));
     this.ScenariosKeys   = new List <ScenarioKey>(scenariosKeys);
 }
        /// <summary>
        /// Add a Known Valid Scenario Combination to the <see cref="IScenariosBuilder{T}" />
        /// </summary>
        /// <param name="scenarioCombinationConfiguration">
        /// A dictionary with the builder parameters that can used to build an <see cref="ScenarioCombinationType.AlwaysValid"/> model.
        /// Key: Scenario Context Name
        /// Value: Scenario Name
        /// </param>
        /// <param name="scenarioCombinationType">
        /// Indicates if the Current Scenario will be <see cref="ScenarioCombinationType.Unknown"/>, <see cref="ScenarioCombinationType.AlwaysValid"/> or <see cref="ScenarioCombinationType.AlwaysInvalid"/>
        /// </param>
        /// <returns>Returns the current instance of the <see cref="IScenariosBuilder{T}" /> (fluent interface)</returns>
        public IScenariosBuilder <T> KnownScenarioCombination(
            IDictionary <string, string> scenarioCombinationConfiguration,
            ScenarioCombinationType scenarioCombinationType = ScenarioCombinationType.Unknown)
        {
            this.scenarioContexts.AddKnownCombination(
                scenarioCombinationType,
                scenarioCombinationConfiguration);

            return(this);
        }
 /// <summary>
 /// Add a new Invalid Scenario to the current Default Scenario Context
 /// </summary>
 /// <param name="action">The actions that will be executed to the Invalid Scenario</param>
 /// <param name="scenarioType">
 /// Indicates if the Current Scenario will be <see cref="ScenarioCombinationType.Unknown"/>, <see cref="ScenarioCombinationType.AlwaysValid"/> or <see cref="ScenarioCombinationType.AlwaysInvalid"/>
 /// </param>
 /// <returns>Returns the current instance of the <see cref="IScenariosBuilder{T}" /> (fluent interface)</returns>
 public IScenariosBuilder <T> DefaultContextInvalidScenario(
     Action <IScenarioRuleSet <T> > action,
     ScenarioCombinationType scenarioType = ScenarioCombinationType.Unknown)
 {
     return(this.Scenario(
                true,
                Defaults.ScenarioInvalidName,
                scenarioType,
                action));
 }
        internal void AddKnownCombination(
            ScenarioCombinationType combinationType,
            IDictionary <string, string> scenarioCombinationConfiguration)
        {
            var knownCombination = this.ValidateKnownCombinationConfiguration(
                combinationType,
                scenarioCombinationConfiguration);

            this.AddKnownCombination(knownCombination);
        }
 /// <summary>
 /// Add a new Scenario to the current Scenario Context
 /// </summary>
 /// <param name="scenarioName">Indicates the name of the Scenario</param>
 /// <param name="action">The actions that will be executed to the current Scenario</param>
 /// <param name="scenarioType">
 /// Indicates if the Current Scenario will be <see cref="ScenarioCombinationType.Unknown"/>, <see cref="ScenarioCombinationType.AlwaysValid"/> or <see cref="ScenarioCombinationType.AlwaysInvalid"/>
 /// </param>
 /// <returns>Returns the current instance of the <see cref="IScenariosBuilder{T}" /> (fluent interface)</returns>
 public IScenariosBuilder <T> Scenario(
     string scenarioName,
     Action <IScenarioRuleSet <T> > action,
     ScenarioCombinationType scenarioType = ScenarioCombinationType.Unknown)
 {
     return(this.Scenario(
                false,
                scenarioName,
                scenarioType,
                action));
 }
        private KnownCombination ValidateKnownCombinationConfiguration(
            ScenarioCombinationType combinationType,
            IDictionary <string, string> scenarioCombinationConfiguration)
        {
            this.ValidateKnownCombinationConfigurationBuilder(
                scenarioCombinationConfiguration);

            this.ValidateScenarioCombinationConfigurationKeys(
                scenarioCombinationConfiguration);

            this.CurrentScenarioContext.ValidateContextCompleted();

            return(this.ValidateKnownCombinationConfigurationBuilderValues(
                       combinationType,
                       scenarioCombinationConfiguration));
        }
        private KnownCombination ValidateKnownCombinationConfigurationBuilderValues(
            ScenarioCombinationType scenarioCombinationType,
            IDictionary <string, string> scenarioCombinationConfiguration)
        {
            var scenariosKeys       = new List <ScenarioKey>();
            var parentGroupsRegex   = string.Empty;
            var childrenGroupsRegex = string.Empty;

            this.ValidateScenarioCombinationConfigurationValues(
                scenarioCombinationConfiguration,
                (builderScenarioKey) =>
            {
                scenariosKeys.Add(builderScenarioKey);

                parentGroupsRegex += Keys.GetScenarioContextKeyValueRegexValue(
                    builderScenarioKey.ContextIndex,
                    builderScenarioKey.ScenarioName);

                childrenGroupsRegex += Keys.GetScenarioContextKeyValueRegexValue(
                    builderScenarioKey.ContextIndex,
                    builderScenarioKey.ScenarioName,
                    false);
            },
                (index) =>
            {
                childrenGroupsRegex += Keys.GetScenarioContextKeyValueRegexValue(
                    index);
            });

            var knownCombination = new KnownCombination(
                scenarioCombinationType,
                scenariosKeys.ToArray());

            this.ValidateParentKnownScenarioCombinationConfiguration(
                knownCombination.CombinationKey,
                parentGroupsRegex);

            if (scenarioCombinationType != ScenarioCombinationType.Unknown)
            {
                this.ValidateChildrenKnownScenarioCombinationConfiguration(
                    childrenGroupsRegex);
            }

            return(knownCombination);
        }
        /// <summary>
        /// Add a new Scenario to the current Scenario Context
        /// </summary>
        /// <param name="hasDefaultScenarioContext">Indicates if the method was called by a Default Scenario Context (true) or a Custom Scenario Context (false)</param>
        /// <param name="scenarioName">Indicates the name of the Scenario</param>
        /// <param name="scenarioType">
        /// Indicates if the Current Scenario will be <see cref="ScenarioCombinationType.Unknown"/>, <see cref="ScenarioCombinationType.AlwaysValid"/> or <see cref="ScenarioCombinationType.AlwaysInvalid"/>
        /// </param>
        /// <param name="action">The actions that will be executed to the current Scenario</param>
        /// <returns>Returns the current instance of the <see cref="IScenariosBuilder{T}" /> (fluent interface)</returns>
        private ScenariosFaker <T> Scenario(
            bool hasDefaultScenarioContext,
            string scenarioName,
            ScenarioCombinationType scenarioType,
            Action <IScenarioRuleSet <T> > action)
        {
            this.ValidateAction(action);

            var scenarioKey = this.scenarioContexts.AddScenario(
                hasDefaultScenarioContext,
                scenarioName,
                scenarioType);

            this.scenariosActions.Add(scenarioKey.KeyValue, action);

            this.scenarioContexts.AddKnownCombination(
                scenarioType,
                scenarioKey);

            return(this);
        }
        /// <summary>
        /// Validate the Scenario and returns the Scenario Key
        /// </summary>
        /// <param name="hasDefaultScenarioContext">
        /// Flag that indicates if the method was called by a Default Scenario Context method (true)
        /// or a Custom Scenario Context method (false)
        /// </param>
        /// <param name="scenarioName">Indicates the name of the Scenario</param>
        /// <param name="scenarioType">
        /// Indicates if the Current Scenario will be <see cref="ScenarioCombinationType.Unknown"/>, <see cref="ScenarioCombinationType.AlwaysValid"/> or <see cref="ScenarioCombinationType.AlwaysInvalid"/>
        /// </param>
        /// <returns>The Scenario Key</returns>
        internal ScenarioKey AddScenario(
            bool hasDefaultScenarioContext,
            string scenarioName,
            ScenarioCombinationType scenarioType)
        {
            var scenarioKey = this.CurrentScenarioContext.AddScenario(
                hasDefaultScenarioContext,
                scenarioName,
                scenarioType);

            if (this.CurrentScenarioContext.ScenariosCount > 1)
            {
                if (this.CurrentScenarioContext.ScenariosCount > 2)
                {
                    this.CountPossibleScenariosCombinations /= (ulong)(this.CurrentScenarioContext.ScenariosCount - 1);
                }

                this.CountPossibleScenariosCombinations *= (ulong)this.CurrentScenarioContext.ScenariosCount;
            }

            return(scenarioKey);
        }