コード例 #1
0
        /// <summary>
        /// Gets the <see cref="FullMethodDescription"/> for the method declared by the <see cref="CallBefore"/> attribute.
        /// </summary>
        /// <param name="callBefore">The call before.</param>
        /// <param name="mainMethod">The main method.</param>
        /// <param name="parametersIndex">Index of the parameters.</param>
        /// <returns>The <see cref="FullMethodDescription"/> for the method declared by the <see cref="CallBefore"/> attribute.</returns>
        private FullMethodDescription GetCallBeforeFullMethodDescription(CallBefore callBefore, FullMethodDescription mainMethod, string parametersIndex)
        {
            MethodInfo                 methodInfo                 = mainMethod.ComponentObject.GetType().GetMethod(callBefore.Method);
            MethodParametersLoader     methodParametersLoader     = new MethodParametersLoader();
            MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities();
            string           fullId           = methodsManagementUtilities.GetMainFullId(mainMethod) + callBefore.Id;
            MethodParameters methodParameters = methodParametersLoader.LoadMethodParameters(mainMethod.ComponentObject, methodInfo, fullId, parametersIndex);

            FullMethodDescription result = this.GetFullMethodDescription(mainMethod.ComponentObject, methodInfo, mainMethod.StepType, mainMethod.Text, methodParameters, string.Empty, 0, callBefore.Delay, callBefore.Timeout, callBefore.ExecutionOrder, callBefore.Id, mainMethod);

            return(result);
        }
コード例 #2
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>
        /// Creates the <see cref="MethodParameters"/> object, populating the values of the parameters using the parameters indexes.
        /// </summary>
        /// <param name="obj">The object containing the method.</param>
        /// <param name="method">The method.</param>
        /// <param name="id">The identifier of the parameters.</param>
        /// <param name="parametersIndex">Index of the parameters.</param>
        /// <returns>The <see cref="MethodParameters"/> object, populating the values of the parameters using the parameters indexes.</returns>
        public virtual MethodParameters LoadMethodParameters(object obj, MethodInfo method, string id, string parametersIndex)
        {
            List <MethodParameter> parametersList = new List <MethodParameter>();

            ParameterInfo[] parametersInfo = method.GetParameters();
            foreach (ParameterInfo parameterInfo in parametersInfo)
            {
                MethodParameter mp = new MethodParameter();
                mp.ParameterInfoObject = parameterInfo;
                mp.Value             = LoadParameterValue(obj, method, parameterInfo, id, parametersIndex);
                mp.ParameterLocation = LoadParameterLocation(obj, method, parameterInfo, id, parametersIndex);
                parametersList.Add(mp);
            }

            MethodParameters result = new MethodParameters();

            result.Parameters = parametersList.ToArray();
            return(result);
        }
        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 LoadMethodParameters_Should_ReturnTheExpectedMethodParametersObject_Given_ADynamicComponentAndAMethodWithOneStringParameterAndItsParameterIndex()
        {
            MethodParametersLoaderTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodParametersLoaderTestDynamicComponent>();

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

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

            MethodInfo method = component.GetType().GetMethod("GivenMethod");

            MethodParameter expectedParameter = new MethodParameter();

            expectedParameter.ParameterInfoObject = method.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 = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));
            parameterLocation.ParameterArrayLocation.ArrayName      = "stringPVS";
            parameterLocation.ParameterArrayLocation.ArrayIndex     = 0;

            expectedParameter.ParameterLocation = parameterLocation;

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

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

            string parametersIndex = ";System.String,MethodParametersLoaderTestDynamicComponent.GivenMethod.stringParam.,stringPVS.Array.data[0];";
            MethodParametersLoader methodParametersLoader = new MethodParametersLoader();
            MethodParameters       methodParameters       = methodParametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex);

            Assert.That(expectedMethodParameters.Equals(methodParameters), "The method MethodParametersLoader.LoadMethodParameters doesn't return the right object.");
        }
コード例 #6
0
        /// <summary>
        /// Gets the full method description.
        /// </summary>
        /// <param name="componentObject">The <see cref="Component"/> object containing the method.</param>
        /// <param name="method">The <see cref="MethodInfo"/> object for the method.</param>
        /// <param name="stepType">The Step Type.</param>
        /// <param name="text">The BDD text for the method. Can be empty. Cannot be null.</param>
        /// <param name="parameters">The <see cref="MethodParameters"/> object.</param>
        /// <param name="parametersIndex">The string indicating the ParametersIndex for the values of the parameters.</param>
        /// <param name="executionOrder">The relative order of the execution of the method in the call chain.</param>
        /// <param name="delay">The value of the delay.</param>
        /// <param name="timeOut">The value of the timeout.</param>
        /// <param name="callBeforeExecutionOrder">The relative order of the execution of the method in the call chain of the CallBefore methods.</param>
        /// <param name="id">The string that can make the parameter identifier unique.</param>
        /// <param name="mainMethod">The <see cref="FullMethodDescription"/> object if the parent method in the call chain.</param>
        /// <returns>THe <see cref="FullMethodDescription"/> object describing the information passed by the parameters.</returns>
        private FullMethodDescription GetFullMethodDescription(Component componentObject, MethodInfo method, Type stepType, string text, MethodParameters parameters, string parametersIndex, uint executionOrder, uint delay, uint timeOut, uint callBeforeExecutionOrder, string id, FullMethodDescription mainMethod)
        {
            FullMethodDescription result = new FullMethodDescription();

            result.ComponentObject = componentObject;
            result.Method          = method;
            result.StepType        = stepType;
            result.Text            = text;
            result.Parameters      = parameters;
            result.ParametersIndex = parametersIndex;
            result.ExecutionOrder  = executionOrder;
            result.Delay           = delay;
            result.TimeOut         = timeOut;
            result.SuccessionOrder = callBeforeExecutionOrder;
            result.MainMethod      = mainMethod;
            result.Id = id;

            return(result);
        }
        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");
        }
        public void LoadMethodParameters_Should_ReturnTheExpectedMethodParametersObject_Given_ADynamicComponentAndAMethodWithOneStringParameterAndOneIntParameterWithTheirParameterIndexes()
        {
            MethodParametersLoaderTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodParametersLoaderTestDynamicComponent>();

            ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities();

            FieldInfo stringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));

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

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

            intArrayStorage.SetValue(component, new int[1] {
                102
            });

            MethodInfo method = component.GetType().GetMethod("WhenMethod");

            ParameterInfo[] parametersInfo = method.GetParameters();

            MethodParameter expectedParameter1 = new MethodParameter();

            expectedParameter1.ParameterInfoObject = parametersInfo[0];

            ParameterLocation parameterLocation1 = new ParameterLocation();

            parameterLocation1.ParameterClassLocation = new ParameterLocation.ClassLocation();
            parameterLocation1.ParameterClassLocation.ComponentObject = component;
            parameterLocation1.ParameterClassLocation.ComponentType   = component.GetType();
            parameterLocation1.ParameterArrayLocation = new ParameterLocation.ArrayLocation();
            parameterLocation1.ParameterArrayLocation.ArrayFieldInfo = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string));
            parameterLocation1.ParameterArrayLocation.ArrayName      = "stringPVS";
            parameterLocation1.ParameterArrayLocation.ArrayIndex     = 0;

            expectedParameter1.ParameterLocation = parameterLocation1;

            expectedParameter1.Value = "Parameter Value";

            MethodParameter expectedParameter2 = new MethodParameter();

            expectedParameter2.ParameterInfoObject = parametersInfo[1];

            ParameterLocation parameterLocation2 = new ParameterLocation();

            parameterLocation2.ParameterClassLocation = new ParameterLocation.ClassLocation();
            parameterLocation2.ParameterClassLocation.ComponentObject = component;
            parameterLocation2.ParameterClassLocation.ComponentType   = component.GetType();
            parameterLocation2.ParameterArrayLocation = new ParameterLocation.ArrayLocation();
            parameterLocation2.ParameterArrayLocation.ArrayFieldInfo = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(int));
            parameterLocation2.ParameterArrayLocation.ArrayName      = "intPVS";
            parameterLocation2.ParameterArrayLocation.ArrayIndex     = 0;

            expectedParameter2.ParameterLocation = parameterLocation2;

            expectedParameter2.Value = 102;

            MethodParameters expectedMethodParameters = new MethodParameters();

            expectedMethodParameters.Parameters = new MethodParameter[2] {
                expectedParameter1, expectedParameter2
            };

            string parametersIndex = ";System.String,MethodParametersLoaderTestDynamicComponent.WhenMethod.whenStringParam.,stringPVS.Array.data[0];System.Int32,MethodParametersLoaderTestDynamicComponent.WhenMethod.whenIntParam.,intPVS.Array.data[0];";
            MethodParametersLoader methodParametersLoader = new MethodParametersLoader();
            MethodParameters       methodParameters       = methodParametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex);

            Assert.That(expectedMethodParameters.Equals(methodParameters), "The method MethodParametersLoader.LoadMethodParameters doesn't return the right object.");
        }