/// <summary>
        /// Draws the cog button.
        /// </summary>
        /// <param name="unityInterface">The unity interface.</param>
        /// <param name="methodDescription">The method description.</param>
        internal void DrawCogButton(IUnityInterfaceWrapper unityInterface, BaseMethodDescription methodDescription)
        {
            string    texture      = @"Assets\UnityTestToolsBDDExtension\Resources\Sprites\cog.png";
            Texture2D inputTexture = unityInterface.AssetDatabaseLoadAssetAtPath(texture, 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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the BaseMethodDescription object method for a single chosen method.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method to filter.</typeparam>
        /// <param name="components">The components.</param>
        /// <param name="chosenMethod">The chosen method.</param>
        /// <returns>The requested <see cref="BaseMethodDescription"/> object.</returns>
        private BaseMethodDescription LoadStepMethodForASingleChosenMethod <T>(Component[] components, string chosenMethod) where T : IGivenWhenThenDeclaration
        {
            BaseMethodDescription result = new BaseMethodDescription();

            if (chosenMethod == null || chosenMethod.Equals(string.Empty))
            {
                return(null);
            }
            else
            {
                string    componentName = chosenMethod.Split('.')[0];
                string    methodName    = chosenMethod.Split('.')[1];
                Component component     = null;
                foreach (Component item in components)
                {
                    if (item.GetType().Name.Equals(componentName))
                    {
                        component = item;
                        break;
                    }
                }

                MethodInfo methodInfo = component.GetType().GetMethod(methodName);
                result = this.methodBuilder.Build <T>(component, methodInfo);
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Builds the list of <see cref="FullMethodDescription"/> objects based on the information contained into a <see cref="BaseMethodDescription"/> object.
        /// </summary>
        /// <param name="baseMethodDescription">The <see cref="BaseMethodDescription"/> object.</param>
        /// <param name="stepNumber">The index of the Step Method inside a chosenMethod list.</param>
        /// <returns>A <see cref="List"/> of <see cref="FullMethodDescription"/> object. Each element represent one of the element in the call chain defined by the <see cref="CallBefore"/> attributes. The last one is the main method described by the <paramref name="baseMethodDescription"/> parameter.</returns>
        public virtual List <FullMethodDescription> BuildFromBaseMethodDescription(BaseMethodDescription baseMethodDescription, uint stepNumber)
        {
            MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder();
            MethodParametersLoader   methodParametersLoader   = new MethodParametersLoader();
            string            parametersIndex   = string.Empty;
            MethodDescription methodDescription = methodDescriptionBuilder.Build(methodParametersLoader, baseMethodDescription, parametersIndex);

            return(this.Build(methodDescription, stepNumber));
        }
        /// <summary>
        /// Builds a list of <see cref="FullMethodDescription"/> objects given a list of <see cref="BaseMethodDescription"/> objects.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="methodsDescriptionsList">The methods descriptions list.</param>
        /// <param name="fullMethodDescriptionBuilder">The full method description builder.</param>
        /// <returns>A list of <see cref="FullMethodDescription"/> objects.</returns>
        public List <FullMethodDescription> LoadFullMethodsDescriptions <T>(List <BaseMethodDescription> methodsDescriptionsList, FullMethodDescriptionBuilder fullMethodDescriptionBuilder) where T : IGivenWhenThenDeclaration
        {
            List <FullMethodDescription> fullMethodsDescriptions = new List <FullMethodDescription>();

            for (int index = 0; index < methodsDescriptionsList.Count; index++)
            {
                BaseMethodDescription        baseMethodDescription      = methodsDescriptionsList[index];
                List <FullMethodDescription> fullmethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(baseMethodDescription, (uint)index + 1);
                fullMethodsDescriptions.AddRange(fullmethodDescriptionsList);
            }

            return(fullMethodsDescriptions);
        }
        /// <summary>
        /// Builds the <see cref="BaseMethodDescription"/> object for the method described by the <paramref name="methodInfo"/> parameter.
        /// </summary>
        /// <typeparam name="T">One of the following types: <see cref="GivenBaseAttribute"/>, <see cref="WhenBaseAttribute"/>, <see cref="ThenBaseAttribute"/>.</typeparam>
        /// <param name="component">The component containing the method.</param>
        /// <param name="methodInfo">The <see cref="MethodInfo"/> object.</param>
        /// <returns>The <see cref="BaseMethodDescription"/> object for the method described by the <paramref name="methodInfo"/> parameter.</returns>
        public virtual BaseMethodDescription Build <T>(Component component, MethodInfo methodInfo) where T : IGivenWhenThenDeclaration
        {
            BaseMethodDescription result = new BaseMethodDescription();

            result.ComponentObject = component;
            result.Method          = methodInfo;
            result.StepType        = typeof(T);
            object[] attributes = methodInfo.GetCustomAttributes(typeof(T), true);
            IGivenWhenThenDeclaration gwtBaseAttribute = (IGivenWhenThenDeclaration)attributes[0];

            result.Text           = gwtBaseAttribute.GetStepScenarioText();
            result.ExecutionOrder = gwtBaseAttribute.GetExecutionOrder();
            return(result);
        }
Esempio n. 6
0
        public void GetMethodDescriptionForTheChosenMethod_Should_ReturnTheExpectedMethodDescriptionObject_Given_ADynamicComponentAndTheMethodFullNameAndTheParametersIndexes()
        {
            MethodDescriptionBuilder methodDescriptionBuilder = Substitute.For <MethodDescriptionBuilder>();

            MethodParametersLoader parametersLoader = Substitute.For <MethodParametersLoader>();

            RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent component = UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent>();

            ArrayStorageUtilities arrayStorageUtilities   = new ArrayStorageUtilities();
            FieldInfo             firstStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));

            firstStringArrayStorage.SetValue(component, new string[2] {
                "FirstValue", "SecondValue"
            });

            FieldInfo firstIntArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(int));

            firstIntArrayStorage.SetValue(component, new int[2] {
                33, 14
            });

            MethodInfo             method                 = component.GetType().GetMethod("WhenMethod");
            string                 parametersIndex        = ";string,RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod.whenStringParam.,stringPVS.Array.data[0];int,RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod.whenIntParam.,intPVS.Array.data[0];";
            MethodParametersLoader methodParametersLoader = new MethodParametersLoader();
            MethodParameters       methodParameters       = methodParametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex);

            parametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex).Returns(methodParameters);

            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            BaseMethodDescription        baseMethodDescription        = baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, method);

            MethodDescriptionBuilder methodDescriptionBuilderInstance = new MethodDescriptionBuilder();
            MethodDescription        methodDescription = methodDescriptionBuilderInstance.Build(parametersLoader, baseMethodDescription, parametersIndex);

            methodDescriptionBuilder.Build(parametersLoader, baseMethodDescription, parametersIndex).Returns(methodDescription);

            string chosenMethodName                 = "RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod";
            string chosenMethodParametersIndex      = parametersIndex;
            List <BaseMethodDescription> methodList = new List <BaseMethodDescription>();

            methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("SecondWhenMethod")));
            methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("WhenMethod")));
            methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("ThirdWhenMethod")));

            RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities();
            MethodDescription result = methodsUtilities.GetMethodDescriptionForTheChosenMethod(methodDescriptionBuilder, parametersLoader, chosenMethodName, chosenMethodParametersIndex, methodList);

            Assert.IsTrue(methodDescription.Equals(result), "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.GetMethodDescriptionForTheChosenMethod doesn't return the right object");
        }
        /// <summary>
        /// Builds a list of <see cref="FullMethodDescription"/> objects given a list of method full names.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="dynamicBDDComponents">The dynamic BDD components.</param>
        /// <param name="methodsLoader">The methods loader.</param>
        /// <param name="methodDescriptionBuilder">The method description builder.</param>
        /// <param name="methodParametersLoader">The method parameters loader.</param>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="chosenMethodsParametersIndexes">The chosen methods parameters indexes.</param>
        /// <returns>A list of <see cref="FullMethodDescription"/> objects.</returns>
        public List <MethodDescription> LoadMethodsDescriptionsFromChosenMethods <T>(Component[] dynamicBDDComponents, MethodsLoader methodsLoader, MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader methodParametersLoader, string[] chosenMethods, string[] chosenMethodsParametersIndexes) where T : IGivenWhenThenDeclaration
        {
            List <MethodDescription>     methodsDescriptions     = new List <MethodDescription>();
            List <BaseMethodDescription> baseMethodsDescriptions = methodsLoader.LoadOrderedStepMethods <T>(dynamicBDDComponents, chosenMethods);

            for (int index = 0; index < baseMethodsDescriptions.Count; index++)
            {
                BaseMethodDescription baseMethodDescription = baseMethodsDescriptions[index];
                string            parametersIndex           = chosenMethodsParametersIndexes[index];
                MethodDescription methodDescription         = methodDescriptionBuilder.Build(methodParametersLoader, baseMethodDescription, parametersIndex);
                methodsDescriptions.Add(methodDescription);
            }

            return(methodsDescriptions);
        }
        public void Build_Should_ReturnTheExpectedBaseMethodDescriptionObject_Given_ADynamicComponentAndASimpleGivenMethod()
        {
            BaseMethodDescriptionBuilderTestDynamicComponent component = UnitTestUtility.CreateComponent<BaseMethodDescriptionBuilderTestDynamicComponent>();
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");

            BaseMethodDescription expectedBaseMethodDescription = new BaseMethodDescription();
            expectedBaseMethodDescription.ComponentObject = component;
            expectedBaseMethodDescription.Method = methodInfo;
            expectedBaseMethodDescription.StepType = typeof(GivenBaseAttribute);
            expectedBaseMethodDescription.Text = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedBaseMethodDescription.ExecutionOrder = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetExecutionOrder();

            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            BaseMethodDescription builderResult = baseMethodDescriptionBuilder.Build<GivenBaseAttribute>(component, methodInfo);

            Assert.IsTrue(expectedBaseMethodDescription.Equals(builderResult), "The method BaseMethodDescriptionBuilder.Build does not return the expected object");
            Assert.AreEqual(expectedBaseMethodDescription.Text, builderResult.Text, "The method BaseMethodDescriptionBuilder.Build does not return the expected Text");
        }
        public void LoadStepMethods_Should_ReturnTheExpectedListOfBaseMethodDescriptionObjects_Given_ADynamicComponentWithTwoThenMethodsLoadingThenMethods()
        {
            Component[] components = new Component[1] {
                UnitTestUtility.CreateComponent <MethodsLoaderTestDynamicComponent>()
            };
            BaseMethodDescription expectedMethod1 = new BaseMethodDescription();

            expectedMethod1.ComponentObject = components[0];
            expectedMethod1.Method          = components[0].GetType().GetMethod("ThenMethod");
            expectedMethod1.StepType        = typeof(ThenBaseAttribute);
            expectedMethod1.Text            = ((IGivenWhenThenDeclaration)expectedMethod1.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethod1.ExecutionOrder  = ((IGivenWhenThenDeclaration)expectedMethod1.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder();

            BaseMethodDescription expectedMethod2 = new BaseMethodDescription();

            expectedMethod2.ComponentObject = components[0];
            expectedMethod2.Method          = components[0].GetType().GetMethod("SecondThenMethod");
            expectedMethod2.StepType        = typeof(ThenBaseAttribute);
            expectedMethod2.Text            = ((IGivenWhenThenDeclaration)expectedMethod2.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethod2.ExecutionOrder  = ((IGivenWhenThenDeclaration)expectedMethod2.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder();

            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader   = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> methods = bddStepMethodsLoader.LoadStepMethods <ThenBaseAttribute>(components);

            Assert.AreEqual(2, methods.Count, "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected amount of elements");
            BaseMethodDescription returnedMethod1 = null;
            BaseMethodDescription returnedMethod2 = null;

            if (methods[0].Method.Name.Equals(expectedMethod1.Method.Name))
            {
                returnedMethod1 = methods[0];
                returnedMethod2 = methods[1];
            }
            else
            {
                returnedMethod1 = methods[1];
                returnedMethod2 = methods[2];
            }

            Assert.IsTrue(expectedMethod1.Equals(returnedMethod1), "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected Method Object");
            Assert.IsTrue(expectedMethod2.Equals(returnedMethod2), "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected Method Object");
        }
Esempio n. 10
0
        public void LoadFullMethodsDescriptions_Should_LoadParametersForTheCallBeforeMethod_When_TheParameterIndexOfTheMainMethodDescriptionIsProperlySet()
        {
            // Create the MethodDescription
            MethodsManagementUtilitiesTestThirdDynamicComponent component = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestThirdDynamicComponent>();

            MethodInfo mainMethodInfo = component.GetType().GetMethod("SecondGivenMethod");
            MethodDescriptionBuilder     methodDescriptionBuilder     = new MethodDescriptionBuilder();
            MethodParametersLoader       methodParametersLoader       = new MethodParametersLoader();
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder();

            BaseMethodDescription mainBaseMethodDescription = baseMethodDescriptionBuilder.Build <GivenBaseAttribute>(component, mainMethodInfo);
            string parametersIndex = ";System.String,MethodsManagementUtilitiesUTDynamicCallBeforeParameterLoad.SecondGivenMethod.stringParam.,stringPVS.Array.data[0]" +
                                     ";System.String,MethodsManagementUtilitiesUTDynamicCallBeforeParameterLoad.GivenMethod.stringParam.,stringPVS.Array.data[1]";
            ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities();
            FieldInfo             stringPVS             = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));

            string[] stringArray = new string[2] {
                "FirstElementForTheMainMethod", "SecondElementForTheCallBeforeMethod"
            };
            stringPVS.SetValue(component, stringArray);

            MethodDescription mainMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, mainBaseMethodDescription, parametersIndex);

            // Creating the expected FullMethodDescription list
            MethodInfo callBeforeMethodInfo = component.GetType().GetMethod("GivenMethod");
            List <FullMethodDescription> expectedFullMethodDescriptionsList = fullMethodDescriptionBuilder.Build(mainMethodDescription, 1);

            expectedFullMethodDescriptionsList[0].Parameters = methodParametersLoader.LoadMethodParameters(component, callBeforeMethodInfo, string.Empty, parametersIndex);

            // Executing LoadFullMethodsDescriptions
            List <MethodDescription> methodsDescriptionsList = new List <MethodDescription>();

            methodsDescriptionsList.Add(mainMethodDescription);
            MethodsManagementUtilities   methodsManagementUtilities = new MethodsManagementUtilities();
            List <FullMethodDescription> result = methodsManagementUtilities.LoadFullMethodsDescriptions <GivenBaseAttribute>(methodsDescriptionsList, fullMethodDescriptionBuilder);

            // Compare the FullMethodDescriptions
            Assert.AreEqual(2, result.Count, "The method build doesn't return the right number of element in the list");
            Assert.AreEqual(expectedFullMethodDescriptionsList[0], result[0], "The method build doesn't return the right fullMethodDescription");
            Assert.AreEqual(expectedFullMethodDescriptionsList[1], result[1], "The method build doesn't return the right fullMethodDescription");
        }
Esempio n. 11
0
        public void LoadFullMethodsDescriptions_Should_ReturnTheExpectedListOfFullMethodDescriptionObjects_Given_AListOfMethodDescriptionObjectsOfMethodsContainingCallBeforeAttributes()
        {
            // Create the MethodDescription
            MethodsManagementUtilitiesUTDynamicBDDForTestForCallBeforeMethodsList component = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesUTDynamicBDDForTestForCallBeforeMethodsList>();

            MethodInfo mainMethodInfo = component.GetType().GetMethod("SecondThenMethod");
            MethodDescriptionBuilder     methodDescriptionBuilder     = new MethodDescriptionBuilder();
            MethodParametersLoader       methodParametersLoader       = new MethodParametersLoader();
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            BaseMethodDescription        mainBaseMethodDescription    = baseMethodDescriptionBuilder.Build <ThenBaseAttribute>(component, mainMethodInfo);
            string            parametersIndex = string.Empty;
            MethodDescription firstChosenMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, mainBaseMethodDescription, parametersIndex);

            // Create the expected FullMethodDescription
            MethodInfo                   firstCallBeforeMethodInfo             = component.GetType().GetMethod("ThenMethod");
            BaseMethodDescription        firstCallBeforeBaseMethodDescription  = baseMethodDescriptionBuilder.Build <ThenBaseAttribute>(component, firstCallBeforeMethodInfo);
            MethodDescription            secondChosenMethodDescription         = methodDescriptionBuilder.Build(methodParametersLoader, firstCallBeforeBaseMethodDescription, parametersIndex);
            FullMethodDescriptionBuilder fullMethodDescriptionBuilder          = new FullMethodDescriptionBuilder();
            List <FullMethodDescription> firstChosenFullMethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(firstChosenMethodDescription, 1);
            List <FullMethodDescription> seconChosenFullMethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(secondChosenMethodDescription, 2);
            List <FullMethodDescription> expectedFullMethodDescriptionsList    = new List <FullMethodDescription>();

            expectedFullMethodDescriptionsList.AddRange(firstChosenFullMethodDescriptionsList);
            expectedFullMethodDescriptionsList.AddRange(seconChosenFullMethodDescriptionsList);

            // Build the fullMethodDescription
            List <MethodDescription> methodsDescriptionsList = new List <MethodDescription>();

            methodsDescriptionsList.Add(firstChosenMethodDescription);
            methodsDescriptionsList.Add(secondChosenMethodDescription);
            MethodsManagementUtilities   methodsManagementUtilities = new MethodsManagementUtilities();
            List <FullMethodDescription> result = methodsManagementUtilities.LoadFullMethodsDescriptions <ThenBaseAttribute>(methodsDescriptionsList, fullMethodDescriptionBuilder);

            // Compare the FullMethodDescriptions
            Assert.AreEqual(6, result.Count, "The method build doesn't return the right number of element in the list");
            Assert.AreEqual(expectedFullMethodDescriptionsList[0], result[0], "The method build doesn't return the right fullMethodDescription");
            Assert.AreEqual(expectedFullMethodDescriptionsList[1], result[1], "The method build doesn't return the right fullMethodDescription");
            Assert.AreEqual(expectedFullMethodDescriptionsList[2], result[2], "The method build doesn't return the right fullMethodDescription");
            Assert.AreEqual(expectedFullMethodDescriptionsList[3], result[3], "The method build doesn't return the right fullMethodDescription");
            Assert.AreEqual(expectedFullMethodDescriptionsList[4], result[4], "The method build doesn't return the right fullMethodDescription");
            Assert.AreEqual(expectedFullMethodDescriptionsList[5], result[5], "The method build doesn't return the right fullMethodDescription");
        }
        public void Build_Should_ReturnTheExpectedMethodDescriptionObject_Given_ADynamicComponentForAThenMethodWithoutParameters()
        {
            MethodDescriptionBuilderTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodDescriptionBuilderTestDynamicComponent>();
            MethodInfo methodInfo      = component.GetType().GetMethod("ThenMethod");
            string     parametersIndex = null;

            MethodDescription expectedMethodDescription = new MethodDescription();

            expectedMethodDescription.ComponentObject = component;
            expectedMethodDescription.Method          = methodInfo;
            expectedMethodDescription.StepType        = typeof(ThenBaseAttribute);
            expectedMethodDescription.Text            = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethodDescription.ExecutionOrder  = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder();

            ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities();
            FieldInfo             arrayStorage          = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));

            arrayStorage.SetValue(component, new string[0]);

            MethodParameters methodParameters = new MethodParameters();

            methodParameters.Parameters               = new MethodParameter[0];
            expectedMethodDescription.Parameters      = methodParameters;
            expectedMethodDescription.ParametersIndex = parametersIndex;

            MethodParametersLoader methodParametersLoader = Substitute.For <MethodParametersLoader>();

            methodParametersLoader.LoadMethodParameters(component, methodInfo, string.Empty, parametersIndex).Returns(expectedMethodDescription.Parameters);

            BaseMethodDescription baseMethodDescription = new BaseMethodDescription();

            baseMethodDescription.ComponentObject = component;
            baseMethodDescription.Method          = methodInfo;
            baseMethodDescription.StepType        = typeof(ThenBaseAttribute);
            baseMethodDescription.Text            = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText();
            baseMethodDescription.ExecutionOrder  = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder();

            MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder();
            MethodDescription        builderResult            = methodDescriptionBuilder.Build(methodParametersLoader, baseMethodDescription, parametersIndex);

            Assert.IsTrue(expectedMethodDescription.Equals(builderResult), "The method MethodDescriptionBuilder.Build does not return the expected object");
        }
        public void LoadStepMethods_Should_ReturnTheExpectedListOfBaseMethodDescriptionObjects_Given_ADynamicComponentLoadingGivenMethods()
        {
            Component[] components = new Component[1] {
                UnitTestUtility.CreateComponent <MethodsLoaderTestDynamicComponent>()
            };
            BaseMethodDescription expectedMethod = new BaseMethodDescription();

            expectedMethod.ComponentObject = components[0];
            expectedMethod.Method          = components[0].GetType().GetMethod("GivenMethod");
            expectedMethod.StepType        = typeof(GivenBaseAttribute);
            expectedMethod.Text            = ((IGivenWhenThenDeclaration)expectedMethod.Method.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethod.ExecutionOrder  = ((IGivenWhenThenDeclaration)expectedMethod.Method.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetExecutionOrder();
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader   = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> methods = bddStepMethodsLoader.LoadStepMethods <GivenBaseAttribute>(components);

            Assert.AreEqual(1, methods.Count, "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected amount of elements");
            Assert.IsTrue(expectedMethod.Equals(methods[0]), "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected Method Object");
        }
Esempio n. 14
0
        /// <summary>
        /// Orders the methods by their execution order.
        /// </summary>
        /// <param name="listToOrder">The list to order.</param>
        /// <returns>The ordered list of <see cref="BaseMethodDescription"/> objects.</returns>
        private List <BaseMethodDescription> OrderMethodsByExecutionOrder(List <BaseMethodDescription> listToOrder)
        {
            List <BaseMethodDescription> result = new List <BaseMethodDescription>();

            uint maxExecutionOrder = 0;

            foreach (BaseMethodDescription method in listToOrder)
            {
                if (method.ExecutionOrder > maxExecutionOrder)
                {
                    maxExecutionOrder = method.ExecutionOrder;
                }
            }

            BaseMethodDescription[] methodsArray = new BaseMethodDescription[maxExecutionOrder];
            foreach (BaseMethodDescription method in listToOrder)
            {
                if (methodsArray[method.ExecutionOrder - 1] != null)
                {
                    return(new List <BaseMethodDescription>());
                }

                methodsArray[method.ExecutionOrder - 1] = method;
            }

            for (int index = 0; index < methodsArray.Length; index++)
            {
                if (methodsArray[index] != null)
                {
                    result.Add(methodsArray[index]);
                }
                else
                {
                    return(new List <BaseMethodDescription>());
                }
            }

            return(result);
        }
Esempio n. 15
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            BaseMethodDescription method = (BaseMethodDescription)obj;

            if (((this.ComponentObject == null && method.ComponentObject == null) || UnityEngine.Object.Equals(this.ComponentObject, method.ComponentObject))
                &&
                ((this.Method == null && method.Method == null) || this.Method.Equals(method.Method))
                &&
                ((this.StepType == null && method.StepType == null) || this.StepType.Equals(method.StepType))
                &&
                ((this.Text == null && method.Text == null) || this.Text.Equals(method.Text))
                &&
                this.ExecutionOrder.Equals(method.ExecutionOrder))
            {
                return(true);
            }

            return(false);
        }
        public void Build_Should_ReturnTheExpectedMethodDescriptionObject_Given_ADynamicComponentForAGivenMethodWithAStringParameterWithItsParameterIndex()
        {
            MethodDescriptionBuilderTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodDescriptionBuilderTestDynamicComponent>();
            MethodInfo methodInfo      = component.GetType().GetMethod("GivenMethod");
            string     parametersIndex = ";string,DynamicBDDForTest.GivenMethod.stringParam.,StringsArrayStorage.Array.data[0];";

            MethodDescription expectedMethodDescription = new MethodDescription();

            expectedMethodDescription.ComponentObject = component;
            expectedMethodDescription.Method          = methodInfo;
            expectedMethodDescription.StepType        = typeof(GivenBaseAttribute);
            expectedMethodDescription.Text            = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethodDescription.ExecutionOrder  = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetExecutionOrder();

            ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities();
            FieldInfo             arrayStorage          = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));

            arrayStorage.SetValue(component, new string[1] {
                "Parameter Value"
            });

            MethodParameter expectedParameter = new MethodParameter();

            expectedParameter.ParameterInfoObject = methodInfo.GetParameters()[0];

            ParameterLocation parameterLocation = new ParameterLocation();

            parameterLocation.ParameterClassLocation = new ParameterLocation.ClassLocation();
            parameterLocation.ParameterClassLocation.ComponentObject = component;
            parameterLocation.ParameterClassLocation.ComponentType   = component.GetType();
            parameterLocation.ParameterArrayLocation = new ParameterLocation.ArrayLocation();
            parameterLocation.ParameterArrayLocation.ArrayFieldInfo = component.GetType().GetField("StringsArrayStorage");
            parameterLocation.ParameterArrayLocation.ArrayName      = "StringsArrayStorage";
            parameterLocation.ParameterArrayLocation.ArrayIndex     = 0;

            expectedParameter.ParameterLocation = parameterLocation;

            expectedParameter.Value = "Parameter Value";
            MethodParameters methodParameters = new MethodParameters();

            methodParameters.Parameters = new MethodParameter[1] {
                expectedParameter
            };
            expectedMethodDescription.Parameters = methodParameters;

            expectedMethodDescription.ParametersIndex = parametersIndex;

            MethodParametersLoader methodParametersLoader = Substitute.For <MethodParametersLoader>();

            methodParametersLoader.LoadMethodParameters(component, methodInfo, string.Empty, parametersIndex).Returns(expectedMethodDescription.Parameters);

            BaseMethodDescription baseMethodDescription = new BaseMethodDescription();

            baseMethodDescription.ComponentObject = component;
            baseMethodDescription.Method          = methodInfo;
            baseMethodDescription.StepType        = typeof(GivenBaseAttribute);
            baseMethodDescription.Text            = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetStepScenarioText();
            baseMethodDescription.ExecutionOrder  = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetExecutionOrder();

            MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder();
            MethodDescription        builderResult            = methodDescriptionBuilder.Build(methodParametersLoader, baseMethodDescription, parametersIndex);

            Assert.IsTrue(expectedMethodDescription.Equals(builderResult), "The method MethodDescriptionBuilder.Build does not return the expected object");
        }