/// <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 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.");
        }
Exemple #3
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);
            }

            MethodParameter methodParameter = (MethodParameter)obj;

            if (((this.ParameterInfoObject == null && methodParameter.ParameterInfoObject == null) || object.Equals(this.ParameterInfoObject, methodParameter.ParameterInfoObject))
                &&
                ((this.Value == null && methodParameter.Value == null) || this.Value.Equals(methodParameter.Value))
                &&
                ((this.ParameterLocation == null && methodParameter.ParameterLocation == null) || this.ParameterLocation.Equals(methodParameter.ParameterLocation)))
            {
                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");
        }
        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.");
        }
        /// <summary>
        /// Builds the index of the parameter.
        /// </summary>
        /// <param name="fullMethodDescription">The full method description.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="index">The index.</param>
        /// <param name="arrayFieldInfo">The array field information.</param>
        /// <returns>A string containing the parameter index.</returns>
        private string BuildParameterIndex(FullMethodDescription fullMethodDescription, MethodParameter parameter, int index, FieldInfo arrayFieldInfo)
        {
            // ";string,BDDComponentForTest.GivenMethod.stringParam.fullId,stringsArrayStorage.Array.data[0];"
            MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities();

            return(parameter.ParameterInfoObject.ParameterType.FullName + "," + fullMethodDescription.GetFullName() + "." +
                   parameter.ParameterInfoObject.Name + "." + methodsManagementUtilities.GetMainFullId(fullMethodDescription.MainMethod) + fullMethodDescription.Id + "," + arrayFieldInfo.Name + ".Array.data[" + index + "]");
        }