Example #1
0
        /// <summary>
        /// Gets the list of <see cref="FullMethodDescription"/> objects to run.
        /// </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>The list of <see cref="FullMethodDescription"/> objects to run.</returns>
        public List <FullMethodDescription> GetAllMethodsDescriptions(
            Component[] allComponents,
            string[] givenMethods,
            string[] givenParameters,
            string[] whenMethods,
            string[] whenParameters,
            string[] thenMethods,
            string[] thenParameters)
        {
            List <FullMethodDescription> result           = new List <FullMethodDescription>();
            ComponentsFilter             componentsFilter = new ComponentsFilter();

            Component[] components = componentsFilter.Filter(allComponents);
            MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities();

            if (methodsManagementUtilities.IsStaticBDDScenario(components))
            {
                result.AddRange(this.GetAllStaticFullMethodsDescriptions <GivenBaseAttribute>(components, methodsManagementUtilities));
                result.AddRange(this.GetAllStaticFullMethodsDescriptions <WhenBaseAttribute>(components, methodsManagementUtilities));
                result.AddRange(this.GetAllStaticFullMethodsDescriptions <ThenBaseAttribute>(components, methodsManagementUtilities));
            }
            else
            {
                result.AddRange(this.GetAllDynamicFullMethodsDescriptions <GivenBaseAttribute>(components, methodsManagementUtilities, givenMethods, givenParameters));
                result.AddRange(this.GetAllDynamicFullMethodsDescriptions <WhenBaseAttribute>(components, methodsManagementUtilities, whenMethods, whenParameters));
                result.AddRange(this.GetAllDynamicFullMethodsDescriptions <ThenBaseAttribute>(components, methodsManagementUtilities, thenMethods, thenParameters));
            }

            return(result);
        }
        public void Filter_Should_ReturnOnlyTheDynamicComponent_Given_TwoObjectsWithTheFirstAsDynamicComponentsAndTheSecondAsANormalMonoBehaviourClass()
        {
            Component[] classes = new Component[2];
            classes[0] = UnitTestUtility.CreateComponent <ComponentsFilterTestFirstDynamicComponent>();
            classes[1] = UnitTestUtility.CreateComponent <ComponentsFilterTestMonoBehaviourClass>();
            ComponentsFilter bddComponentsFilter = new ComponentsFilter();

            Component[] filteredClasses = bddComponentsFilter.Filter(classes);

            Assert.AreEqual(1, filteredClasses.Length, "The BddComponentsFilter doesn't return the right number of classes");
            Assert.IsTrue(typeof(ComponentsFilterTestFirstDynamicComponent).Equals(filteredClasses[0].GetType()), "The BddComponentsFilter doesn't return the right class");
        }
Example #3
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);
        }
Example #4
0
        public void BddObjectsHaveChanged_Should_ReturnFalse_GivenTheBDDObjectsArrayIsNullAndTheCurrentComponentsArrayIsEmpty()
        {
            RunnerEditorBusinessLogicParametersRebuild runnerEditorBusinessLogicParametersRebuild = new RunnerEditorBusinessLogicParametersRebuild();
            RunnerEditorBusinessLogicData runnerBusinessLogicData = new RunnerEditorBusinessLogicData();

            runnerBusinessLogicData.BDDObjects = null;
            Component[]      currentComponents   = new Component[0];
            ComponentsFilter bddComponentsFilter = Substitute.For <ComponentsFilter>();

            Component[] bddComponentsFilterResult = new Component[0];
            bddComponentsFilter.Filter(currentComponents).Returns <Component[]>(bddComponentsFilterResult);

            bool result = runnerEditorBusinessLogicParametersRebuild.BddObjectsHaveChanged(currentComponents, runnerBusinessLogicData, bddComponentsFilter);

            Assert.IsFalse(result, "The method BddObjectsHaveChanged doesn't return the right state");
        }
Example #5
0
        public void BddObjectsHaveChanged_Should_ReturnTrue_GivenTheBDDObjectsArrayIsNullAndTheCurrentComponentsArrayIsNotEmpty()
        {
            RunnerEditorBusinessLogicParametersRebuild runnerEditorBusinessLogicParametersRebuild = new RunnerEditorBusinessLogicParametersRebuild();
            RunnerEditorBusinessLogicData runnerBusinessLogicData = new RunnerEditorBusinessLogicData();

            runnerBusinessLogicData.BDDObjects = null;
            Component[] currentComponents = new Component[1] {
                UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicParametersRebuildUTDynamicBDDForTest>()
            };
            ComponentsFilter bddComponentsFilter = Substitute.For <ComponentsFilter>();

            Component[] bddComponentsFilterResult = new Component[1] {
                currentComponents[0]
            };
            bddComponentsFilter.Filter(currentComponents).Returns <Component[]>(bddComponentsFilterResult);

            bool result = runnerEditorBusinessLogicParametersRebuild.BddObjectsHaveChanged(currentComponents, runnerBusinessLogicData, bddComponentsFilter);

            Assert.IsTrue(result, "The method BddObjectsHaveChanged doesn't return the right state");
        }
        /// <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));
        }
        /// <summary>
        /// Determines if the BDD Components are changed inside the Integration Test.
        /// </summary>
        /// <param name="components">The components.</param>
        /// <param name="runnerBusinessLogicData">The runner business logic data.</param>
        /// <param name="bddComponentsFilter">The BDD components filter.</param>
        /// <returns>True if some component is changed.</returns>
        public bool BddObjectsHaveChanged(Component[] components, RunnerEditorBusinessLogicData runnerBusinessLogicData, ComponentsFilter bddComponentsFilter)
        {
            bool result = false;

            object[] newBddObjects       = bddComponentsFilter.Filter(components);
            object[] previuousBDDObjects = null;
            if (runnerBusinessLogicData.BDDObjects == null)
            {
                previuousBDDObjects = new object[0];
            }
            else
            {
                previuousBDDObjects = runnerBusinessLogicData.BDDObjects;
            }

            // Checking for some new BDD Object.
            foreach (object mainObj in newBddObjects)
            {
                bool found = false;
                foreach (object obj in previuousBDDObjects)
                {
                    if (obj.Equals(mainObj))
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    result = true;
                }
            }

            // Checking for some BDD Object removed
            foreach (object mainObj in previuousBDDObjects)
            {
                bool found = false;
                foreach (object obj in newBddObjects)
                {
                    if (obj.Equals(mainObj))
                    {
                        found = true;
                    }
                }

                if (!found)
                {
                    result = true;
                }
            }

            return(result);
        }
Example #8
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);
                }
            }
        }