/// <summary>
        /// Draws the parameters rows.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="foldout">If set to <c>true</c> [foldout].</param>
        /// <param name="fullMethodDescription">The full method description.</param>
        /// <param name="serializedObjects">The serialized objects.</param>
        /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param>
        public void DrawParametersRows(IUnityInterfaceWrapper unityInterface, bool foldout, FullMethodDescription fullMethodDescription, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, bool lockParametersRows)
        {
            if (fullMethodDescription != null && foldout && !lockParametersRows)
            {
                ISerializedObjectWrapper serializedObject = null;
                serializedObjects.TryGetValue(fullMethodDescription.ComponentObject.GetType(), out serializedObject);

                foreach (MethodParameter parameter in fullMethodDescription.Parameters.Parameters)
                {
                    string            parameterName     = parameter.ParameterInfoObject.Name;
                    ParameterLocation parameterLocation = parameter.ParameterLocation;

                    // "given.Array.data[0]"
                    string     parameterLocationString = parameterLocation.ParameterArrayLocation.ArrayName + ".Array.data[" + parameterLocation.ParameterArrayLocation.ArrayIndex + "]";
                    GUIContent label = unityInterface.GUIContent(parameterName);
                    ISerializedPropertyWrapper property = serializedObject.FindProperty(parameterLocationString);
                    unityInterface.EditorGUILayoutPropertyField(property, label);
                }
            }

            if (fullMethodDescription != null && foldout && lockParametersRows)
            {
                float labelWidth = unityInterface.EditorGUIUtilityCurrentViewWidth();
                unityInterface.EditorGUILayoutLabelField("When there are some errors the parameters are protected to avoid data lost.", labelWidth);
            }
        }
        /// <summary>
        /// Draws the ComboBox for choosing the Step Method.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="selectedMethod">The selected method.</param>
        /// <param name="methodsArray">The methods array.</param>
        /// <returns>The chosen Step Method.</returns>
        public string DrawComboBox(IUnityInterfaceWrapper unityInterface, string selectedMethod, string[] methodsArray)
        {
            string[] methods = null;
            if (methodsArray.Length == 0)
            {
                methods = new string[1] {
                    string.Empty
                };
            }
            else if (!methodsArray[0].Equals(string.Empty))
            {
                methods    = new string[methodsArray.Length + 1];
                methods[0] = string.Empty;
                Array.Copy(methodsArray, 0, methods, 1, methodsArray.Length);
            }
            else
            {
                methods = new string[methodsArray.Length];
                Array.Copy(methodsArray, methods, methodsArray.Length);
            }

            string result = string.Empty;

            int index = this.GetIndexByValue(selectedMethod, methods);

            index  = unityInterface.EditorGUILayoutPopup(index, methods);
            result = methods[index];
            return(result);
        }
        /// <summary>
        /// Draws the parameters rows.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="foldout">If set to <c>true</c> [foldout].</param>
        /// <param name="fullMethodDescriptionsList">The full method descriptions list.</param>
        /// <param name="serializedObjects">The serialized objects.</param>
        /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param>
        public void DrawParametersRows(IUnityInterfaceWrapper unityInterface, bool foldout, List <FullMethodDescription> fullMethodDescriptionsList, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, bool lockParametersRows)
        {
            if (fullMethodDescriptionsList != null && fullMethodDescriptionsList.Count > 0 && foldout /* && !lockParametersRows*/)
            {
                bool theCallBeforeMethodsHaveParameters = false;
                foreach (FullMethodDescription fullMethodDescription in fullMethodDescriptionsList)
                {
                    if (fullMethodDescription.Parameters.Parameters.Length > 0)
                    {
                        if (fullMethodDescription.MainMethod != null)
                        {
                            theCallBeforeMethodsHaveParameters = true;
                        }

                        if (theCallBeforeMethodsHaveParameters)
                        {
                            unityInterface.EditorGUILayoutSeparator();
                            unityInterface.EditorGUILayoutBeginHorizontal();
                            float  currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth();
                            string text             = this.GetHeaderTextForFullMethodDescription(fullMethodDescription);
                            unityInterface.EditorGUILayoutLabelFieldTruncate(text, currentViewWidth);
                            unityInterface.EditorGUILayoutEndHorizontal();
                        }

                        this.DrawParametersRows(unityInterface, foldout, fullMethodDescription, serializedObjects, lockParametersRows);
                    }
                }

                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutSeparator();
            }
        }
        /// <summary>
        /// Draws the cog button.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="methodDescription">The method description.</param>
        /// <param name="bddExtensionRunner">The BDD extension runner.</param>
        internal void DrawCogButton(IUnityInterfaceWrapper unityInterface, MethodDescription methodDescription, BDDExtensionRunner bddExtensionRunner)
        {
            string cogTexture = @"cog.png";

            string    cogTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, cogTexture);
            Texture2D inputTexture       = unityInterface.AssetDatabaseLoadAssetAtPath(cogTextureFullPath, typeof(Texture2D));

            GUILayoutOption[] options = new GUILayoutOption[2] {
                unityInterface.GUILayoutWidth(16), unityInterface.GUILayoutHeight(16)
            };

            if (unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, options))
            {
                GenericMenu menu    = new GenericMenu();
                GUIContent  content = new GUIContent("Open method source");
                bool        on      = false;
                MethodInfo  method  = null;
                if (methodDescription != null)
                {
                    on     = true;
                    method = methodDescription.Method;
                    menu.AddItem(content, on, () => { SourcesManagement.OpenMethodSourceCode(method, unityInterface); });
                }
                else
                {
                    menu.AddDisabledItem(content);
                }

                menu.ShowAsContext();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Opens the source code of a BDD Component positioning the cursor to the method.
        /// </summary>
        /// <param name="methodInfo">The method information.</param>
        /// <param name="unityInterfaceWrapper">The unity interface wrapper.</param>
        /// <param name="assemblyDefinition">The assembly definition.</param>
        public static void OpenMethodSourceCode(MethodInfo methodInfo, IUnityInterfaceWrapper unityInterfaceWrapper, AssemblyDefinition assemblyDefinition)
        {
            SequencePoint sp          = GetSequencePointForMethod(methodInfo, assemblyDefinition);
            Document      document    = sp.Document;
            string        documentUrl = document.Url;

            unityInterfaceWrapper.UnityEditorInternalInternalEditorUtilityOpenFileAtLineExternal(documentUrl, sp.StartLine);
        }
Beispiel #6
0
        /// <summary>
        /// Opens the source code of a BDD Component.
        /// </summary>
        /// <param name="component">The component.</param>
        /// <param name="unityInterfaceWrapper">The unity interface wrapper.</param>
        public static void OpenSourceCode(Component component, IUnityInterfaceWrapper unityInterfaceWrapper)
        {
            MonoScript script = MonoScript.FromMonoBehaviour((MonoBehaviour)component);
            string     relativeDocumentUrl = AssetDatabase.GetAssetPath(script);
            string     absoluteDocumentUrl = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + relativeDocumentUrl;

            unityInterfaceWrapper.UnityEditorInternalInternalEditorUtilityOpenFileAtLineExternal(absoluteDocumentUrl, 0);
        }
        /// <summary>
        /// Determines whether the rebuild of the parameters indexes is needed.
        /// </summary>
        /// <param name="unityInterfaceWrapper">The unity interface wrapper.</param>
        /// <param name="runnerBusinessLogicData">The runner business logic data.</param>
        /// <param name="components">The components.</param>
        /// <param name="bddComponentsFilter">The BDD components filter.</param>
        /// <returns>
        ///   <c>true</c> if the rebuild of the parameters indexes is needed; otherwise, <c>false</c>.
        /// </returns>
        public bool IsParametersRebuildNeeded(IUnityInterfaceWrapper unityInterfaceWrapper, RunnerEditorBusinessLogicData runnerBusinessLogicData, Component[] components, ComponentsFilter bddComponentsFilter)
        {
            bool isBDDObjectsNull      = this.IsBDDObjectsNull(runnerBusinessLogicData);
            bool bddObjectsHaveChanged = this.BddObjectsHaveChanged(components, runnerBusinessLogicData, bddComponentsFilter);
            bool isEditorApplicationCompilingJustFinished = this.IsEditorApplicationCompilingJustFinished(unityInterfaceWrapper, runnerBusinessLogicData);
            bool isDynamicScenario = this.IsDynamicScenario(components);

            return(this.IsParametersRebuildNeeded(isBDDObjectsNull, bddObjectsHaveChanged, runnerBusinessLogicData.IsCompiling, isEditorApplicationCompilingJustFinished, runnerBusinessLogicData.Rebuild, isDynamicScenario));
        }
Beispiel #8
0
        /// <summary>
        /// Opens the source code of a BDD Component positioning the cursor to the method.
        /// </summary>
        /// <param name="methodInfo">The method information.</param>
        /// <param name="unityInterfaceWrapper">The unity interface wrapper.</param>
        public static void OpenMethodSourceCode(MethodInfo methodInfo, IUnityInterfaceWrapper unityInterfaceWrapper)
        {
            ReaderParameters readerParameters = new ReaderParameters {
                ReadSymbols = true
            };
            AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(GetAbsoluteDLLPathFromMethod(methodInfo), readerParameters);

            OpenMethodSourceCode(methodInfo, unityInterfaceWrapper, assemblyDefinition);
        }
Beispiel #9
0
        /// <summary>
        /// Draws the checkbox for choosing between update and fixed update.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="unityInterface">The unity interface.</param>
        private void ChooseBetweenUpdateAndFixedUpdate(BDDExtensionRunner script, IUnityInterfaceWrapper unityInterface)
        {
            GUIContent label  = unityInterface.GUIContent("Run under Fixed Update");
            bool       result = GUILayout.Toggle(script.UseFixedUpdate, label, GUILayout.ExpandWidth(false));

            if (result != script.UseFixedUpdate)
            {
                Undo.RecordObject(script, "Change the use of Fixed Update.");
                script.UseFixedUpdate = result;
            }
        }
        /// <summary>
        /// Draws the right label: "Given", "When", "Then" or "and".
        /// </summary>
        /// <typeparam name="T">The Step Method type.</typeparam>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="index">The index.</param>
        public void DrawLabel <T>(IUnityInterfaceWrapper unityInterface, int index) where T : IGivenWhenThenDeclaration
        {
            string label = StepMethodUtilities.GetStepMethodName <T>();

            if (index > 0)
            {
                label = "and";
            }

            unityInterface.EditorGUILayoutLabelField(label, RunnerEditorBusinessLogicData.LabelWidthAbsolute);
        }
        /// <summary>
        /// Draws the given errors.
        /// </summary>
        /// <param name="errors">The errors.</param>
        /// <param name="unityInterface">The unity interface.</param>
        public void Errors(List <UnityTestBDDError> errors, IUnityInterfaceWrapper unityInterface)
        {
            BDDExtensionRunner bddExtensionRunner = this.component.gameObject.GetComponent <BDDExtensionRunner>();
            string             openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.OpenComponentButtonTextureFileName);
            string             errorTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.ErrorTextureFileName);

            foreach (UnityTestBDDError error in errors)
            {
                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutEndHorizontal();
                unityInterface.EditorGUILayoutBeginHorizontal();
                float             currentViewWidth    = unityInterface.EditorGUIUtilityCurrentViewWidth();
                Texture2D         errorTexture        = unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D));
                GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2] {
                    unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24)
                };
                unityInterface.EditorGUILayoutLabelField(errorTexture, errorTextureOptions);
                float labelWidth = currentViewWidth - 100;
                unityInterface.EditorGUILayoutLabelField(error.Message, labelWidth);

                Texture2D         openComponentButtonTexture = unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D));
                GUILayoutOption[] options = new GUILayoutOption[2] {
                    unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24)
                };
                if (unityInterface.GUILayoutButton(openComponentButtonTexture, EditorStyles.label, options))
                {
                    if (error.MethodMethodInfo != null)
                    {
                        SourcesManagement.OpenMethodSourceCode(error.MethodMethodInfo, unityInterface);
                    }
                    else if (error.Component != null)
                    {
                        SourcesManagement.OpenSourceCode(error.Component, unityInterface);
                    }
                    else
                    {
                        MethodInfo[] methods = this.component.GetType().GetMethods();
                        foreach (MethodInfo method in methods)
                        {
                            if (method.DeclaringType.Name.Equals(this.component.GetType().Name))
                            {
                                SourcesManagement.OpenSourceCode(method, unityInterface);
                            }
                        }
                    }
                }

                unityInterface.EditorGUILayoutEndHorizontal();
            }
        }
        public void DrawStaticRows_Should_CallTheRightUnityEditoStatements_Given_AStaticComponentWithTwoWhenMethods()
        {
            Component[] bddComponents = new Component[1] {
                UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicStaticRowsTestStaticComponent>()
            };

            IUnityInterfaceWrapper unityInterface = Substitute.For <IUnityInterfaceWrapper>();

            unityInterface.EditorGUIUtilityCurrentViewWidth().Returns <float>(500F);

            BaseMethodDescriptionBuilder methodBuilder = Substitute.For <BaseMethodDescriptionBuilder>();

            BaseMethodDescriptionBuilder  baseMethodDescriptionBuilder  = new BaseMethodDescriptionBuilder();
            MethodsFilterByExecutionOrder methodsFilterByExecutionOrder = new MethodsFilterByExecutionOrder();
            MethodsLoader bddStepMethodsLoader = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByExecutionOrder);
            List <BaseMethodDescription> baseMethodDescriptionList = bddStepMethodsLoader.LoadStepMethods <WhenBaseAttribute>(bddComponents);
            MethodInfo whenMethodInfo       = typeof(RunnerEditorBusinessLogicStaticRowsTestStaticComponent).GetMethod("WhenMethod");
            MethodInfo secondWhenMethodInfo = typeof(RunnerEditorBusinessLogicStaticRowsTestStaticComponent).GetMethod("SecondWhenMethod");

            methodBuilder.Build <WhenBaseAttribute>(bddComponents[0], whenMethodInfo).Returns <BaseMethodDescription>(baseMethodDescriptionList[0]);

            methodBuilder.Build <WhenBaseAttribute>(bddComponents[0], secondWhenMethodInfo).Returns <BaseMethodDescription>(baseMethodDescriptionList[1]);

            IMethodsFilter methodFilter = Substitute.For <IMethodsFilter>();

            methodFilter.Filter <WhenBaseAttribute>(whenMethodInfo).Returns(true);
            methodFilter.Filter <WhenBaseAttribute>(secondWhenMethodInfo).Returns(true);

            object[] constructorArguments = new object[2] {
                new BaseMethodDescriptionBuilder(), new MethodsFilterByExecutionOrder()
            };
            MethodsLoader stepMethodsLoader = Substitute.For <MethodsLoader>(constructorArguments);

            stepMethodsLoader.LoadStepMethods <WhenBaseAttribute>(bddComponents).Returns(baseMethodDescriptionList);
            RunnerEditorBusinessLogicStaticRows runnerEditorBusinessLogicStaticRows = new RunnerEditorBusinessLogicStaticRows();

            runnerEditorBusinessLogicStaticRows.DrawStaticRows <WhenBaseAttribute>(unityInterface, stepMethodsLoader, bddComponents, RunnerEditorBusinessLogicData.LabelWidthAbsolute, RunnerEditorBusinessLogicData.ButtonsWidthAbsolute);
            Received.InOrder(() =>
            {
                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUIUtilityCurrentViewWidth();
                unityInterface.EditorGUILayoutLabelField("When", RunnerEditorBusinessLogicData.LabelWidthAbsolute);
                unityInterface.EditorGUILayoutLabelField("When method", 368);
                unityInterface.EditorGUILayoutEndHorizontal();

                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUIUtilityCurrentViewWidth();
                unityInterface.EditorGUILayoutLabelField("and", RunnerEditorBusinessLogicData.LabelWidthAbsolute);
                unityInterface.EditorGUILayoutLabelField("Second When method", 368);
                unityInterface.EditorGUILayoutEndHorizontal();
            });
        }
Beispiel #13
0
        public void IsEditorApplicationCompilingJustFinished_Should_ReturnTrueAndSetTheValueOfIsCompilingPropertyToFalse_Given_TheStateOfIsCompilingPropertyIsTrueAndTheStateOfTheEditorApplicationIsCompilingPropertyIsFalse()
        {
            RunnerEditorBusinessLogicParametersRebuild runnerEditorBusinessLogicParametersRebuild = new RunnerEditorBusinessLogicParametersRebuild();
            RunnerEditorBusinessLogicData runnerBusinessLogicData = new RunnerEditorBusinessLogicData();

            IUnityInterfaceWrapper unityInterfaceWrapper = Substitute.For <IUnityInterfaceWrapper>();

            unityInterfaceWrapper.EditorApplicationIsCompiling().Returns(false);
            runnerBusinessLogicData.IsCompiling = true;
            bool result = runnerEditorBusinessLogicParametersRebuild.IsEditorApplicationCompilingJustFinished(unityInterfaceWrapper, runnerBusinessLogicData);

            Assert.IsTrue(result, "The method IsEditorApplicationCompilingJustFinished doesn't return the right state of editor compilation just finished");
            Assert.IsFalse(runnerBusinessLogicData.IsCompiling, "The method IsEditorApplicationCompilingJustFinished doesn't return the right last state of editor compilation");
        }
        /// <summary>
        /// Draws the given errors.
        /// </summary>
        /// <param name="errors">The errors.</param>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="bddExtensionRunner">The BDD extension runner.</param>
        public void Errors(List <UnityTestBDDError> errors, IUnityInterfaceWrapper unityInterface, BDDExtensionRunner bddExtensionRunner)
        {
            string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.OpenComponentButtonTextureFileName);
            string errorTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.ErrorTextureFileName);

            foreach (UnityTestBDDError error in errors)
            {
                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutEndHorizontal();
                unityInterface.EditorGUILayoutBeginHorizontal();
                float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth();
                if (error.ShowRedExclamationMark)
                {
                    Texture2D         errorTexture        = unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D));
                    GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2] {
                        unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24)
                    };
                    unityInterface.EditorGUILayoutLabelField(errorTexture, errorTextureOptions);
                }

                float labelWidth = currentViewWidth - 100;
                unityInterface.EditorGUILayoutLabelField(error.Message, labelWidth);

                Texture2D         openComponentButtonTexture = unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D));
                GUILayoutOption[] options = new GUILayoutOption[2] {
                    unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24)
                };
                if (error.ShowButton)
                {
                    if (unityInterface.GUILayoutButton(openComponentButtonTexture, EditorStyles.label, options))
                    {
                        if (error.MethodMethodInfo != null)
                        {
                            SourcesManagement.OpenMethodSourceCode(error.MethodMethodInfo, unityInterface);
                        }
                        else if (error.Component != null)
                        {
                            SourcesManagement.OpenSourceCode(error.Component, unityInterface);
                        }
                    }
                }

                unityInterface.EditorGUILayoutEndHorizontal();
            }
        }
        /// <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);
        }
        /// <summary>
        /// Draws the Step Method sentence.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="chosenMethod">The chosen method.</param>
        /// <param name="methodDescription">The method description.</param>
        /// <param name="textSize">Size of the text.</param>
        public void DrawDescription(IUnityInterfaceWrapper unityInterface, string chosenMethod, MethodDescription methodDescription, float textSize)
        {
            string description = string.Empty;

            if (methodDescription != null)
            {
                description = methodDescription.GetDecodifiedText();
            }
            else if (chosenMethod.Equals(string.Empty))
            {
                description = ChoseMethodFromComboBox;
            }
            else
            {
                description = "### The method " + chosenMethod + " is missing ###";
            }

            unityInterface.EditorGUILayoutLabelField(description, textSize);
        }
        /// <summary>
        /// Determines whether the build process is just finished.
        /// </summary>
        /// <param name="unityInterfaceWrapper">The unity interface wrapper.</param>
        /// <param name="runnerBusinessLogicData">The runner business logic data.</param>
        /// <returns>
        ///   <c>true</c> if the build process is just finished; otherwise, <c>false</c>.
        /// </returns>
        public bool IsEditorApplicationCompilingJustFinished(IUnityInterfaceWrapper unityInterfaceWrapper, RunnerEditorBusinessLogicData runnerBusinessLogicData)
        {
            bool result = false;

            if (!unityInterfaceWrapper.EditorApplicationIsCompiling())
            {
                if (runnerBusinessLogicData.IsCompiling)
                {
                    result = true;
                    runnerBusinessLogicData.IsCompiling = false;
                }
            }
            else
            {
                runnerBusinessLogicData.IsCompiling = true;
                result = false;
            }

            return(result);
        }
        /// <summary>
        /// Draws the foldout symbol.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="updatedFoldouts">The updated foldouts.</param>
        /// <param name="index">The index.</param>
        /// <param name="fullMethodDescriptionList">The full method description list.</param>
        public void DrawFoldoutSymbol(IUnityInterfaceWrapper unityInterface, bool[] updatedFoldouts, int index, List <FullMethodDescription> fullMethodDescriptionList)
        {
            bool thereAreParameters = false;

            foreach (FullMethodDescription fullMethodDescription in fullMethodDescriptionList)
            {
                if (fullMethodDescription.Parameters.Parameters.Length > 0)
                {
                    thereAreParameters = true;
                }
            }

            if (thereAreParameters)
            {
                Rect rect = unityInterface.EditorGUILayoutGetControlRect();
                updatedFoldouts[index] = unityInterface.EditorGUIFoldout(rect, updatedFoldouts[index], string.Empty);
            }
            else
            {
                Rect rect = unityInterface.EditorGUILayoutGetControlRect();
                unityInterface.EditorGUIFoldout(rect, false, string.Empty, EditorStyles.label);
            }
        }
        /// <summary>
        /// Draws the static rows.
        /// </summary>
        /// <typeparam name="T">The Step Methods type.</typeparam>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="stepMethodsLoader">The step methods loader.</param>
        /// <param name="bddComponents">The BDD components.</param>
        /// <param name="labelWidthAbsolute">The label width absolute.</param>
        /// <param name="buttonsWidthAbsolute">The buttons width absolute.</param>
        public void DrawStaticRows <T>(IUnityInterfaceWrapper unityInterface, MethodsLoader stepMethodsLoader, Component[] bddComponents, float labelWidthAbsolute, float buttonsWidthAbsolute) where T : IGivenWhenThenDeclaration
        {
            List <BaseMethodDescription> methodsList = stepMethodsLoader.LoadStepMethods <T>(bddComponents);

            for (int index = 0; index < methodsList.Count; index++)
            {
                unityInterface.EditorGUILayoutBeginHorizontal();
                float  rowWidth = unityInterface.EditorGUIUtilityCurrentViewWidth() - labelWidthAbsolute - buttonsWidthAbsolute;
                float  textSize = rowWidth - 20;
                string label    = StepMethodUtilities.GetStepMethodName <T>();
                if (index > 0)
                {
                    label = "and";
                }

                unityInterface.EditorGUILayoutLabelField(label, labelWidthAbsolute);
                string description = string.Empty;

                description = methodsList[index].Text;
                unityInterface.EditorGUILayoutLabelField(description, textSize);
                this.DrawCogButton(unityInterface, methodsList[index]);
                unityInterface.EditorGUILayoutEndHorizontal();
            }
        }
        /// <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);
        }
Beispiel #21
0
        /// <summary>
        /// Draws the options.
        /// </summary>
        /// <param name="businessLogicData">The business logic data.</param>
        /// <param name="isStaticScenario">If set to <c>true</c> [is static scenario].</param>
        /// <param name="script">The script.</param>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="bddComponents">The BDD components.</param>
        private void DrawOptions(RunnerEditorBusinessLogicData businessLogicData, bool isStaticScenario, BDDExtensionRunner script, IUnityInterfaceWrapper unityInterface, Component[] bddComponents)
        {
            Rect rect = unityInterface.EditorGUILayoutGetControlRect();

            businessLogicData.OptionsFoldout = unityInterface.EditorGUIFoldout(rect, businessLogicData.OptionsFoldout, "Options");
            if (businessLogicData.OptionsFoldout)
            {
                if (!isStaticScenario)
                {
                    this.ForceRebuildParametersButton(script, bddComponents);
                }

                unityInterface.EditorGUILayoutSeparator();
                this.ChooseBetweenUpdateAndFixedUpdate(script, this.unityIntefaceWrapper);
                float  width = unityInterface.EditorGUIUtilityCurrentViewWidth();
                int    numberOfSeparatorChars = (int)width / 7;
                string text = string.Empty.PadLeft(numberOfSeparatorChars, '_');

                unityInterface.EditorGUILayoutLabelFieldTruncate(text, width);
            }
        }
        public void Errors_Should_CallTheExpectedUnityEditorStatements_Given_OneErrorOnAComponent()
        {
            UnityTestBDDComponentBaseEditorBusinessLogicTestFirstDynamicComponent component = UnitTestUtility.CreateComponent <UnityTestBDDComponentBaseEditorBusinessLogicTestFirstDynamicComponent>();
            BDDExtensionRunner runner = UnitTestUtility.CreateComponent <BDDExtensionRunner>(component.gameObject);

            BaseBDDComponentEditorBusinessLogic unityTestBDDComponentBaseEditorBusinessLogic = new BaseBDDComponentEditorBusinessLogic(component);
            string expectedMessage          = "Message";
            List <UnityTestBDDError> errors = new List <UnityTestBDDError>();
            UnityTestBDDError        error  = new UnityTestBDDError();

            error.Message          = expectedMessage;
            error.Component        = component;
            error.MethodMethodInfo = null;
            errors.Add(error);

            string errorTextureFullPath = Utilities.GetAssetFullPath(runner, unityTestBDDComponentBaseEditorBusinessLogic.ErrorTextureFileName);
            string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(runner, unityTestBDDComponentBaseEditorBusinessLogic.OpenComponentButtonTextureFileName);

            IUnityInterfaceWrapper unityInterface = Substitute.For <IUnityInterfaceWrapper>();

            unityInterface.EditorGUIUtilityCurrentViewWidth().Returns(600f);
            float     labelWidth   = 500f;
            Texture2D inputTexture = new Texture2D(10, 10);

            unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)).Returns(inputTexture);
            Texture2D errorTexture = new Texture2D(10, 10);

            unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)).Returns(errorTexture);

            GUILayoutOption buttonWidth = GUILayout.Width(16);

            unityInterface.GUILayoutWidth(24).Returns(buttonWidth);
            GUILayoutOption buttonHeight = GUILayout.Height(16);

            unityInterface.GUILayoutHeight(24).Returns(buttonHeight);
            GUILayoutOption[] options = new GUILayoutOption[2];
            options[0] = buttonWidth;
            options[1] = buttonHeight;
            unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, options).Returns(false);
            GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2];
            errorTextureOptions[0] = buttonWidth;
            errorTextureOptions[1] = buttonHeight;
            unityTestBDDComponentBaseEditorBusinessLogic.Errors(errors, unityInterface);

            Received.InOrder(() =>
            {
                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutSeparator();
                unityInterface.EditorGUILayoutEndHorizontal();
                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUIUtilityCurrentViewWidth();
                unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D));
                unityInterface.GUILayoutWidth(24);
                unityInterface.GUILayoutHeight(24);
                unityInterface.EditorGUILayoutLabelField(errorTexture, Arg.Is <GUILayoutOption[]>(x => x.SequenceEqual(errorTextureOptions) == true));
                unityInterface.EditorGUILayoutLabelField(expectedMessage, labelWidth);
                unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D));
                unityInterface.GUILayoutWidth(24);
                unityInterface.GUILayoutHeight(24);
                unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, Arg.Is <GUILayoutOption[]>(x => x.SequenceEqual(options) == true));
                unityInterface.EditorGUILayoutEndHorizontal();
            });
        }