Пример #1
0
        /// <summary>
        /// Builds the dynamic scenario.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="bddComponents">The BDD components.</param>
        /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param>
        /// <param name="dirtyStatus">If set to <c>true</c> [dirty status].</param>
        private void BuildDynamicScenario(BDDExtensionRunner script, Component[] bddComponents, bool lockParametersRows, out bool dirtyStatus)
        {
            bool   givenDirtyStatus = false;
            bool   whenDirtyStatus  = false;
            bool   thenDirtyStatus  = false;
            string undoText;
            MethodParametersLoader parametersLoader = new MethodParametersLoader();
            RunnerEditorBusinessLogicMethodsUtilities    methodsUtilities    = new RunnerEditorBusinessLogicMethodsUtilities();
            RunnerEditorBusinessLogicDynamicRowsElements dynamicRowsElements = new RunnerEditorBusinessLogicDynamicRowsElements();
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder        = new BaseMethodDescriptionBuilder();
            MethodDescriptionBuilder     methodDescriptionBuilder            = new MethodDescriptionBuilder();
            IMethodsFilter methodFilter  = new MethodsFilterByStepType();
            MethodsLoader  methodsLoader = new MethodsLoader(baseMethodDescriptionBuilder, methodFilter);

            ChosenMethods chosenMethods = new ChosenMethods();

            chosenMethods.ChosenMethodsNames           = script.Given;
            chosenMethods.ChosenMethodsParametersIndex = script.GivenParametersIndex;

            this.runnerBusinessLogicData.Rebuild = this.businessLogicDynamicRows.DrawDynamicRows <GivenBaseAttribute>(this.unityIntefaceWrapper, methodsLoader, methodDescriptionBuilder, parametersLoader, bddComponents, chosenMethods, this.runnerBusinessLogicData.GivenFoldouts, this.runnerBusinessLogicData.SerializedObjects, script, methodsUtilities, dynamicRowsElements, lockParametersRows, this.runnerBusinessLogicData.Rebuild, out chosenMethods, out this.runnerBusinessLogicData.GivenFoldouts, out givenDirtyStatus, out undoText);
            this.RegisterUndoInformation(this.target, bddComponents, undoText);
            script.Given = chosenMethods.ChosenMethodsNames;
            script.GivenParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            chosenMethods.ChosenMethodsNames           = script.When;
            chosenMethods.ChosenMethodsParametersIndex = script.WhenParametersIndex;

            this.runnerBusinessLogicData.Rebuild = this.businessLogicDynamicRows.DrawDynamicRows <WhenBaseAttribute>(this.unityIntefaceWrapper, methodsLoader, methodDescriptionBuilder, parametersLoader, bddComponents, chosenMethods, this.runnerBusinessLogicData.WhenFoldouts, this.runnerBusinessLogicData.SerializedObjects, script, methodsUtilities, dynamicRowsElements, lockParametersRows, this.runnerBusinessLogicData.Rebuild, out chosenMethods, out this.runnerBusinessLogicData.WhenFoldouts, out whenDirtyStatus, out undoText);
            this.RegisterUndoInformation(this.target, bddComponents, undoText);

            script.When = chosenMethods.ChosenMethodsNames;
            script.WhenParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            chosenMethods.ChosenMethodsNames           = script.Then;
            chosenMethods.ChosenMethodsParametersIndex = script.ThenParametersIndex;
            this.runnerBusinessLogicData.Rebuild       = this.businessLogicDynamicRows.DrawDynamicRows <ThenBaseAttribute>(this.unityIntefaceWrapper, methodsLoader, methodDescriptionBuilder, parametersLoader, bddComponents, chosenMethods, this.runnerBusinessLogicData.ThenFoldouts, this.runnerBusinessLogicData.SerializedObjects, script, methodsUtilities, dynamicRowsElements, lockParametersRows, this.runnerBusinessLogicData.Rebuild, out chosenMethods, out this.runnerBusinessLogicData.ThenFoldouts, out thenDirtyStatus, out undoText);
            this.RegisterUndoInformation(this.target, bddComponents, undoText);

            script.Then = chosenMethods.ChosenMethodsNames;
            script.ThenParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            dirtyStatus = givenDirtyStatus || whenDirtyStatus || thenDirtyStatus;
        }
        /// <summary>
        /// Draws the dynamic rows.
        /// </summary>
        /// <typeparam name="T">The type of the Step Methods.</typeparam>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="methodsLoader">The methods loader.</param>
        /// <param name="methodDescriptionBuilder">The method description builder.</param>
        /// <param name="parametersLoader">The parameters loader.</param>
        /// <param name="bddComponents">The BDD components.</param>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="foldouts">The foldouts.</param>
        /// <param name="serializedObjects">The serialized objects.</param>
        /// <param name="target">The target.</param>
        /// <param name="methodsUtilities">The methods utilities.</param>
        /// <param name="dynamicRowsElements">The dynamic rows elements.</param>
        /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param>
        /// <param name="rebuild">If set to <c>true</c> [rebuild].</param>
        /// <param name="updatedChosenMethodsList">The updated chosen methods list.</param>
        /// <param name="updatedFoldouts">The updated foldouts.</param>
        /// <param name="dirtyStatus">If set to <c>true</c> [dirty status].</param>
        /// <param name="undoText">The undo text.</param>
        /// <returns>True if a rebuild of the parameters index is requested.</returns>
        public bool DrawDynamicRows <T>(
            IUnityInterfaceWrapper unityInterface,
            MethodsLoader methodsLoader,
            MethodDescriptionBuilder methodDescriptionBuilder,
            MethodParametersLoader parametersLoader,
            Component[] bddComponents,
            ChosenMethods chosenMethods,
            bool[] foldouts,
            Dictionary <Type, ISerializedObjectWrapper> serializedObjects,
            UnityEngine.Object target,
            RunnerEditorBusinessLogicMethodsUtilities methodsUtilities,
            RunnerEditorBusinessLogicDynamicRowsElements dynamicRowsElements,
            bool lockParametersRows,
            bool rebuild,
            out ChosenMethods updatedChosenMethodsList,
            out bool[] updatedFoldouts,
            out bool dirtyStatus,
            out string undoText) where T : IGivenWhenThenDeclaration
        {
            updatedChosenMethodsList = (ChosenMethods)chosenMethods.Clone();
            updatedFoldouts          = new bool[foldouts.Length];
            Array.Copy(foldouts, updatedFoldouts, foldouts.Length);
            undoText    = string.Empty;
            dirtyStatus = false;

            List <BaseMethodDescription> methodsList = methodsLoader.LoadStepMethods <T>(bddComponents);

            string[] methodsNames = methodsUtilities.GetMethodsNames(methodsList);

            FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder();

            for (int index = 0; index < chosenMethods.ChosenMethodsNames.Length; index++)
            {
                MethodDescription methodDescription = methodsUtilities.GetMethodDescription(methodDescriptionBuilder, parametersLoader, chosenMethods, methodsList, index);

                methodsNames = methodsUtilities.CheckMissedMethod(chosenMethods, methodsNames, index, methodDescription);

                List <FullMethodDescription> fullMethodDescriptionsList = fullMethodDescriptionBuilder.Build(methodDescription, (uint)index + 1);

                unityInterface.EditorGUILayoutBeginHorizontal();
                dynamicRowsElements.DrawFoldoutSymbol(unityInterface, updatedFoldouts, index, fullMethodDescriptionsList);

                dynamicRowsElements.DrawLabel <T>(unityInterface, index);
                float textSize = (unityInterface.EditorGUIUtilityCurrentViewWidth() - RunnerEditorBusinessLogicData.LabelWidthAbsolute - RunnerEditorBusinessLogicData.ButtonsWidthAbsolute) * RunnerEditorBusinessLogicData.TextWidthPercent;
                dynamicRowsElements.DrawDescription(unityInterface, chosenMethods.ChosenMethodsNames[index], methodDescription, textSize);

                string newChosenMethod = dynamicRowsElements.DrawComboBox(unityInterface, chosenMethods.ChosenMethodsNames[index], methodsNames);
                rebuild     = methodsUtilities.UpdateDataIfNewMethodIsChosen(newChosenMethod, updatedChosenMethodsList, updatedFoldouts, index, rebuild, out undoText);
                dirtyStatus = dirtyStatus || dynamicRowsElements.DrawAddRowButton(unityInterface, index, updatedChosenMethodsList, target, undoText, out updatedChosenMethodsList, out undoText);
                dirtyStatus = dirtyStatus || dynamicRowsElements.DrawRemoveRowButton(unityInterface, index, updatedChosenMethodsList, target, undoText, out updatedChosenMethodsList, out undoText);
                if (dirtyStatus)
                {
                    break;
                }

                dynamicRowsElements.DrawCogButton(unityInterface, methodDescription, (BDDExtensionRunner)target);
                unityInterface.EditorGUILayoutEndHorizontal();

                dynamicRowsElements.DrawParametersRows(unityInterface, foldouts[index], fullMethodDescriptionsList, serializedObjects, lockParametersRows);
            }

            return(rebuild);
        }