Пример #1
0
        public void Filter_Should_ReturnTrue_Given_ADynamicComponentForAGivenMethodFilteringGivenMethods()
        {
            MethodsFilterByStepTypeTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodsFilterByStepTypeTestDynamicComponent>();
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");
            MethodsFilterByStepType methodsFilterByStepType = new MethodsFilterByStepType();
            bool result = methodsFilterByStepType.Filter <GivenBaseAttribute>(methodInfo);

            Assert.AreEqual(true, result, "The method MethodsFilterByStepType.Filter does not return the right answer");
        }
        public void LoadStepMethods_Should_ReturnAnEmptyListOfBaseMethodDescriptionObjects_GivenADynamicComponentWithoutWhenMethodsLoadingWhenMethods()
        {
            Component[] components = new Component[1] {
                UnitTestUtility.CreateComponent <MethodsLoaderTestDynamicComponent>()
            };
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader   = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> methods = bddStepMethodsLoader.LoadStepMethods <WhenBaseAttribute>(components);

            Assert.AreEqual(0, methods.Count, "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected amount of elements");
        }
        public void LoadStepMethods_Should_ReturnAnEmptyList_Given_AStaticComponentWithARepetedExecutionOrderValue()
        {
            Component[] components = new Component[1] {
                UnitTestUtility.CreateComponent <MethodsLoaderTestThirdStaticComponent>()
            };

            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader  = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> result = bddStepMethodsLoader.LoadStepMethods <GivenBaseAttribute>(components);

            Assert.AreEqual(0, result.Count, "The method LoadStepMethods does not return the right list.");
        }
        public void LoadStepMethods_Should_ReturnTheExpectedListOfBaseMethodDescriptionObjects_Given_ADynamicComponentWithTwoThenMethodsLoadingThenMethods()
        {
            Component[] components = new Component[1] {
                UnitTestUtility.CreateComponent <MethodsLoaderTestDynamicComponent>()
            };
            BaseMethodDescription expectedMethod1 = new BaseMethodDescription();

            expectedMethod1.ComponentObject = components[0];
            expectedMethod1.Method          = components[0].GetType().GetMethod("ThenMethod");
            expectedMethod1.StepType        = typeof(ThenBaseAttribute);
            expectedMethod1.Text            = ((IGivenWhenThenDeclaration)expectedMethod1.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethod1.ExecutionOrder  = ((IGivenWhenThenDeclaration)expectedMethod1.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder();

            BaseMethodDescription expectedMethod2 = new BaseMethodDescription();

            expectedMethod2.ComponentObject = components[0];
            expectedMethod2.Method          = components[0].GetType().GetMethod("SecondThenMethod");
            expectedMethod2.StepType        = typeof(ThenBaseAttribute);
            expectedMethod2.Text            = ((IGivenWhenThenDeclaration)expectedMethod2.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethod2.ExecutionOrder  = ((IGivenWhenThenDeclaration)expectedMethod2.Method.GetCustomAttributes(typeof(ThenBaseAttribute), true)[0]).GetExecutionOrder();

            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader   = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> methods = bddStepMethodsLoader.LoadStepMethods <ThenBaseAttribute>(components);

            Assert.AreEqual(2, methods.Count, "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected amount of elements");
            BaseMethodDescription returnedMethod1 = null;
            BaseMethodDescription returnedMethod2 = null;

            if (methods[0].Method.Name.Equals(expectedMethod1.Method.Name))
            {
                returnedMethod1 = methods[0];
                returnedMethod2 = methods[1];
            }
            else
            {
                returnedMethod1 = methods[1];
                returnedMethod2 = methods[2];
            }

            Assert.IsTrue(expectedMethod1.Equals(returnedMethod1), "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected Method Object");
            Assert.IsTrue(expectedMethod2.Equals(returnedMethod2), "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected Method Object");
        }
Пример #5
0
        /// <summary>
        /// Builds the dynamic scenario.
        /// </summary>
        /// <param name="script">The script.</param>
        /// <param name="bddComponents">The BDD components.</param>
        /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param>
        /// <param name="dirtyStatus">If set to <c>true</c> [dirty status].</param>
        private void BuildDynamicScenario(BDDExtensionRunner script, Component[] bddComponents, bool lockParametersRows, out bool dirtyStatus)
        {
            bool   givenDirtyStatus = false;
            bool   whenDirtyStatus  = false;
            bool   thenDirtyStatus  = false;
            string undoText;
            MethodParametersLoader parametersLoader = new MethodParametersLoader();
            RunnerEditorBusinessLogicMethodsUtilities    methodsUtilities    = new RunnerEditorBusinessLogicMethodsUtilities();
            RunnerEditorBusinessLogicDynamicRowsElements dynamicRowsElements = new RunnerEditorBusinessLogicDynamicRowsElements();
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder        = new BaseMethodDescriptionBuilder();
            MethodDescriptionBuilder     methodDescriptionBuilder            = new MethodDescriptionBuilder();
            IMethodsFilter methodFilter  = new MethodsFilterByStepType();
            MethodsLoader  methodsLoader = new MethodsLoader(baseMethodDescriptionBuilder, methodFilter);

            ChosenMethods chosenMethods = new ChosenMethods();

            chosenMethods.ChosenMethodsNames           = script.Given;
            chosenMethods.ChosenMethodsParametersIndex = script.GivenParametersIndex;

            this.runnerBusinessLogicData.Rebuild = this.businessLogicDynamicRows.DrawDynamicRows <GivenBaseAttribute>(this.unityIntefaceWrapper, methodsLoader, methodDescriptionBuilder, parametersLoader, bddComponents, chosenMethods, this.runnerBusinessLogicData.GivenFoldouts, this.runnerBusinessLogicData.SerializedObjects, script, methodsUtilities, dynamicRowsElements, lockParametersRows, this.runnerBusinessLogicData.Rebuild, out chosenMethods, out this.runnerBusinessLogicData.GivenFoldouts, out givenDirtyStatus, out undoText);
            this.RegisterUndoInformation(this.target, bddComponents, undoText);
            script.Given = chosenMethods.ChosenMethodsNames;
            script.GivenParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            chosenMethods.ChosenMethodsNames           = script.When;
            chosenMethods.ChosenMethodsParametersIndex = script.WhenParametersIndex;

            this.runnerBusinessLogicData.Rebuild = this.businessLogicDynamicRows.DrawDynamicRows <WhenBaseAttribute>(this.unityIntefaceWrapper, methodsLoader, methodDescriptionBuilder, parametersLoader, bddComponents, chosenMethods, this.runnerBusinessLogicData.WhenFoldouts, this.runnerBusinessLogicData.SerializedObjects, script, methodsUtilities, dynamicRowsElements, lockParametersRows, this.runnerBusinessLogicData.Rebuild, out chosenMethods, out this.runnerBusinessLogicData.WhenFoldouts, out whenDirtyStatus, out undoText);
            this.RegisterUndoInformation(this.target, bddComponents, undoText);

            script.When = chosenMethods.ChosenMethodsNames;
            script.WhenParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            chosenMethods.ChosenMethodsNames           = script.Then;
            chosenMethods.ChosenMethodsParametersIndex = script.ThenParametersIndex;
            this.runnerBusinessLogicData.Rebuild       = this.businessLogicDynamicRows.DrawDynamicRows <ThenBaseAttribute>(this.unityIntefaceWrapper, methodsLoader, methodDescriptionBuilder, parametersLoader, bddComponents, chosenMethods, this.runnerBusinessLogicData.ThenFoldouts, this.runnerBusinessLogicData.SerializedObjects, script, methodsUtilities, dynamicRowsElements, lockParametersRows, this.runnerBusinessLogicData.Rebuild, out chosenMethods, out this.runnerBusinessLogicData.ThenFoldouts, out thenDirtyStatus, out undoText);
            this.RegisterUndoInformation(this.target, bddComponents, undoText);

            script.Then = chosenMethods.ChosenMethodsNames;
            script.ThenParametersIndex = chosenMethods.ChosenMethodsParametersIndex;

            dirtyStatus = givenDirtyStatus || whenDirtyStatus || thenDirtyStatus;
        }
Пример #6
0
        public void GetMethodsNames_Should_ReturnTheExpectedArrayOfStringsContainingTheFullNamesOfTheMethods_Given_ALIstOfBaseMethodDescriptionObjects()
        {
            string[]    expectedResult = new string[3];
            Component[] components     = new Component[1] {
                UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent>()
            };
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader       = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> methodsList = bddStepMethodsLoader.LoadStepMethods <WhenBaseAttribute>(components);

            expectedResult[0] = methodsList[0].GetFullName();
            expectedResult[1] = methodsList[1].GetFullName();
            expectedResult[2] = methodsList[2].GetFullName();
            RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities();

            string[] result = methodsUtilities.GetMethodsNames(methodsList);
            Assert.AreEqual(expectedResult, result, "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.GetMethodsNames doesn't return the right list of methods names.");
        }
        public void LoadStepMethods_Should_ReturnTheExpectedListOfBaseMethodDescriptionObjects_Given_ADynamicComponentLoadingGivenMethods()
        {
            Component[] components = new Component[1] {
                UnitTestUtility.CreateComponent <MethodsLoaderTestDynamicComponent>()
            };
            BaseMethodDescription expectedMethod = new BaseMethodDescription();

            expectedMethod.ComponentObject = components[0];
            expectedMethod.Method          = components[0].GetType().GetMethod("GivenMethod");
            expectedMethod.StepType        = typeof(GivenBaseAttribute);
            expectedMethod.Text            = ((IGivenWhenThenDeclaration)expectedMethod.Method.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedMethod.ExecutionOrder  = ((IGivenWhenThenDeclaration)expectedMethod.Method.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetExecutionOrder();
            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            MethodsFilterByStepType      methodsFilterByStepType      = new MethodsFilterByStepType();
            MethodsLoader bddStepMethodsLoader   = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByStepType);
            List <BaseMethodDescription> methods = bddStepMethodsLoader.LoadStepMethods <GivenBaseAttribute>(components);

            Assert.AreEqual(1, methods.Count, "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected amount of elements");
            Assert.IsTrue(expectedMethod.Equals(methods[0]), "The BDDStepMethodsFilter.FilterAllStepMethods method doesn't return the expected Method Object");
        }