public void ResetAllArrayStorage_Should_ResetAllParametersValuesStorageArraysInsideTheDynamicComponentsInTheList() { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); ArrayStorageUtilitiesTestFirstDynamicComponent firstDynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestFirstDynamicComponent>(); FieldInfo firstStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(firstDynamicBDDComponent, typeof(string)); string[] stringArray = new string[1] { "FirstElement" }; firstStringArrayStorage.SetValue(firstDynamicBDDComponent, stringArray); Array previousStringArray = firstStringArrayStorage.GetValue(firstDynamicBDDComponent) as Array; Assert.AreEqual(1, previousStringArray.Length, "Test setup does not work properly"); FieldInfo firstIntArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(firstDynamicBDDComponent, typeof(int)); int[] intArray = new int[1] { 123 }; firstIntArrayStorage.SetValue(firstDynamicBDDComponent, intArray); Array previousintArray = firstIntArrayStorage.GetValue(firstDynamicBDDComponent) as Array; Assert.AreEqual(1, previousintArray.Length, "Test setup does not work properly"); ArrayStorageUtilitiesTestFirstDynamicComponent secondDynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestFirstDynamicComponent>(); FieldInfo secondStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(secondDynamicBDDComponent, typeof(string)); stringArray = new string[1] { "FirstElement" }; secondStringArrayStorage.SetValue(secondDynamicBDDComponent, stringArray); previousStringArray = secondStringArrayStorage.GetValue(secondDynamicBDDComponent) as Array; Assert.AreEqual(1, previousStringArray.Length, "Test setup does not work properly"); FieldInfo secondIntArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(secondDynamicBDDComponent, typeof(int)); intArray = new int[1] { 123 }; secondIntArrayStorage.SetValue(secondDynamicBDDComponent, intArray); previousintArray = secondIntArrayStorage.GetValue(secondDynamicBDDComponent) as Array; Assert.AreEqual(1, previousintArray.Length, "Test setup does not work properly"); Component[] components = new Component[2] { firstDynamicBDDComponent, secondDynamicBDDComponent }; arrayStorageUtilities.ResetAllArrayStorage(components); Array currentFirstStringArrayStorageValue = firstStringArrayStorage.GetValue(firstDynamicBDDComponent) as Array; Array currentFirstIntArrayStorageValue = firstIntArrayStorage.GetValue(firstDynamicBDDComponent) as Array; Array currentSecondStringArrayStorageValue = secondStringArrayStorage.GetValue(secondDynamicBDDComponent) as Array; Array currentSecondIntArrayStorageValue = secondStringArrayStorage.GetValue(secondDynamicBDDComponent) as Array; Assert.AreEqual(0, currentFirstStringArrayStorageValue.Length, "The method ResetArrayStorage doesn't reset the array storage properly"); Assert.AreEqual(0, currentFirstIntArrayStorageValue.Length, "The method ResetArrayStorage doesn't reset the array storage properly"); Assert.AreEqual(0, currentSecondStringArrayStorageValue.Length, "The method ResetArrayStorage doesn't reset the array storage properly"); Assert.AreEqual(0, currentSecondIntArrayStorageValue.Length, "The method ResetArrayStorage doesn't reset the array storage properly"); }
/// <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); }
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"); }
public void GetArrayStorageFieldInfoByType_Should_ReturnNull_Given_ADynamicComponentPassingANotPresentType() { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); ArrayStorageUtilitiesTestFirstDynamicComponent dynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestFirstDynamicComponent>(); FieldInfo arrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(dynamicBDDComponent, typeof(Button)); Assert.IsNull(arrayStorage, "The method GetArrayStorage doesn't return the right ArrayStorage"); }
private FieldInfo SetPVSAndReturnFieldInfo(object component, Type pvsType, object value) { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo pvs = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, pvsType); pvs.SetValue(component, value); return(pvs); }
public void GetArrayStorageFieldInfoByName_Should_ReturnNull_Given_ADynamicComponentAndANameOfAParametersValuesStorageArrayThatIsNotPresentInTheComponent() { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); ArrayStorageUtilitiesTestFirstDynamicComponent dynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestFirstDynamicComponent>(); string fieldName = "stringPVSForNotFound"; FieldInfo arrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByName(dynamicBDDComponent, fieldName); Assert.IsNull(arrayStorage, "The method GetArrayStorage doesn't return the right ArrayStorage"); }
public void GetArrayStorageFieldInfoByType_Should_ReturnTheExpectedParametersValuesStorageFieldInfoObject_Given_ADynamicComponentPassingStringType() { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); ArrayStorageUtilitiesTestFirstDynamicComponent dynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestFirstDynamicComponent>(); FieldInfo arrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(dynamicBDDComponent, typeof(string)); string fieldName = "stringPVS"; FieldInfo expectedArrayStorage = dynamicBDDComponent.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); Assert.That(expectedArrayStorage.Name.Equals(arrayStorage.Name), "The method GetArrayStorage doesn't return the right ArrayStorage"); Assert.That(expectedArrayStorage.FieldType.Equals(arrayStorage.FieldType), "The method GetArrayStorage doesn't return the right ArrayStorage"); Assert.That(expectedArrayStorage.DeclaringType.Equals(arrayStorage.DeclaringType), "The method GetArrayStorage doesn't return the right ArrayStorage"); }
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> /// Rebuilds the parameters. /// </summary> /// <param name="script">The script.</param> /// <param name="dynamicBDDComponents">The dynamic BDD components.</param> /// <param name="runnerBusinessLogicData">The runner business logic data.</param> private void RebuildParameters(BDDExtensionRunner script, Component[] dynamicBDDComponents, RunnerEditorBusinessLogicData runnerBusinessLogicData) { // Generate the three list of MethodDescription for each step type: Given, When, Then MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); BaseMethodDescriptionBuilder methodBuilder = new BaseMethodDescriptionBuilder(); IMethodsFilter givenMethodFilter = new MethodsFilterByMethodsFullNameList(script.Given); MethodsLoader givenMethodsLoader = new MethodsLoader(methodBuilder, givenMethodFilter); MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); MethodParametersLoader methodsParametersLoader = new MethodParametersLoader(); List <MethodDescription> givenMethodsDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <GivenBaseAttribute>(dynamicBDDComponents, givenMethodsLoader, methodDescriptionBuilder, methodsParametersLoader, script.Given, script.GivenParametersIndex); List <FullMethodDescription> givenFullMethodsDescriptionList = methodsManagementUtilities.LoadFullMethodsDescriptions <GivenBaseAttribute>(givenMethodsDescriptionList, fullMethodDescriptionBuilder); IMethodsFilter whenMethodFilter = new MethodsFilterByMethodsFullNameList(script.When); MethodsLoader whenMethodsLoader = new MethodsLoader(methodBuilder, whenMethodFilter); List <MethodDescription> whenMethodsDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <WhenBaseAttribute>(dynamicBDDComponents, whenMethodsLoader, methodDescriptionBuilder, methodsParametersLoader, script.When, script.WhenParametersIndex); List <FullMethodDescription> whenFullMethodsDescriptionList = methodsManagementUtilities.LoadFullMethodsDescriptions <WhenBaseAttribute>(whenMethodsDescriptionList, fullMethodDescriptionBuilder); IMethodsFilter thenMethodFilter = new MethodsFilterByMethodsFullNameList(script.Then); MethodsLoader thenMethodsLoader = new MethodsLoader(methodBuilder, thenMethodFilter); List <MethodDescription> thenMethodsDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <ThenBaseAttribute>(dynamicBDDComponents, thenMethodsLoader, methodDescriptionBuilder, methodsParametersLoader, script.Then, script.ThenParametersIndex); List <FullMethodDescription> thenFullMethodsDescriptionList = methodsManagementUtilities.LoadFullMethodsDescriptions <ThenBaseAttribute>(thenMethodsDescriptionList, fullMethodDescriptionBuilder); // Reset the valuesArrayStorages for each component ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); arrayStorageUtilities.ResetAllArrayStorage(dynamicBDDComponents); // Rebuild the parameters indexes and locations for each list of MethodDescription RunnerEditorBusinessLogicParametersLocationsBuilder parametersLocationsBuilder = new RunnerEditorBusinessLogicParametersLocationsBuilder(); parametersLocationsBuilder.BuildParametersLocation(givenFullMethodsDescriptionList); parametersLocationsBuilder.BuildParametersLocation(whenFullMethodsDescriptionList); parametersLocationsBuilder.BuildParametersLocation(thenFullMethodsDescriptionList); // Rebuild the parameters Indexes arrays script.GivenParametersIndex = parametersLocationsBuilder.RebuildParametersIndexesArrays(givenFullMethodsDescriptionList, script.Given); script.WhenParametersIndex = parametersLocationsBuilder.RebuildParametersIndexesArrays(whenFullMethodsDescriptionList, script.When); script.ThenParametersIndex = parametersLocationsBuilder.RebuildParametersIndexesArrays(thenFullMethodsDescriptionList, script.Then); }
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 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 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."); }
/// <summary> /// Gets the value of the parameter from its ParametersValuesStorage field. /// </summary> /// <param name="obj">The object.</param> /// <param name="arrayName">Name of the array.</param> /// <param name="index">The index.</param> /// <returns>The value of the parameter.</returns> private static object GetValue(object obj, string arrayName, int index) { object result = null; ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo field = arrayStorageUtilities.GetArrayStorageFieldInfoByName(obj, arrayName); if (field == null) { return(null); } Array array = field.GetValue(obj) as Array; if (array.Length > index) { result = array.GetValue(index); } return(result); }
public void ResetArrayStorage_Should_ResetTheParametersValuesStorageArray_Given_ADynamicComponentAndTheFieldInfoObjectOfTheParametersValuesStorageArray() { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); ArrayStorageUtilitiesTestFirstDynamicComponent dynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestFirstDynamicComponent>(); FieldInfo stringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(dynamicBDDComponent, typeof(string)); string[] stringArray = new string[1] { "FirstElement" }; stringArrayStorage.SetValue(dynamicBDDComponent, stringArray); Array previousStringArray = stringArrayStorage.GetValue(dynamicBDDComponent) as Array; Assert.AreEqual(1, previousStringArray.Length, "The method ResetArrayStorage doesn't reset the array storage properly"); arrayStorageUtilities.ResetArrayStorage(stringArrayStorage, dynamicBDDComponent); Array currentValue = stringArrayStorage.GetValue(dynamicBDDComponent) as Array; Assert.AreEqual(0, currentValue.Length, "The method ResetArrayStorage doesn't reset the array storage properly"); }
public void CheckForNotMatchingPVS_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndADynamicComponentWithTheCorrespondingParametersValuesStorages() { Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>(); Component[] components = new Component[1] { component }; ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo stringPVS = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string)); Array array = new string[1]; stringPVS.SetValue(component, array); string[] chosenMethods = new string[1] { "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod" }; string[] parametersIndexes = new string[1] { ";System.String,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParamWrongName.,stringPVS.Array.data[0];" }; ChosenMethodsChecker checkForErrors = new ChosenMethodsChecker(); List <UnityTestBDDError> result = checkForErrors.CheckForNotMatchingPVS <GivenBaseAttribute>(chosenMethods, parametersIndexes, components); Assert.AreEqual(0, result.Count, "The method CheckForNotMatchingPVS doesn't check properly"); }
/// <summary> /// Builds the parameters location. /// </summary> /// <param name="fullMethodsDescriptionsList">The full methods descriptions list.</param> internal void BuildParametersLocation(List <FullMethodDescription> fullMethodsDescriptionsList) { foreach (FullMethodDescription fullMethodDescription in fullMethodsDescriptionsList) { fullMethodDescription.ParametersIndex = string.Empty; } ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); foreach (FullMethodDescription fullMethodDescription in fullMethodsDescriptionsList) { if (fullMethodDescription != null) { string parametersIndex = string.Empty; foreach (MethodParameter methodParameter in fullMethodDescription.Parameters.Parameters) { FieldInfo arrayStorageFieldInfo = arrayStorageUtilities.GetArrayStorageFieldInfoByType(fullMethodDescription.ComponentObject, methodParameter.ParameterInfoObject.ParameterType); Array array = arrayStorageFieldInfo.GetValue(fullMethodDescription.ComponentObject) as Array; int oldArrayLength = array.Length; int newArrayLength = oldArrayLength + 1; Array newArray = Array.CreateInstance(methodParameter.ParameterInfoObject.ParameterType, newArrayLength); if (array.Length > 0) { array.CopyTo(newArray, 0); } int index = newArray.Length - 1; newArray.SetValue(methodParameter.Value, index); arrayStorageFieldInfo.SetValue(fullMethodDescription.ComponentObject, newArray); parametersIndex += ";" + this.BuildParameterIndex(fullMethodDescription, methodParameter, index, arrayStorageFieldInfo); } this.AddParametersIndex(fullMethodDescription, parametersIndex); } } }
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."); }
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 GetArrayStorageFieldInfoByType_Should_ReturnTheCorrespondingParametersValuesStorageFieldInfoObjectForAllThePlannedSuppoertedTypes() { ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); ArrayStorageUtilitiesTestSecondDynamicComponent dynamicBDDComponent = UnitTestUtility.CreateComponent <ArrayStorageUtilitiesTestSecondDynamicComponent>(); Type[] typesToTest = new Type[43] { typeof(bool), typeof(byte), typeof(sbyte), typeof(char), typeof(decimal), typeof(double), typeof(float), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(short), typeof(ushort), typeof(string), typeof(Boolean), typeof(Byte), typeof(SByte), typeof(Char), typeof(Decimal), typeof(Double), typeof(Int16), typeof(Int32), typeof(Int64), typeof(UInt16), typeof(UInt32), typeof(UInt64), typeof(String), typeof(Vector2), typeof(Vector3), typeof(Vector4), typeof(Rect), typeof(Quaternion), typeof(Matrix4x4), typeof(Color), typeof(Color32), typeof(LayerMask), typeof(AnimationCurve), typeof(Gradient), typeof(RectOffset), typeof(GUIStyle), typeof(GameObject), typeof(Transform), typeof(Component) }; for (int index = 0; index < typesToTest.Length; index++) { Assert.IsNotNull(arrayStorageUtilities.GetArrayStorageFieldInfoByType(dynamicBDDComponent, typesToTest[index]), "The GetArrayStorageFieldInfo can't locate the ParametersValuesStorage array of type " + typesToTest[index].Name); Type fieldType = arrayStorageUtilities.GetArrayStorageFieldInfoByType(dynamicBDDComponent, typesToTest[index]).FieldType.GetElementType(); Assert.That(typesToTest[index].Equals(fieldType), "The GetArrayStorageFieldInfo returns the wrong ParametersValuesStorage array of type " + typesToTest[index].Name); } }