/// <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 GetParameterFullName_Should_ReturnTheExpectedParameterFullName_Given_AParameterIndex() { string parameterIndex = ";System.String,ComponentName.MethodName.parameterName.parameterId,parameterPVS.Array.data[0]"; string expectedParameterFullName = "ComponentName.MethodName.parameterName.parameterId"; ParametersIndexUtilities parametersIndexUtilities = new ParametersIndexUtilities(); string result = parametersIndexUtilities.GetParameterFullName(parameterIndex); Assert.AreEqual(expectedParameterFullName, result, "The method GetParameterFullName 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"); }
/// <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); }