コード例 #1
0
        /// <summary>
        /// Checks the parameters index for not matching parameters..
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="component">The component.</param>
        /// <param name="methodInfo">The method information.</param>
        /// <param name="parameterType">Type of the parameter.</param>
        /// <param name="parameterName">Name of the parameter.</param>
        /// <param name="chosenMethodIndex">Index of the chosen method.</param>
        /// <returns>A list of <see cref="UnityTestBDDError"/> objects. Each element describes an error found. If the list is empty, there are no errors. The list cannot be null.</returns>
        public List <UnityTestBDDError> CheckForNotMatchingParametersIndex <T>(Component component, MethodInfo methodInfo, string parameterType, string parameterName, int chosenMethodIndex) where T : IGivenWhenThenDeclaration
        {
            List <UnityTestBDDError> result = new List <UnityTestBDDError>();
            bool isParameterFound           = false;
            bool isParameterTypeMatching    = false;

            ParameterInfo[] parameters = methodInfo.GetParameters();

            Type currentParameterType = null;

            foreach (ParameterInfo parameter in parameters)
            {
                if (parameter.Name.Equals(parameterName))
                {
                    isParameterFound     = true;
                    currentParameterType = parameter.ParameterType;
                    if (currentParameterType.FullName.Equals(parameterType))
                    {
                        isParameterTypeMatching = true;
                    }
                }
            }

            if (!isParameterFound)
            {
                IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty);
                UnityTestBDDError         error = new UnityTestBDDError();
                error.Message                     = "The parameter " + component.GetType().Name + "." + methodInfo.Name + "." + parameterName + " is not found in " + genericComponentInteface.GetStepName() + " methods at position " + (chosenMethodIndex + 1);
                error.Component                   = component;
                error.MethodMethodInfo            = methodInfo;
                error.StepType                    = typeof(T);
                error.Index                       = chosenMethodIndex;
                error.LockRunnerInspectorOnErrors = false;
                error.ShowButton                  = true;
                error.LockBuildParameters         = true;
                error.LockParametersRows          = true;
                result.Add(error);
            }
            else if (!isParameterTypeMatching)
            {
                IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty);
                UnityTestBDDError         error = new UnityTestBDDError();
                error.Message                     = "The parameter " + component.GetType().Name + "." + methodInfo.Name + "." + parameterName + " has a wrong type in " + genericComponentInteface.GetStepName() + " methods at position " + (chosenMethodIndex + 1) + ".\n Previous type: " + parameterType + "\n Current type " + currentParameterType.FullName;
                error.Component                   = component;
                error.MethodMethodInfo            = methodInfo;
                error.StepType                    = typeof(T);
                error.Index                       = chosenMethodIndex;
                error.LockRunnerInspectorOnErrors = false;
                error.ShowButton                  = true;
                error.LockBuildParameters         = true;
                error.LockParametersRows          = true;

                result.Add(error);
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Checks for not matching ParametersValuesStorage fields.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="parametersIndexes">The parameters indexes.</param>
        /// <param name="components">The components.</param>
        /// <returns>A list of <see cref="UnityTestBDDError"/> objects. Each element describes an error found. If the list is empty, there are no errors. The list cannot be null.</returns>
        public List <UnityTestBDDError> CheckForNotMatchingPVS <T>(string[] chosenMethods, string[] parametersIndexes, Component[] components)
        {
            List <UnityTestBDDError> result = new List <UnityTestBDDError>();
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();

            for (int index = 0; index < chosenMethods.Length; index++)
            {
                Component component           = this.GetComponent(chosenMethods[index], components);
                string[]  parametersIndexList = parametersIndexUtilities.GetParametersIndexList(parametersIndexes[index]);
                foreach (string parameterIndex in parametersIndexList)
                {
                    string    arrayPVSName = parametersIndexUtilities.GetParameterValueStorageName(parameterIndex);
                    FieldInfo arrayPVS     = component.GetType().GetField(arrayPVSName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                    if (arrayPVS == null)
                    {
                        IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty);
                        UnityTestBDDError         error = new UnityTestBDDError();
                        error.Message                     = "The ParametersValuesStorage field " + arrayPVSName + " for the parameter " + parametersIndexUtilities.GetParameterFullName(parameterIndex) + " is not found in " + genericComponentInteface.GetStepName() + " methods at position " + (index + 1);
                        error.Component                   = component;
                        error.MethodMethodInfo            = this.GetMethodInfo(chosenMethods[index], component);
                        error.StepType                    = typeof(T);
                        error.Index                       = index;
                        error.LockRunnerInspectorOnErrors = false;
                        error.ShowButton                  = true;
                        error.LockBuildParameters         = true;
                        error.LockParametersRows          = true;

                        result.Add(error);
                    }
                    else
                    {
                        Array array = arrayPVS.GetValue(component) as Array;
                        if (array == null || array.Length == 0)
                        {
                            UnityTestBDDError error = new UnityTestBDDError();
                            error.Message                     = "The component " + component.GetType().Name + " seems to have been reset, so some parameter values are lost. Please, undo the reset operation or rebuild the settings to confirm the reset.";
                            error.Component                   = component;
                            error.MethodMethodInfo            = this.GetMethodInfo(chosenMethods[index], component);
                            error.StepType                    = typeof(T);
                            error.Index                       = index;
                            error.LockRunnerInspectorOnErrors = false;
                            error.ShowButton                  = true;
                            error.LockBuildParameters         = true;
                            error.LockParametersRows          = true;

                            result.Add(error);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Checks for blank methods.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <returns>A list of <see cref="UnityTestBDDError"/> objects. Each element describes an error found. If the list is empty, there are no errors. The list cannot be null.</returns>
        public List <UnityTestBDDError> CheckForBlankMethods <T>(string[] chosenMethods) where T : IGivenWhenThenDeclaration
        {
            List <UnityTestBDDError> result = new List <UnityTestBDDError>();

            for (int index = 0; index < chosenMethods.Length; index++)
            {
                if (chosenMethods[index].Equals(string.Empty))
                {
                    IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty);
                    UnityTestBDDError         error = new UnityTestBDDError();
                    error.Message  = "Incomplete settings detected on " + genericComponentInteface.GetStepName() + " methods at position " + (index + 1);
                    error.StepType = typeof(T);
                    error.Index    = index;
                    error.LockRunnerInspectorOnErrors = false;
                    error.ShowButton          = false;
                    error.LockBuildParameters = false;
                    error.LockParametersRows  = false;
                    result.Add(error);
                }
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Checks for BDD Component not found.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="components">The components.</param>
        /// <returns>A list of <see cref="UnityTestBDDError"/> objects. Each element describes an error found. If the list is empty, there are no errors. The list cannot be null.</returns>
        public List <UnityTestBDDError> CheckForComponentNotFound <T>(string[] chosenMethods, Component[] components)
        {
            List <UnityTestBDDError> result = new List <UnityTestBDDError>();

            for (int index = 0; index < chosenMethods.Length; index++)
            {
                if (this.GetComponent(chosenMethods[index], components) == null && chosenMethods[index] != null && !chosenMethods[index].Equals(string.Empty))
                {
                    IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty);
                    UnityTestBDDError         error = new UnityTestBDDError();
                    error.Message  = "The component for the method " + chosenMethods[index] + " is not found  in " + genericComponentInteface.GetStepName() + " methods at position " + (index + 1);
                    error.StepType = typeof(T);
                    error.Index    = index;
                    error.LockRunnerInspectorOnErrors = false;
                    error.ShowButton          = false;
                    error.LockBuildParameters = true;
                    error.LockParametersRows  = true;

                    result.Add(error);
                }
            }

            return(result);
        }
コード例 #5
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);
                }
            }
        }
        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();
            });
        }