Ejemplo n.º 1
0
        public void CheckForNotMatchingPVS_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndADynamicComponentWithoutACorrespondingParametersValuesStorages()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");

            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndexes = new string[1] {
                ";System.String,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam.,otherPVS.Array.data[0];"
            };
            ChosenMethodsChecker checkForErrors = new ChosenMethodsChecker();

            List <UnityTestBDDError> result = checkForErrors.CheckForNotMatchingPVS <GivenBaseAttribute>(chosenMethods, parametersIndexes, components);

            string expectedMessage = "The ParametersValuesStorage field otherPVS for the parameter ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam. is not found in Given methods at position 1";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForNotMatchingPVS doesn't resturn the right message");
            Assert.That(component.Equals(result[0].Component), "The method CheckForNotMatchingPVS doesn't resturn the right Component");
            Assert.That(methodInfo.Equals(result[0].MethodMethodInfo), "The method CheckForNotMatchingPVS doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(GivenBaseAttribute), result[0].StepType, "The method CheckForNotMatchingPVS doesn't resturn the right StepType");
            Assert.AreEqual(0, result[0].Index, "The method CheckForNotMatchingPVS doesn't resturn the right method index");
        }
Ejemplo n.º 2
0
        public void CheckForNotMatchingParametersIndex_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndTheDynamicComponentWithTheCorrespondingMethodsButWithAParameterWithDifferentType()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");

            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndexes = new string[1] {
                ";System.Int32,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam.,intPVS.Array.data[0];"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForNotMatchingParametersIndex <GivenBaseAttribute>(chosenMethods, parametersIndexes, components);
            string expectedMessage = "The parameter ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam has a wrong type in Given methods at position 1.\n Previous type: System.Int32\n Current type System.String";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForNotMatchingParametersIndex doesn't resturn the right message");
            Assert.That(component.Equals(result[0].Component), "The method CheckForNotMatchingParametersIndex doesn't resturn the right Component");
            Assert.That(methodInfo.Equals(result[0].MethodMethodInfo), "The method CheckForNotMatchingParametersIndex doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(GivenBaseAttribute), result[0].StepType, "The method CheckForNotMatchingParametersIndex doesn't resturn the right StepType");
            Assert.AreEqual(0, result[0].Index, "The method CheckForNotMatchingParametersIndex doesn't resturn the right method index");
        }
Ejemplo n.º 3
0
        public void CheckForBlankMethods_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_AChosenMethodsListWithoutEmptyElements()
        {
            string[] chosenMethods = new string[5] {
                "class.method", "class.method", "class.method", "class.method", "class.method"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForBlankMethods <GivenBaseAttribute>(chosenMethods);

            Assert.AreEqual(0, result.Count, "The method CheckForBlankMethods doesn't check properly");
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        public void CheckForMethodNotFound_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_AListOfChosenMethodsAndADynamicComponentWithAllMethodsInTheList()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            string[] chosenMethods = new string[2] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.ThenMethod", "ChosenMethodsCheckerTestFirstDynamicComponent.SecondThenMethod"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForMethodNotFound <ThenBaseAttribute>(chosenMethods, components);

            Assert.AreEqual(0, result.Count, "The method CheckForMethodNotFound doesn't check properly");
        }
Ejemplo n.º 6
0
        public void CheckForBlankMethods_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_AChosenMethodsListWithAnEmptyElement()
        {
            string[] chosenMethods = new string[5] {
                "class.method", "class.method", string.Empty, "class.method", "class.method"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForBlankMethods <GivenBaseAttribute>(chosenMethods);

            Assert.AreEqual(1, result.Count, "The method CheckForBlankMethods doesn't check properly");
            string expectedMessage = "Incomplete settings detected on Given methods at position 3";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForBlankMethods doesn't resturn the right message");
            Assert.IsNull(result[0].Component, "The method CheckForBlankMethods doesn't resturn the right Component");
            Assert.IsNull(result[0].MethodMethodInfo, "The method CheckForBlankMethods doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(GivenBaseAttribute), result[0].StepType, "The method CheckForBlankMethods doesn't resturn the right StepType");
            Assert.AreEqual(2, result[0].Index, "The method CheckForBlankMethods doesn't resturn the right method index");
        }
Ejemplo n.º 7
0
        public void CheckForNotMatchingParametersIndex_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndTheDynamicComponentWithTheCorrespondingMethodsAndParameters()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndex = new string[1] {
                ";System.String,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam.,stringPVS.Array.data[0];"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForNotMatchingParametersIndex <GivenBaseAttribute>(chosenMethods, parametersIndex, components);

            Assert.AreEqual(0, result.Count, "The method CheckForNotMatchingParametersIndex doesn't check properly");
        }
Ejemplo n.º 8
0
        public void CheckForComponentNotFound_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_AListOfChosenMethodsWithoutACorrespondingDynamicComponent()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            string[] chosenMethods = new string[2] {
                "ChosenMethodsCheckerTestFirstDynamicComponentFake.ThenMethod", "ChosenMethodsCheckerTestFirstDynamicComponent.SecondThenMethod"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForComponentNotFound <ThenBaseAttribute>(chosenMethods, components);
            string expectedMessage = "The component for the method ChosenMethodsCheckerTestFirstDynamicComponentFake.ThenMethod is not found  in Then methods at position 1";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForComponentNotFound doesn't resturn the right message");
            Assert.IsNull(result[0].Component, "The method CheckForComponentNotFound doesn't resturn the right Component");
            Assert.IsNull(result[0].MethodMethodInfo, "The method CheckForComponentNotFound doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(ThenBaseAttribute), result[0].StepType, "The method CheckForComponentNotFound doesn't resturn the right StepType");
            Assert.AreEqual(0, result[0].Index, "The method CheckForComponentNotFound doesn't resturn the right method index");
        }
Ejemplo n.º 9
0
        public void CheckForNotMatchingPVS_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndADynamicComponentWithTheCorrespondingParametersValuesStorages()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities();
            FieldInfo             stringPVS             = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));
            Array array = new string[1];

            stringPVS.SetValue(component, array);
            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndexes = new string[1] {
                ";System.String,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParamWrongName.,stringPVS.Array.data[0];"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForNotMatchingPVS <GivenBaseAttribute>(chosenMethods, parametersIndexes, components);

            Assert.AreEqual(0, result.Count, "The method CheckForNotMatchingPVS doesn't check properly");
        }
Ejemplo n.º 10
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);
                }
            }
        }