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");
        }
Пример #2
0
        /// <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);
        }