/// <summary> /// Gets the <see cref="FullMethodDescription"/> for the method declared by the <see cref="CallBefore"/> attribute. /// </summary> /// <param name="callBefore">The call before.</param> /// <param name="mainMethod">The main method.</param> /// <param name="parametersIndex">Index of the parameters.</param> /// <returns>The <see cref="FullMethodDescription"/> for the method declared by the <see cref="CallBefore"/> attribute.</returns> private FullMethodDescription GetCallBeforeFullMethodDescription(CallBefore callBefore, FullMethodDescription mainMethod, string parametersIndex) { MethodInfo methodInfo = mainMethod.ComponentObject.GetType().GetMethod(callBefore.Method); MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); string fullId = methodsManagementUtilities.GetMainFullId(mainMethod) + callBefore.Id; MethodParameters methodParameters = methodParametersLoader.LoadMethodParameters(mainMethod.ComponentObject, methodInfo, fullId, parametersIndex); FullMethodDescription result = this.GetFullMethodDescription(mainMethod.ComponentObject, methodInfo, mainMethod.StepType, mainMethod.Text, methodParameters, string.Empty, 0, callBefore.Delay, callBefore.Timeout, callBefore.ExecutionOrder, callBefore.Id, mainMethod); 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"); }
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 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"); }
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."); }