Beispiel #1
0
        /// <summary>
        /// Runs the errors check.
        /// </summary>
        /// <param name="allComponents">All components.</param>
        /// <param name="givenMethods">The given methods.</param>
        /// <param name="givenParameters">The given parameters.</param>
        /// <param name="whenMethods">The when methods.</param>
        /// <param name="whenParameters">The when parameters.</param>
        /// <param name="thenMethods">The then methods.</param>
        /// <param name="thenParameters">The then parameters.</param>
        /// <returns>True if there is at least one error, false otherwise.</returns>
        internal bool CheckForErrors(
            Component[] allComponents,
            string[] givenMethods,
            string[] givenParameters,
            string[] whenMethods,
            string[] whenParameters,
            string[] thenMethods,
            string[] thenParameters)
        {
            List <UnityTestBDDError> errors = new List <UnityTestBDDError>();
            ComponentsFilter         bddComponentsFilter = new ComponentsFilter();

            Component[]       bddComponents            = bddComponentsFilter.Filter(allComponents);
            ComponentsChecker checkForComponentsErrors = new ComponentsChecker();

            errors.AddRange(checkForComponentsErrors.Check(bddComponents));

            if (bddComponents.Length > 0)
            {
                bool isStaticScenario = false;
                foreach (Component component in bddComponents)
                {
                    if (typeof(StaticBDDComponent).IsAssignableFrom(component.GetType()))
                    {
                        isStaticScenario = true;
                    }
                }

                if (!isStaticScenario)
                {
                    ChosenMethodsChecker checkForChosenMethodsErrors = new ChosenMethodsChecker();
                    errors.AddRange(checkForChosenMethodsErrors.Check(givenMethods, givenParameters, whenMethods, whenParameters, thenMethods, thenParameters, bddComponents));
                }
            }

            if (errors.Count > 0)
            {
                string message = string.Empty;
                foreach (UnityTestBDDError error in errors)
                {
                    message += error.Message + "\n";
                }

                this.InvokeAssertionFailed("Errors detected in configuration. Please, fix them before run the test.\n" + message, null, null, this.IntegrationTestGameObject);
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Implement this function to make a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            BDDExtensionRunner bddExtensionRunner = ((Component)target).gameObject.GetComponent <BDDExtensionRunner>();
            string             openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.MainTexturePath);

            BaseBDDComponent script = (BaseBDDComponent)target;

            if (EditorApplication.isCompiling)
            {
                script.Checking = true;
            }

            BDDExtensionRunner runner = script.gameObject.GetComponent <BDDExtensionRunner>();

            if (runner != null)
            {
                this.unityInterface.EditorGUILayoutBeginHorizontal();
                Texture2D         texture = this.unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D));
                GUILayoutOption[] options = new GUILayoutOption[1] {
                    this.unityInterface.GUILayoutHeight(70)
                };
                GUIContent label = new GUIContent(texture);
                EditorGUILayout.LabelField(label, options);
                this.unityInterface.EditorGUILayoutEndHorizontal();
                ComponentsChecker checkForErrors = new ComponentsChecker();
                script.Errors = checkForErrors.Check(script);

                if (script.Errors.Count > 0)
                {
                    BaseBDDComponentEditorBusinessLogic businessLogic = new BaseBDDComponentEditorBusinessLogic(script);
                    businessLogic.Errors(script.Errors, this.unityInterface);
                }
                else
                {
                    this.DrawDefaultInspector();
                }

                script.Checking = false;
            }
            else
            {
                this.DrawDefaultInspector();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Implement this function to make a custom inspector.
        /// </summary>
        public override void OnInspectorGUI()
        {
            BDDExtensionRunner script = (BDDExtensionRunner)target;

            serializedObject.Update();
            Component[] components          = script.gameObject.GetComponents <Component>();
            List <UnityTestBDDError> errors = new List <UnityTestBDDError>();
            ComponentsFilter         bddComponentsFilter = new ComponentsFilter();

            Component[]       bddComponents            = bddComponentsFilter.Filter(components);
            ComponentsChecker checkForComponentsErrors = new ComponentsChecker();

            errors.AddRange(checkForComponentsErrors.Check(bddComponents));

            if (!this.RunnerInspectorIsLockedOnErrors(errors) && bddComponents.Length > 0)
            {
                foreach (Component component in bddComponents)
                {
                    if (((BaseBDDComponent)component).Errors.Count > 0)
                    {
                        UnityTestBDDError error = new UnityTestBDDError();
                        error.Message                     = "There are some errors in the BDDComponents. Please, check and resolve them before continue.";
                        error.MethodMethodInfo            = null;
                        error.Component                   = null;
                        error.LockRunnerInspectorOnErrors = true;
                        error.ShowButton                  = false;
                        error.Index = 0;
                        error.LockBuildParameters    = true;
                        error.LockParametersRows     = true;
                        error.ShowRedExclamationMark = true;
                        error.StepType = null;
                        errors.Add(error);
                        break;
                    }
                }
            }

            if (!this.RunnerInspectorIsLockedOnErrors(errors) && !this.IsStaticScenario(components))
            {
                ChosenMethodsChecker checkForErrors = new ChosenMethodsChecker();
                errors.AddRange(checkForErrors.Check(script.Given, script.GivenParametersIndex, script.When, script.WhenParametersIndex, script.Then, script.ThenParametersIndex, bddComponents));
            }

            RunnerEditorBusinessLogicErrorsManagement runnerEditorBusinessLogicErrorsManagement = new RunnerEditorBusinessLogicErrorsManagement();

            runnerEditorBusinessLogicErrorsManagement.Errors(errors, this.unityIntefaceWrapper, script);

            MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities();
            bool isStaticScenario = methodsManagementUtilities.IsStaticBDDScenario(bddComponents);

            SetSucceedOnAssertions(script.gameObject);
            if (!this.RunnerInspectorIsLockedOnErrors(errors))
            {
                this.DrawOptions(this.runnerBusinessLogicData, isStaticScenario, script, this.unityIntefaceWrapper, bddComponents);

                if (!isStaticScenario)
                {
                    if (!this.BuildParametersIsLocked(errors))
                    {
                        bool isParametersRebuildNeeded = this.businessLogicParametersRebuild.IsParametersRebuildNeeded(this.unityIntefaceWrapper, this.runnerBusinessLogicData, bddComponents, bddComponentsFilter);
                        if (isParametersRebuildNeeded)
                        {
                            this.RebuildParameters(script, bddComponents, this.runnerBusinessLogicData);
                            this.runnerBusinessLogicData.BDDObjects        = bddComponents;
                            this.runnerBusinessLogicData.SerializedObjects = this.businessLogicParametersRebuild.RebuildSerializedObjectsList(bddComponents, this.runnerBusinessLogicData.SerializedObjects);
                        }
                    }
                }

                if (Event.current.type == EventType.Layout || this.dirtyStatus == false)
                {
                    this.dirtyStatus = false;
                    if (this.runnerBusinessLogicData.SerializedObjects != null)
                    {
                        foreach (ISerializedObjectWrapper so in this.runnerBusinessLogicData.SerializedObjects.Values)
                        {
                            so.Update();
                        }
                    }

                    if (methodsManagementUtilities.IsStaticBDDScenario(bddComponents))
                    {
                        this.BuildStaticScenario(bddComponents);
                    }
                    else
                    {
                        this.BuildDynamicScenario(script, bddComponents, this.LockParametersRows(errors), out this.dirtyStatus);
                    }

                    serializedObject.ApplyModifiedProperties();
                    if (this.runnerBusinessLogicData.SerializedObjects != null)
                    {
                        foreach (ISerializedObjectWrapper so in this.runnerBusinessLogicData.SerializedObjects.Values)
                        {
                            so.ApplyModifiedProperties();
                        }
                    }
                }
                else
                {
                    this.unityIntefaceWrapper.EditorUtilitySetDirty(script);
                }
            }
        }