/// <summary> /// Gets the the string of the Step Method type. /// </summary> /// <typeparam name="T">An implementation of the interface IGivenWhenThenDeclaration.</typeparam> /// <returns>The string of the Step Method type.</returns> public static string GetStepMethodName <T>() where T : IGivenWhenThenDeclaration { IGivenWhenThenDeclaration declaration = Activator.CreateInstance(typeof(T), string.Empty) as IGivenWhenThenDeclaration; string result = declaration.GetStepName(); return(result); }
/// <summary> /// Adds the delay and timeout information to the Main method. /// </summary> /// <param name="mainFullMethodDescription">The main full method description.</param> private void AddDelayAndTimeoutToMainFullMethodDescription(FullMethodDescription mainFullMethodDescription) { object[] customCallBeforeAttributes = mainFullMethodDescription.Method.GetCustomAttributes(mainFullMethodDescription.StepType, true); IGivenWhenThenDeclaration bddBethodBaseAttribute = (IGivenWhenThenDeclaration)customCallBeforeAttributes[0]; mainFullMethodDescription.Delay = bddBethodBaseAttribute.GetDelay(); mainFullMethodDescription.TimeOut = bddBethodBaseAttribute.GetTimeout(); }
/// <summary> /// Checks the parameters index for not matching parameters.. /// </summary> /// <typeparam name="T">The type of the Step Method.</typeparam> /// <param name="component">The component.</param> /// <param name="methodInfo">The method information.</param> /// <param name="parameterType">Type of the parameter.</param> /// <param name="parameterName">Name of the parameter.</param> /// <param name="chosenMethodIndex">Index of the chosen method.</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>(Component component, MethodInfo methodInfo, string parameterType, string parameterName, int chosenMethodIndex) where T : IGivenWhenThenDeclaration { List <UnityTestBDDError> result = new List <UnityTestBDDError>(); bool isParameterFound = false; bool isParameterTypeMatching = false; ParameterInfo[] parameters = methodInfo.GetParameters(); Type currentParameterType = null; foreach (ParameterInfo parameter in parameters) { if (parameter.Name.Equals(parameterName)) { isParameterFound = true; currentParameterType = parameter.ParameterType; if (currentParameterType.FullName.Equals(parameterType)) { isParameterTypeMatching = true; } } } if (!isParameterFound) { IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty); UnityTestBDDError error = new UnityTestBDDError(); error.Message = "The parameter " + component.GetType().Name + "." + methodInfo.Name + "." + parameterName + " is not found in " + genericComponentInteface.GetStepName() + " methods at position " + (chosenMethodIndex + 1); error.Component = component; error.MethodMethodInfo = methodInfo; error.StepType = typeof(T); error.Index = chosenMethodIndex; error.LockRunnerInspectorOnErrors = false; error.ShowButton = true; error.LockBuildParameters = true; error.LockParametersRows = true; result.Add(error); } else if (!isParameterTypeMatching) { IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty); UnityTestBDDError error = new UnityTestBDDError(); error.Message = "The parameter " + component.GetType().Name + "." + methodInfo.Name + "." + parameterName + " has a wrong type in " + genericComponentInteface.GetStepName() + " methods at position " + (chosenMethodIndex + 1) + ".\n Previous type: " + parameterType + "\n Current type " + currentParameterType.FullName; error.Component = component; error.MethodMethodInfo = methodInfo; error.StepType = typeof(T); error.Index = chosenMethodIndex; error.LockRunnerInspectorOnErrors = false; error.ShowButton = true; error.LockBuildParameters = true; error.LockParametersRows = true; result.Add(error); } return(result); }
/// <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); }
/// <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); }
/// <summary> /// Checks for blank methods. /// </summary> /// <typeparam name="T">The type of the Step Method.</typeparam> /// <param name="chosenMethods">The chosen methods.</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> CheckForBlankMethods <T>(string[] chosenMethods) where T : IGivenWhenThenDeclaration { List <UnityTestBDDError> result = new List <UnityTestBDDError>(); for (int index = 0; index < chosenMethods.Length; index++) { if (chosenMethods[index].Equals(string.Empty)) { IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty); UnityTestBDDError error = new UnityTestBDDError(); error.Message = "Incomplete settings detected on " + genericComponentInteface.GetStepName() + " methods at position " + (index + 1); error.StepType = typeof(T); error.Index = index; error.LockRunnerInspectorOnErrors = false; error.ShowButton = false; error.LockBuildParameters = false; error.LockParametersRows = false; result.Add(error); } } return(result); }
/// <summary> /// Checks for BDD Component not found. /// </summary> /// <typeparam name="T">The type of the Step Method.</typeparam> /// <param name="chosenMethods">The chosen methods.</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> CheckForComponentNotFound <T>(string[] chosenMethods, Component[] components) { List <UnityTestBDDError> result = new List <UnityTestBDDError>(); for (int index = 0; index < chosenMethods.Length; index++) { if (this.GetComponent(chosenMethods[index], components) == null && chosenMethods[index] != null && !chosenMethods[index].Equals(string.Empty)) { IGivenWhenThenDeclaration genericComponentInteface = (IGivenWhenThenDeclaration)Activator.CreateInstance(typeof(T), string.Empty); UnityTestBDDError error = new UnityTestBDDError(); error.Message = "The component for the method " + chosenMethods[index] + " is not found in " + genericComponentInteface.GetStepName() + " methods at position " + (index + 1); error.StepType = typeof(T); error.Index = index; error.LockRunnerInspectorOnErrors = false; error.ShowButton = false; error.LockBuildParameters = true; error.LockParametersRows = true; result.Add(error); } } return(result); }