/// <summary> /// Draws the cog button. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="methodDescription">The method description.</param> /// <param name="bddExtensionRunner">The BDD extension runner.</param> internal void DrawCogButton(IUnityInterfaceWrapper unityInterface, MethodDescription methodDescription, BDDExtensionRunner bddExtensionRunner) { string cogTexture = @"cog.png"; string cogTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, cogTexture); Texture2D inputTexture = unityInterface.AssetDatabaseLoadAssetAtPath(cogTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(16), unityInterface.GUILayoutHeight(16) }; if (unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, options)) { GenericMenu menu = new GenericMenu(); GUIContent content = new GUIContent("Open method source"); bool on = false; MethodInfo method = null; if (methodDescription != null) { on = true; method = methodDescription.Method; menu.AddItem(content, on, () => { SourcesManagement.OpenMethodSourceCode(method, unityInterface); }); } else { menu.AddDisabledItem(content); } menu.ShowAsContext(); } }
/// <summary> /// Builds the list of <see cref="FullMethodDescription"/> objects based on the information contained into a <see cref="BaseMethodDescription"/> object. /// </summary> /// <param name="baseMethodDescription">The <see cref="BaseMethodDescription"/> object.</param> /// <param name="stepNumber">The index of the Step Method inside a chosenMethod list.</param> /// <returns>A <see cref="List"/> of <see cref="FullMethodDescription"/> object. Each element represent one of the element in the call chain defined by the <see cref="CallBefore"/> attributes. The last one is the main method described by the <paramref name="baseMethodDescription"/> parameter.</returns> public virtual List <FullMethodDescription> BuildFromBaseMethodDescription(BaseMethodDescription baseMethodDescription, uint stepNumber) { MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); string parametersIndex = string.Empty; MethodDescription methodDescription = methodDescriptionBuilder.Build(methodParametersLoader, baseMethodDescription, parametersIndex); return(this.Build(methodDescription, stepNumber)); }
public void LoadMethodsDescriptionsFromChosenMethods_Should_ReturnTheExpectedMethodDescriptionObjects_Given_ADynamicComponentAndAListOfChosenMethods() { MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); MethodsManagementUtilitiesTestFirstDynamicComponent bddComponent1 = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestFirstDynamicComponent>(); MethodsManagementUtilitiesTestSecondDynamicComponent bddComponent2 = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestSecondDynamicComponent>(); ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo firstStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(bddComponent1, typeof(string)); firstStringArrayStorage.SetValue(bddComponent1, new string[1] { "Parameter For The MethodsManagementUtilitiesTestFirstDynamicComponent.GivenMethod" }); FieldInfo secondStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(bddComponent2, typeof(string)); secondStringArrayStorage.SetValue(bddComponent2, new string[1] { "Parameter For The MethodsManagementUtilitiesTestSecondDynamicComponent.GivenMethod" }); Component[] dynamicBDDComponents = new Component[2] { bddComponent1, bddComponent2 }; BaseMethodDescriptionBuilder methodBuilder = new BaseMethodDescriptionBuilder(); string[] chosenMethods = new string[2] { "MethodsManagementUtilitiesTestSecondDynamicComponent.GivenMethod", "MethodsManagementUtilitiesTestFirstDynamicComponent.GivenMethod" }; IMethodsFilter methodFilter = new MethodsFilterByMethodsFullNameList(chosenMethods); MethodsLoader methodsLoader = new MethodsLoader(methodBuilder, methodFilter); MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); string[] chosenMethodsParametersIndexes = new string[2] { ";string,MethodsManagementUtilitiesTestSecondDynamicComponent.GivenMethod.stringParam.,stringPVS.Array.data[0];", ";string,MethodsManagementUtilitiesTestFirstDynamicComponent.GivenMethod.stringParam.,stringPVS.Array.data[0];" }; List <MethodDescription> methodDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <GivenBaseAttribute>(dynamicBDDComponents, methodsLoader, methodDescriptionBuilder, methodParametersLoader, chosenMethods, chosenMethodsParametersIndexes); Assert.AreEqual(2, methodDescriptionList.Count, "The method LoadMethodsDescriptionsFromChosenMethods doesn't return the expected amount of Method Descriptions"); MethodDescription expectedMethodDescription1 = null; MethodDescription expectedMethodDescription2 = null; if (chosenMethods[0].Equals(methodDescriptionList[0].Method.DeclaringType.Name + "." + methodDescriptionList[0].Method.Name)) { expectedMethodDescription1 = methodDescriptionList[0]; expectedMethodDescription2 = methodDescriptionList[1]; } else { expectedMethodDescription1 = methodDescriptionList[1]; expectedMethodDescription2 = methodDescriptionList[0]; } Assert.AreEqual(chosenMethods[0], expectedMethodDescription1.GetFullName(), "The method LoadMethodsDescriptionsFromChosenMethods doesn't return the expected methods"); Assert.AreEqual(chosenMethods[1], expectedMethodDescription2.GetFullName(), "The method LoadMethodsDescriptionsFromChosenMethods doesn't return the expected methods"); }
/// <summary> /// Gets the method description. /// </summary> /// <param name="methodDescriptionBuilder">The method description builder.</param> /// <param name="parametersLoader">The parameters loader.</param> /// <param name="chosenMethods">The chosen methods.</param> /// <param name="methodsList">The methods list.</param> /// <param name="index">The index.</param> /// <returns>The method description.</returns> public MethodDescription GetMethodDescription(MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader parametersLoader, ChosenMethods chosenMethods, List <BaseMethodDescription> methodsList, int index) { MethodDescription methodDescription = null; if (!chosenMethods.ChosenMethodsNames[index].Equals(string.Empty)) { methodDescription = this.GetMethodDescriptionForTheChosenMethod(methodDescriptionBuilder, parametersLoader, chosenMethods.ChosenMethodsNames[index], chosenMethods.ChosenMethodsParametersIndex[index], methodsList); } return(methodDescription); }
/// <summary> /// Builds a list of <see cref="FullMethodDescription"/> objects given a list of <see cref="MethodDescription"/> objects. /// </summary> /// <typeparam name="T">The type of the Step Method.</typeparam> /// <param name="methodsDescriptionsList">The methods descriptions list.</param> /// <param name="fullMethodDescriptionBuilder">The full method description builder.</param> /// <returns>A list of <see cref="FullMethodDescription"/> objects.</returns> public List <FullMethodDescription> LoadFullMethodsDescriptions <T>(List <MethodDescription> methodsDescriptionsList, FullMethodDescriptionBuilder fullMethodDescriptionBuilder) where T : IGivenWhenThenDeclaration { List <FullMethodDescription> fullMethodsDescriptions = new List <FullMethodDescription>(); for (int index = 0; index < methodsDescriptionsList.Count; index++) { MethodDescription methodDescription = methodsDescriptionsList[index]; List <FullMethodDescription> fullmethodDescriptionsList = fullMethodDescriptionBuilder.Build(methodDescription, (uint)index + 1); fullMethodsDescriptions.AddRange(fullmethodDescriptionsList); } return(fullMethodsDescriptions); }
/// <summary> /// Gets the <see cref="MethodDescription"/> object for the chosen method. /// </summary> /// <param name="methodDescriptionBuilder">The method description builder.</param> /// <param name="parametersLoader">The parameters loader.</param> /// <param name="chosenMethodName">Name of the chosen method.</param> /// <param name="chosenMethodParametersIndex">Index of the chosen method parameters.</param> /// <param name="methodsList">The methods list.</param> /// <returns>The <see cref="MethodDescription"/> object for the chosen method.</returns> public MethodDescription GetMethodDescriptionForTheChosenMethod(MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader parametersLoader, string chosenMethodName, string chosenMethodParametersIndex, List <BaseMethodDescription> methodsList) { MethodDescription methodDescription = null; foreach (BaseMethodDescription baseMethodDescription in methodsList) { if (baseMethodDescription.GetFullName().Equals(chosenMethodName)) { methodDescription = methodDescriptionBuilder.Build(parametersLoader, baseMethodDescription, chosenMethodParametersIndex); } } return(methodDescription); }
/// <summary> /// Builds the list of <see cref="FullMethodDescription"/> objects based on the information contained into a <see cref="MethodDescription"/> object. /// </summary> /// <param name="methodDescription">The method description.</param> /// <param name="stepNumber">The step number.</param> /// <returns>A <see cref="List"/> of <see cref="FullMethodDescription"/> object. Each element represent one of the element in the call chain defined by the <see cref="CallBefore"/> attributes. The last one is the main method described by the <paramref name="methodDescription"/> parameter.</returns> public virtual List <FullMethodDescription> Build(MethodDescription methodDescription, uint stepNumber) { List <FullMethodDescription> result = new List <FullMethodDescription>(); if (methodDescription != null) { FullMethodDescription mainFullMethodDescription = this.GetFullMethodDescription(methodDescription.ComponentObject, methodDescription.Method, methodDescription.StepType, methodDescription.Text, methodDescription.Parameters, methodDescription.ParametersIndex, methodDescription.ExecutionOrder, 0, 0, stepNumber, string.Empty, null); this.AddDelayAndTimeoutToMainFullMethodDescription(mainFullMethodDescription); result = this.GetCallBeforeListFullMethodsDescriptions(mainFullMethodDescription, mainFullMethodDescription.ParametersIndex); result.Add(mainFullMethodDescription); } return(result); }
public void GetMethodDescriptionForTheChosenMethod_Should_ReturnTheExpectedMethodDescriptionObject_Given_ADynamicComponentAndTheMethodFullNameAndTheParametersIndexes() { MethodDescriptionBuilder methodDescriptionBuilder = Substitute.For <MethodDescriptionBuilder>(); MethodParametersLoader parametersLoader = Substitute.For <MethodParametersLoader>(); RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent component = UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent>(); ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo firstStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string)); firstStringArrayStorage.SetValue(component, new string[2] { "FirstValue", "SecondValue" }); FieldInfo firstIntArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(int)); firstIntArrayStorage.SetValue(component, new int[2] { 33, 14 }); MethodInfo method = component.GetType().GetMethod("WhenMethod"); string parametersIndex = ";string,RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod.whenStringParam.,stringPVS.Array.data[0];int,RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod.whenIntParam.,intPVS.Array.data[0];"; MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); MethodParameters methodParameters = methodParametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex); parametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex).Returns(methodParameters); BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder(); BaseMethodDescription baseMethodDescription = baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, method); MethodDescriptionBuilder methodDescriptionBuilderInstance = new MethodDescriptionBuilder(); MethodDescription methodDescription = methodDescriptionBuilderInstance.Build(parametersLoader, baseMethodDescription, parametersIndex); methodDescriptionBuilder.Build(parametersLoader, baseMethodDescription, parametersIndex).Returns(methodDescription); string chosenMethodName = "RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod"; string chosenMethodParametersIndex = parametersIndex; List <BaseMethodDescription> methodList = new List <BaseMethodDescription>(); methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("SecondWhenMethod"))); methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("WhenMethod"))); methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("ThirdWhenMethod"))); RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities(); MethodDescription result = methodsUtilities.GetMethodDescriptionForTheChosenMethod(methodDescriptionBuilder, parametersLoader, chosenMethodName, chosenMethodParametersIndex, methodList); Assert.IsTrue(methodDescription.Equals(result), "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.GetMethodDescriptionForTheChosenMethod doesn't return the right object"); }
/// <summary> /// Builds a list of <see cref="FullMethodDescription"/> objects given a list of method full names. /// </summary> /// <typeparam name="T">The type of the Step Method.</typeparam> /// <param name="dynamicBDDComponents">The dynamic BDD components.</param> /// <param name="methodsLoader">The methods loader.</param> /// <param name="methodDescriptionBuilder">The method description builder.</param> /// <param name="methodParametersLoader">The method parameters loader.</param> /// <param name="chosenMethods">The chosen methods.</param> /// <param name="chosenMethodsParametersIndexes">The chosen methods parameters indexes.</param> /// <returns>A list of <see cref="FullMethodDescription"/> objects.</returns> public List <MethodDescription> LoadMethodsDescriptionsFromChosenMethods <T>(Component[] dynamicBDDComponents, MethodsLoader methodsLoader, MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader methodParametersLoader, string[] chosenMethods, string[] chosenMethodsParametersIndexes) where T : IGivenWhenThenDeclaration { List <MethodDescription> methodsDescriptions = new List <MethodDescription>(); List <BaseMethodDescription> baseMethodsDescriptions = methodsLoader.LoadOrderedStepMethods <T>(dynamicBDDComponents, chosenMethods); for (int index = 0; index < baseMethodsDescriptions.Count; index++) { BaseMethodDescription baseMethodDescription = baseMethodsDescriptions[index]; string parametersIndex = chosenMethodsParametersIndexes[index]; MethodDescription methodDescription = methodDescriptionBuilder.Build(methodParametersLoader, baseMethodDescription, parametersIndex); methodsDescriptions.Add(methodDescription); } return(methodsDescriptions); }
public void LoadFullMethodsDescriptions_Should_LoadParametersForTheCallBeforeMethod_When_TheParameterIndexOfTheMainMethodDescriptionIsProperlySet() { // Create the MethodDescription MethodsManagementUtilitiesTestThirdDynamicComponent component = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestThirdDynamicComponent>(); MethodInfo mainMethodInfo = component.GetType().GetMethod("SecondGivenMethod"); MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder(); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); BaseMethodDescription mainBaseMethodDescription = baseMethodDescriptionBuilder.Build <GivenBaseAttribute>(component, mainMethodInfo); string parametersIndex = ";System.String,MethodsManagementUtilitiesUTDynamicCallBeforeParameterLoad.SecondGivenMethod.stringParam.,stringPVS.Array.data[0]" + ";System.String,MethodsManagementUtilitiesUTDynamicCallBeforeParameterLoad.GivenMethod.stringParam.,stringPVS.Array.data[1]"; ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo stringPVS = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string)); string[] stringArray = new string[2] { "FirstElementForTheMainMethod", "SecondElementForTheCallBeforeMethod" }; stringPVS.SetValue(component, stringArray); MethodDescription mainMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, mainBaseMethodDescription, parametersIndex); // Creating the expected FullMethodDescription list MethodInfo callBeforeMethodInfo = component.GetType().GetMethod("GivenMethod"); List <FullMethodDescription> expectedFullMethodDescriptionsList = fullMethodDescriptionBuilder.Build(mainMethodDescription, 1); expectedFullMethodDescriptionsList[0].Parameters = methodParametersLoader.LoadMethodParameters(component, callBeforeMethodInfo, string.Empty, parametersIndex); // Executing LoadFullMethodsDescriptions List <MethodDescription> methodsDescriptionsList = new List <MethodDescription>(); methodsDescriptionsList.Add(mainMethodDescription); MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); List <FullMethodDescription> result = methodsManagementUtilities.LoadFullMethodsDescriptions <GivenBaseAttribute>(methodsDescriptionsList, fullMethodDescriptionBuilder); // Compare the FullMethodDescriptions Assert.AreEqual(2, result.Count, "The method build doesn't return the right number of element in the list"); Assert.AreEqual(expectedFullMethodDescriptionsList[0], result[0], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[1], result[1], "The method build doesn't return the right fullMethodDescription"); }
public void LoadFullMethodsDescriptions_Should_ReturnTheExpectedListOfFullMethodDescriptionObjects_Given_AListOfMethodDescriptionObjectsOfMethodsContainingCallBeforeAttributes() { // Create the MethodDescription MethodsManagementUtilitiesUTDynamicBDDForTestForCallBeforeMethodsList component = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesUTDynamicBDDForTestForCallBeforeMethodsList>(); MethodInfo mainMethodInfo = component.GetType().GetMethod("SecondThenMethod"); MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder(); BaseMethodDescription mainBaseMethodDescription = baseMethodDescriptionBuilder.Build <ThenBaseAttribute>(component, mainMethodInfo); string parametersIndex = string.Empty; MethodDescription firstChosenMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, mainBaseMethodDescription, parametersIndex); // Create the expected FullMethodDescription MethodInfo firstCallBeforeMethodInfo = component.GetType().GetMethod("ThenMethod"); BaseMethodDescription firstCallBeforeBaseMethodDescription = baseMethodDescriptionBuilder.Build <ThenBaseAttribute>(component, firstCallBeforeMethodInfo); MethodDescription secondChosenMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, firstCallBeforeBaseMethodDescription, parametersIndex); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); List <FullMethodDescription> firstChosenFullMethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(firstChosenMethodDescription, 1); List <FullMethodDescription> seconChosenFullMethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(secondChosenMethodDescription, 2); List <FullMethodDescription> expectedFullMethodDescriptionsList = new List <FullMethodDescription>(); expectedFullMethodDescriptionsList.AddRange(firstChosenFullMethodDescriptionsList); expectedFullMethodDescriptionsList.AddRange(seconChosenFullMethodDescriptionsList); // Build the fullMethodDescription List <MethodDescription> methodsDescriptionsList = new List <MethodDescription>(); methodsDescriptionsList.Add(firstChosenMethodDescription); methodsDescriptionsList.Add(secondChosenMethodDescription); MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); List <FullMethodDescription> result = methodsManagementUtilities.LoadFullMethodsDescriptions <ThenBaseAttribute>(methodsDescriptionsList, fullMethodDescriptionBuilder); // Compare the FullMethodDescriptions Assert.AreEqual(6, result.Count, "The method build doesn't return the right number of element in the list"); Assert.AreEqual(expectedFullMethodDescriptionsList[0], result[0], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[1], result[1], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[2], result[2], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[3], result[3], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[4], result[4], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[5], result[5], "The method build doesn't return the right fullMethodDescription"); }
public void Build_Should_ReturnTheExpectedMethodDescriptionObject_Given_ADynamicComponentForAThenMethodWithoutParameters() { MethodDescriptionBuilderTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodDescriptionBuilderTestDynamicComponent>(); MethodInfo methodInfo = component.GetType().GetMethod("ThenMethod"); string parametersIndex = null; MethodDescription expectedMethodDescription = new MethodDescription(); expectedMethodDescription.ComponentObject = component; expectedMethodDescription.Method = methodInfo; expectedMethodDescription.StepType = typeof(ThenBaseAttribute); expectedMethodDescription.Text = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText(); expectedMethodDescription.ExecutionOrder = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder(); ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo arrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string)); arrayStorage.SetValue(component, new string[0]); MethodParameters methodParameters = new MethodParameters(); methodParameters.Parameters = new MethodParameter[0]; 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(ThenBaseAttribute); baseMethodDescription.Text = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText(); baseMethodDescription.ExecutionOrder = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(ThenBaseAttribute), 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"); }
/// <summary> /// Draws the Step Method sentence. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="chosenMethod">The chosen method.</param> /// <param name="methodDescription">The method description.</param> /// <param name="textSize">Size of the text.</param> public void DrawDescription(IUnityInterfaceWrapper unityInterface, string chosenMethod, MethodDescription methodDescription, float textSize) { string description = string.Empty; if (methodDescription != null) { description = methodDescription.GetDecodifiedText(); } else if (chosenMethod.Equals(string.Empty)) { description = ChoseMethodFromComboBox; } else { description = "### The method " + chosenMethod + " is missing ###"; } unityInterface.EditorGUILayoutLabelField(description, textSize); }
/// <summary> /// Checks if there is a missed method and adds it at the end of the combo box list.. /// </summary> /// <param name="chosenMethods">The chosen methods.</param> /// <param name="methodsNames">The methods names.</param> /// <param name="index">The index.</param> /// <param name="methodDescription">The method description.</param> /// <returns>The updated combo box list.</returns> public string[] CheckMissedMethod(ChosenMethods chosenMethods, string[] methodsNames, int index, MethodDescription methodDescription) { if (methodDescription == null) { methodsNames = this.AddMissedMethodNameToMethodsNames(chosenMethods.ChosenMethodsNames[index], methodsNames); } return(methodsNames); }
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"); }
/// <summary> /// Draws the dynamic rows. /// </summary> /// <typeparam name="T">The type of the Step Methods.</typeparam> /// <param name="unityInterface">The unity interface.</param> /// <param name="methodsLoader">The methods loader.</param> /// <param name="methodDescriptionBuilder">The method description builder.</param> /// <param name="parametersLoader">The parameters loader.</param> /// <param name="bddComponents">The BDD components.</param> /// <param name="chosenMethods">The chosen methods.</param> /// <param name="foldouts">The foldouts.</param> /// <param name="serializedObjects">The serialized objects.</param> /// <param name="target">The target.</param> /// <param name="methodsUtilities">The methods utilities.</param> /// <param name="dynamicRowsElements">The dynamic rows elements.</param> /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param> /// <param name="rebuild">If set to <c>true</c> [rebuild].</param> /// <param name="updatedChosenMethodsList">The updated chosen methods list.</param> /// <param name="updatedFoldouts">The updated foldouts.</param> /// <param name="dirtyStatus">If set to <c>true</c> [dirty status].</param> /// <param name="undoText">The undo text.</param> /// <returns>True if a rebuild of the parameters index is requested.</returns> public bool DrawDynamicRows <T>( IUnityInterfaceWrapper unityInterface, MethodsLoader methodsLoader, MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader parametersLoader, Component[] bddComponents, ChosenMethods chosenMethods, bool[] foldouts, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, UnityEngine.Object target, RunnerEditorBusinessLogicMethodsUtilities methodsUtilities, RunnerEditorBusinessLogicDynamicRowsElements dynamicRowsElements, bool lockParametersRows, bool rebuild, out ChosenMethods updatedChosenMethodsList, out bool[] updatedFoldouts, out bool dirtyStatus, out string undoText) where T : IGivenWhenThenDeclaration { updatedChosenMethodsList = (ChosenMethods)chosenMethods.Clone(); updatedFoldouts = new bool[foldouts.Length]; Array.Copy(foldouts, updatedFoldouts, foldouts.Length); undoText = string.Empty; dirtyStatus = false; List <BaseMethodDescription> methodsList = methodsLoader.LoadStepMethods <T>(bddComponents); string[] methodsNames = methodsUtilities.GetMethodsNames(methodsList); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); for (int index = 0; index < chosenMethods.ChosenMethodsNames.Length; index++) { MethodDescription methodDescription = methodsUtilities.GetMethodDescription(methodDescriptionBuilder, parametersLoader, chosenMethods, methodsList, index); methodsNames = methodsUtilities.CheckMissedMethod(chosenMethods, methodsNames, index, methodDescription); List <FullMethodDescription> fullMethodDescriptionsList = fullMethodDescriptionBuilder.Build(methodDescription, (uint)index + 1); unityInterface.EditorGUILayoutBeginHorizontal(); dynamicRowsElements.DrawFoldoutSymbol(unityInterface, updatedFoldouts, index, fullMethodDescriptionsList); dynamicRowsElements.DrawLabel <T>(unityInterface, index); float textSize = (unityInterface.EditorGUIUtilityCurrentViewWidth() - RunnerEditorBusinessLogicData.LabelWidthAbsolute - RunnerEditorBusinessLogicData.ButtonsWidthAbsolute) * RunnerEditorBusinessLogicData.TextWidthPercent; dynamicRowsElements.DrawDescription(unityInterface, chosenMethods.ChosenMethodsNames[index], methodDescription, textSize); string newChosenMethod = dynamicRowsElements.DrawComboBox(unityInterface, chosenMethods.ChosenMethodsNames[index], methodsNames); rebuild = methodsUtilities.UpdateDataIfNewMethodIsChosen(newChosenMethod, updatedChosenMethodsList, updatedFoldouts, index, rebuild, out undoText); dirtyStatus = dirtyStatus || dynamicRowsElements.DrawAddRowButton(unityInterface, index, updatedChosenMethodsList, target, undoText, out updatedChosenMethodsList, out undoText); dirtyStatus = dirtyStatus || dynamicRowsElements.DrawRemoveRowButton(unityInterface, index, updatedChosenMethodsList, target, undoText, out updatedChosenMethodsList, out undoText); if (dirtyStatus) { break; } dynamicRowsElements.DrawCogButton(unityInterface, methodDescription, (BDDExtensionRunner)target); unityInterface.EditorGUILayoutEndHorizontal(); dynamicRowsElements.DrawParametersRows(unityInterface, foldouts[index], fullMethodDescriptionsList, serializedObjects, lockParametersRows); } return(rebuild); }