/// <summary>
        /// Loads the parameter location.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="method">The method.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="parametersIndex">Index of the parameters.</param>
        /// <returns>The parameter location.</returns>
        private static ParameterLocation LoadParameterLocation(object obj, MethodInfo method, ParameterInfo parameter, string id, string parametersIndex)
        {
            // parametersIndex Format: ;paramtype,className.methodName.paramName.fullId,arrayName.Array.data[index];
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            ParameterLocation        result = null;

            if (parametersIndex != null)
            {
                string   expectedParameterFullName = parametersIndexUtilities.GetParameterFullName(method.DeclaringType.Name, method.Name, parameter.Name, id);
                string[] parameterIndexes          = parametersIndexUtilities.GetParametersIndexList(parametersIndex);
                foreach (string parameterIndex in parameterIndexes)
                {
                    if (!parameterIndex.Equals(string.Empty))
                    {
                        string parameterFullName = parametersIndexUtilities.GetParameterFullName(parameterIndex);
                        if (parameterFullName.Equals(expectedParameterFullName))
                        {
                            string arrayName = parametersIndexUtilities.GetParameterValueStorageName(parameterIndex);

                            int index = parametersIndexUtilities.GetParameterValueStorageLocationIndex(parameterIndex);
                            result = new ParameterLocation();
                            ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities();
                            FieldInfo             field = arrayStorageUtilities.GetArrayStorageFieldInfoByName(obj, arrayName);
                            result.ParameterArrayLocation.ArrayFieldInfo  = field;
                            result.ParameterArrayLocation.ArrayIndex      = index;
                            result.ParameterArrayLocation.ArrayName       = arrayName;
                            result.ParameterClassLocation.ComponentType   = obj.GetType();
                            result.ParameterClassLocation.ComponentObject = obj;
                        }
                    }
                }
            }

            return(result);
        }
        /// <summary>
        /// Loads the parameter value.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="method">The method.</param>
        /// <param name="parameter">The parameter.</param>
        /// <param name="id">The identifier.</param>
        /// <param name="parametersIndexes">The parameters indexes.</param>
        /// <returns>The parameter value.</returns>
        private static object LoadParameterValue(object obj, MethodInfo method, ParameterInfo parameter, string id, string parametersIndexes)
        {
            // parametersIndex Format: ;paramtype,className.methodName.paramName.fullId,arrayName.Array.data[index];
            object result = null;
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();

            if (parametersIndexes != null)
            {
                string   expectedParameterFullName = parametersIndexUtilities.GetParameterFullName(method.DeclaringType.Name, method.Name, parameter.Name, id);
                string[] parametersIndexesList     = parametersIndexUtilities.GetParametersIndexList(parametersIndexes);
                foreach (string parameterIndex in parametersIndexesList)
                {
                    if (!parameterIndex.Equals(string.Empty))
                    {
                        string parameterFullName = parametersIndexUtilities.GetParameterFullName(parameterIndex);
                        if (parameterFullName.Equals(expectedParameterFullName))
                        {
                            string arrayName = parametersIndexUtilities.GetParameterValueStorageName(parameterIndex);

                            int index = parametersIndexUtilities.GetParameterValueStorageLocationIndex(parameterIndex);
                            result = GetValue(obj, arrayName, index);
                        }
                    }
                }
            }

            return(result);
        }
        public void GetParameterId_Should_ReturnParameterId_Given_AParameterIndexForAParameterIdWithValueParameterId()
        {
            string parameterIndex       = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]";
            string expectedParamenterId = "parameterId";
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            string result = parametersIndexUtilities.GetParameterId(parameterIndex);

            Assert.AreEqual(expectedParamenterId, result, "The method GetParameterId doesn't return the right parameterType");
        }
        public void GetMethodName_Should_ReturnMethodName_Given_AParameterIndexForAMethodCalledMethodName()
        {
            string parameterIndex     = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]";
            string expectedMethodName = "MethodName";
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            string result = parametersIndexUtilities.GetMethodName(parameterIndex);

            Assert.AreEqual(expectedMethodName, result, "The method GetMethodName doesn't return the right parameterType");
        }
        public void GetParameterValueStorageLocationIndex_Should_ReturnZero_Given_AParameterIndexWithTheIndexOfTHeParametersValuesStorageArraySetToZero()
        {
            string parameterIndex = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]";
            int    expectedParameterValueStorageLocationIndex = 0;
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            int result = parametersIndexUtilities.GetParameterValueStorageLocationIndex(parameterIndex);

            Assert.AreEqual(expectedParameterValueStorageLocationIndex, result, "The method GetParameterValueStorageLocationIndex doesn't return the right parameterType");
        }
        public void GetParameterValueStorageLocation_Should_ReturnTheExpectedValueStorageLocation_Given_AParameterIndex()
        {
            string parameterIndex = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]";
            string expectedParamenterValueStorageLocation     = "parameterPVS.Array.data[0]";
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            string result = parametersIndexUtilities.GetParameterValueStorageLocation(parameterIndex);

            Assert.AreEqual(expectedParamenterValueStorageLocation, result, "The method GetParameterValueStorageLocation doesn't return the right parameterType");
        }
        public void GetParameterFullName_Should_ReturnTheExpectedParameterFullName_Given_AllTheInformationsForBuildingIt()
        {
            string expectedParameterFullName = "ComponentName.MethodName.parameterName.parameterId";
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            string componentName = "ComponentName";
            string methodName    = "MethodName";
            string parameterName = "parameterName";
            string parameterId   = "parameterId";
            string result        = parametersIndexUtilities.GetParameterFullName(componentName, methodName, parameterName, parameterId);

            Assert.AreEqual(expectedParameterFullName, result, "The method GetParameterFullName doesn't return the right parameterType");
        }
Example #8
0
        /// <summary>
        /// Checks for not matching ParametersValuesStorage fields.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="parametersIndexes">The parameters indexes.</param>
        /// <param name="components">The components.</param>
        /// <returns>A list of <see cref="UnityTestBDDError"/> objects. Each element describes an error found. If the list is empty, there are no errors. The list cannot be null.</returns>
        public List <UnityTestBDDError> CheckForNotMatchingPVS <T>(string[] chosenMethods, string[] parametersIndexes, Component[] components)
        {
            List <UnityTestBDDError> result = new List <UnityTestBDDError>();
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();

            for (int index = 0; index < chosenMethods.Length; index++)
            {
                Component component           = this.GetComponent(chosenMethods[index], components);
                string[]  parametersIndexList = parametersIndexUtilities.GetParametersIndexList(parametersIndexes[index]);
                foreach (string parameterIndex in parametersIndexList)
                {
                    string    arrayPVSName = parametersIndexUtilities.GetParameterValueStorageName(parameterIndex);
                    FieldInfo arrayPVS     = component.GetType().GetField(arrayPVSName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                    if (arrayPVS == null)
                    {
                        IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty);
                        UnityTestBDDError         error = new UnityTestBDDError();
                        error.Message                     = "The ParametersValuesStorage field " + arrayPVSName + " for the parameter " + parametersIndexUtilities.GetParameterFullName(parameterIndex) + " is not found in " + genericComponentInteface.GetStepName() + " methods at position " + (index + 1);
                        error.Component                   = component;
                        error.MethodMethodInfo            = this.GetMethodInfo(chosenMethods[index], component);
                        error.StepType                    = typeof(T);
                        error.Index                       = index;
                        error.LockRunnerInspectorOnErrors = false;
                        error.ShowButton                  = true;
                        error.LockBuildParameters         = true;
                        error.LockParametersRows          = true;

                        result.Add(error);
                    }
                    else
                    {
                        Array array = arrayPVS.GetValue(component) as Array;
                        if (array == null || array.Length == 0)
                        {
                            UnityTestBDDError error = new UnityTestBDDError();
                            error.Message                     = "The component " + component.GetType().Name + " seems to have been reset, so some parameter values are lost. Please, undo the reset operation or rebuild the settings to confirm the reset.";
                            error.Component                   = component;
                            error.MethodMethodInfo            = this.GetMethodInfo(chosenMethods[index], component);
                            error.StepType                    = typeof(T);
                            error.Index                       = index;
                            error.LockRunnerInspectorOnErrors = false;
                            error.ShowButton                  = true;
                            error.LockBuildParameters         = true;
                            error.LockParametersRows          = true;

                            result.Add(error);
                        }
                    }
                }
            }

            return(result);
        }
        public void GetParametersIndexList_Should_ReturnTheExpectedListOfParameterIndexes_Given_AParametersIndexes()
        {
            string parameterIndex = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0];System.String,ComponentName.MethodName.parameterName.parameterId1,parameterPVS.Array.data[1];";

            string[] expectedGetParametersIndexList = new string[2] {
                "System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]", "System.String,ComponentName.MethodName.parameterName.parameterId1,parameterPVS.Array.data[1]"
            };
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();

            string[] result = parametersIndexUtilities.GetParametersIndexList(parameterIndex);
            Assert.AreEqual(expectedGetParametersIndexList[0], result[0], "The method GetParametersIndexList doesn't return the right parameterType");
            Assert.AreEqual(expectedGetParametersIndexList[1], result[1], "The method GetParametersIndexList doesn't return the right parameterType");
        }
        public void BuildParameterIndex_Should_ReturnTheExpectedParameterIndex_Given_AllTheInformationsForBuildingIt()
        {
            string expectedParametersIndex = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]";
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();
            Type   parameterType = typeof(string);
            string componentName = "ComponentName";
            string methodName    = "MethodName";

            string parameterName         = "parameterName";
            string parameterId           = "parameterId";
            string parameterValueStorage = "parameterPVS";
            int    index  = 0;
            string result = parametersIndexUtilities.BuildParameterIndex(parameterType, componentName, methodName, parameterName, parameterId, parameterValueStorage, index);

            Assert.AreEqual(expectedParametersIndex, result, "The method BuildParameterIndex doesn't return the right index");
        }
Example #11
0
        /// <summary>
        /// Checks the parameters index for not matching parameters.
        /// </summary>
        /// <typeparam name="T">The type of the Step Method.</typeparam>
        /// <param name="chosenMethods">The chosen methods.</param>
        /// <param name="parametersIndexes">The parameters indexes.</param>
        /// <param name="components">The components.</param>
        /// <returns>A list of <see cref="UnityTestBDDError"/> objects. Each element describes an error found. If the list is empty, there are no errors. The list cannot be null.</returns>
        public List <UnityTestBDDError> CheckForNotMatchingParametersIndex <T>(string[] chosenMethods, string[] parametersIndexes, Component[] components) where T : IGivenWhenThenDeclaration
        {
            List <UnityTestBDDError> result = new List <UnityTestBDDError>();
            ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities();

            for (int index = 0; index < chosenMethods.Length; index++)
            {
                string[] parametersIndexList = parametersIndexUtilities.GetParametersIndexList(parametersIndexes[index]);
                foreach (string parametersIndex in parametersIndexList)
                {
                    string     parameterType  = parametersIndexUtilities.GetParameterType(parametersIndex);
                    string     parameterName  = parametersIndexUtilities.GetParameterName(parametersIndex);
                    string     methodFullName = parametersIndexUtilities.GetMethodFullName(parametersIndex);
                    Component  component      = this.GetComponent(methodFullName, components);
                    MethodInfo methodInfo     = this.GetMethodInfo(methodFullName, component);
                    List <UnityTestBDDError> partialResult = this.CheckForNotMatchingParametersIndex <T>(component, methodInfo, parameterType, parameterName, index);
                    result.AddRange(partialResult);
                }
            }

            return(result);
        }