/// <summary>
        /// Checks if there is a missed method and adds it at the end of the combo box list..
        /// </summary>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="methodsNames">The methods names.</param>
        /// <param name="index">The index.</param>
        /// <param name="methodDescription">The method description.</param>
        /// <returns>The updated combo box list.</returns>
        public string[] CheckMissedMethod(ChosenMethods chosenMethods, string[] methodsNames, int index, MethodDescription methodDescription)
        {
            if (methodDescription == null)
            {
                methodsNames = this.AddMissedMethodNameToMethodsNames(chosenMethods.ChosenMethodsNames[index], methodsNames);
            }

            return(methodsNames);
        }
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>The cloned object.</returns>
        public object Clone()
        {
            ChosenMethods newObject = new ChosenMethods();

            newObject.chosenMethodsNames = new string[this.chosenMethodsNames.Length];
            Array.Copy(this.chosenMethodsNames, newObject.chosenMethodsNames, this.chosenMethodsNames.Length);
            newObject.chosenMethodsParametersIndex = new string[this.chosenMethodsParametersIndex.Length];
            Array.Copy(this.chosenMethodsParametersIndex, newObject.chosenMethodsParametersIndex, this.chosenMethodsParametersIndex.Length);
            return(newObject);
        }
        /// <summary>
        /// Detect if the data in the inspector need to be updated.
        /// </summary>
        /// <param name="newChosenMethod">The new chosen method.</param>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="foldouts">The foldouts.</param>
        /// <param name="index">The index.</param>
        /// <param name="rebuild">If set to <c>true</c> [rebuild].</param>
        /// <param name="newUndoText">The new undo text.</param>
        /// <returns>True if the data in the inspector need to be updated, false otherwise.</returns>
        public bool UpdateDataIfNewMethodIsChosen(string newChosenMethod, ChosenMethods chosenMethods, bool[] foldouts, int index, bool rebuild, out string newUndoText)
        {
            newUndoText = string.Empty;
            if (!newChosenMethod.Equals(chosenMethods.ChosenMethodsNames[index]))
            {
                chosenMethods.ChosenMethodsNames[index] = newChosenMethod;
                newUndoText     = "Change Step Method";
                foldouts[index] = false;
                rebuild         = true;
            }

            return(rebuild);
        }
Esempio n. 4
0
        public void Clone_Should_ReturnAnEqualObject()
        {
            ChosenMethods original = new ChosenMethods();

            original.ChosenMethodsNames = new string[3] {
                "Name1", "Name3", "Name2"
            };
            original.ChosenMethodsParametersIndex = new string[3] {
                "indexParameter1", "indexParameter3", "indexParameter2"
            };
            ChosenMethods clone = (ChosenMethods)original.Clone();

            Assert.AreEqual(original.ChosenMethodsNames, clone.ChosenMethodsNames, "the clone method for the class ChosenMethods returns a different names list");
            Assert.AreEqual(original.ChosenMethodsParametersIndex, clone.ChosenMethodsParametersIndex, "the clone method for the class ChosenMethods returns a different indexes list");
        }
Esempio n. 5
0
        public void UpdateDataIfNewMethodIsChosen_Should_UpdateTheExpectedDataAndReturnTrue_Given_TheCurrentChosenMethodIsDifferenToThePrevious()
        {
            RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities();

            string[] expectedChosenMethodsNames = new string[3] {
                "DynamicBDDForTest.SecondWhenMethod", "DynamicBDDForTest.SecondWhenMethod", string.Empty
            };

            string[] expectedChosenMethodsParametersIndex = new string[3] {
                "FirstParametersIndex", "SecondParametersIndex", string.Empty
            };

            bool[] expectedFoldouts = new bool[10] {
                false, true, true, true, true, true, true, true, true, true
            };

            bool expectedRebuild = true;

            string        newChosenMethod = "DynamicBDDForTest.SecondWhenMethod";
            ChosenMethods chosenMethods   = new ChosenMethods();

            chosenMethods.ChosenMethodsNames = new string[3] {
                "DynamicBDDForTest.WhenMethod", "DynamicBDDForTest.SecondWhenMethod", string.Empty
            };
            chosenMethods.ChosenMethodsParametersIndex = new string[3] {
                "FirstParametersIndex", "SecondParametersIndex", string.Empty
            };
            bool[] foldouts = new bool[10] {
                true, true, true, true, true, true, true, true, true, true
            };
            int    index    = 0;
            bool   rebuild  = false;
            string undoText = string.Empty;

            rebuild = methodsUtilities.UpdateDataIfNewMethodIsChosen(newChosenMethod, chosenMethods, foldouts, index, rebuild, out undoText);

            Assert.AreEqual(expectedChosenMethodsNames, chosenMethods.ChosenMethodsNames, "The method UpdateDataIfNewMethodIsChosen does not return the right ChosenMethods object");

            Assert.AreEqual(expectedChosenMethodsParametersIndex, chosenMethods.ChosenMethodsParametersIndex, "The method UpdateDataIfNewMethodIsChosen does not return the right ChosenMethods object");

            Assert.AreEqual(expectedFoldouts, foldouts, "The method UpdateDataIfNewMethodIsChosen does not return the right foldout state");

            Assert.AreEqual(expectedRebuild, rebuild, "The method UpdateDataIfNewMethodIsChosen does not return the right rebuild state");
        }
        /// <summary>
        /// Draws the add row button.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="currentIndex">Index of the current.</param>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="target">The target.</param>
        /// <param name="undoText">The undo text.</param>
        /// <param name="newChosenMethods">The new chosen methods.</param>
        /// <param name="newUndoText">The new undo text.</param>
        /// <returns>Returns true if the inspector needs to be redrawn.</returns>
        public bool DrawAddRowButton(IUnityInterfaceWrapper unityInterface, int currentIndex, ChosenMethods chosenMethods, UnityEngine.Object target, string undoText, out ChosenMethods newChosenMethods, out string newUndoText)
        {
            newUndoText = undoText;
            bool dirty = false;

            newChosenMethods = new ChosenMethods();
            newChosenMethods.ChosenMethodsNames           = chosenMethods.ChosenMethodsNames;
            newChosenMethods.ChosenMethodsParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            if (unityInterface.GUILayoutButton("+", EditorStyles.miniButton, unityInterface.GUILayoutWidth(20)))
            {
                newUndoText = "Add Step Method row";
                string[] newArrayMethodsNames           = new string[newChosenMethods.ChosenMethodsNames.Length + 1];
                string[] newArrayMethodsParametersIndex = new string[newChosenMethods.ChosenMethodsParametersIndex.Length + 1];
                int      newIndex = 0;
                for (int tempIndex = 0; tempIndex < chosenMethods.ChosenMethodsNames.Length; tempIndex++)
                {
                    if (tempIndex == currentIndex + 1)
                    {
                        newArrayMethodsNames[newIndex]           = string.Empty;
                        newArrayMethodsParametersIndex[newIndex] = string.Empty;
                        newIndex++;
                    }

                    newArrayMethodsNames[newIndex]           = newChosenMethods.ChosenMethodsNames[tempIndex];
                    newArrayMethodsParametersIndex[newIndex] = newChosenMethods.ChosenMethodsParametersIndex[tempIndex];
                    newIndex++;
                }

                if (newArrayMethodsNames[newArrayMethodsNames.Length - 1] == null)
                {
                    newArrayMethodsNames[newArrayMethodsNames.Length - 1]           = string.Empty;
                    newArrayMethodsParametersIndex[newArrayMethodsNames.Length - 1] = string.Empty;
                }

                newChosenMethods.ChosenMethodsNames           = newArrayMethodsNames;
                newChosenMethods.ChosenMethodsParametersIndex = newArrayMethodsParametersIndex;
                unityInterface.EditorUtilitySetDirty(target);
                dirty = true;
            }

            return(dirty);
        }
Esempio n. 7
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>
        /// Gets the method description.
        /// </summary>
        /// <param name="methodDescriptionBuilder">The method description builder.</param>
        /// <param name="parametersLoader">The parameters loader.</param>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="methodsList">The methods list.</param>
        /// <param name="index">The index.</param>
        /// <returns>The method description.</returns>
        public MethodDescription GetMethodDescription(MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader parametersLoader, ChosenMethods chosenMethods, List <BaseMethodDescription> methodsList, int index)
        {
            MethodDescription methodDescription = null;

            if (!chosenMethods.ChosenMethodsNames[index].Equals(string.Empty))
            {
                methodDescription = this.GetMethodDescriptionForTheChosenMethod(methodDescriptionBuilder, parametersLoader, chosenMethods.ChosenMethodsNames[index], chosenMethods.ChosenMethodsParametersIndex[index], methodsList);
            }

            return(methodDescription);
        }
        /// <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);
        }