/// <summary> /// Draws the parameters rows. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="foldout">If set to <c>true</c> [foldout].</param> /// <param name="fullMethodDescription">The full method description.</param> /// <param name="serializedObjects">The serialized objects.</param> /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param> public void DrawParametersRows(IUnityInterfaceWrapper unityInterface, bool foldout, FullMethodDescription fullMethodDescription, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, bool lockParametersRows) { if (fullMethodDescription != null && foldout && !lockParametersRows) { ISerializedObjectWrapper serializedObject = null; serializedObjects.TryGetValue(fullMethodDescription.ComponentObject.GetType(), out serializedObject); foreach (MethodParameter parameter in fullMethodDescription.Parameters.Parameters) { string parameterName = parameter.ParameterInfoObject.Name; ParameterLocation parameterLocation = parameter.ParameterLocation; // "given.Array.data[0]" string parameterLocationString = parameterLocation.ParameterArrayLocation.ArrayName + ".Array.data[" + parameterLocation.ParameterArrayLocation.ArrayIndex + "]"; GUIContent label = unityInterface.GUIContent(parameterName); ISerializedPropertyWrapper property = serializedObject.FindProperty(parameterLocationString); unityInterface.EditorGUILayoutPropertyField(property, label); } } if (fullMethodDescription != null && foldout && lockParametersRows) { float labelWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); unityInterface.EditorGUILayoutLabelField("When there are some errors the parameters are protected to avoid data lost.", labelWidth); } }
/// <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> /// 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); } ParameterLocation parameterLocation = (ParameterLocation)obj; if (((this.ParameterClassLocation == null && parameterLocation.ParameterClassLocation == null) || this.ParameterClassLocation.Equals(parameterLocation.ParameterClassLocation)) && ((this.ParameterArrayLocation == null && parameterLocation.ParameterArrayLocation == null) || this.ParameterArrayLocation.Equals(parameterLocation.ParameterArrayLocation))) { return(true); } return(false); }
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."); }
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."); }