Пример #1
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 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);
        }