예제 #1
0
        public void CheckForNotMatchingParametersIndex_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndTheDynamicComponentWithTheCorrespondingMethodsButWithAParameterWithDifferentType()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");

            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndexes = new string[1] {
                ";System.Int32,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam.,intPVS.Array.data[0];"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForNotMatchingParametersIndex <GivenBaseAttribute>(chosenMethods, parametersIndexes, components);
            string expectedMessage = "The parameter ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam has a wrong type in Given methods at position 1.\n Previous type: System.Int32\n Current type System.String";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForNotMatchingParametersIndex doesn't resturn the right message");
            Assert.That(component.Equals(result[0].Component), "The method CheckForNotMatchingParametersIndex doesn't resturn the right Component");
            Assert.That(methodInfo.Equals(result[0].MethodMethodInfo), "The method CheckForNotMatchingParametersIndex doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(GivenBaseAttribute), result[0].StepType, "The method CheckForNotMatchingParametersIndex doesn't resturn the right StepType");
            Assert.AreEqual(0, result[0].Index, "The method CheckForNotMatchingParametersIndex doesn't resturn the right method index");
        }
        public void RunCycle_ShouldPerFormTheExpectedCalls_Given_ItIsInvokedAfterTheLastMethodInTheList()
        {
            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);

            ExtensionRunnerBusinessLogicTestFirstStaticComponent component = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestFirstStaticComponent>();

            Component[] components = new Component[1] {
                component
            };

            List <FullMethodDescription> methodsDescription = businessLogic.GetAllMethodsDescriptions(components, null, null, null, null, null, null);

            ExtensionRunnerBusinessLogic mockedBusinessLogic = Substitute.For <ExtensionRunnerBusinessLogic>(gameObject);

            mockedBusinessLogic.InvokeMethod(businessLogic, methodsDescription[0], gameObject).Returns <bool>(true);

            int indexToRun = 8;

            businessLogic.RunCycle(mockedBusinessLogic, methodsDescription, indexToRun);
            Received.InOrder(() =>
            {
                businessLogic.InvokeAssertionSuccessful(gameObject);
            });
        }
예제 #3
0
        public void CheckForNotMatchingPVS_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndADynamicComponentWithoutACorrespondingParametersValuesStorages()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");

            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndexes = new string[1] {
                ";System.String,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam.,otherPVS.Array.data[0];"
            };
            ChosenMethodsChecker checkForErrors = new ChosenMethodsChecker();

            List <UnityTestBDDError> result = checkForErrors.CheckForNotMatchingPVS <GivenBaseAttribute>(chosenMethods, parametersIndexes, components);

            string expectedMessage = "The ParametersValuesStorage field otherPVS for the parameter ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam. is not found in Given methods at position 1";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForNotMatchingPVS doesn't resturn the right message");
            Assert.That(component.Equals(result[0].Component), "The method CheckForNotMatchingPVS doesn't resturn the right Component");
            Assert.That(methodInfo.Equals(result[0].MethodMethodInfo), "The method CheckForNotMatchingPVS doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(GivenBaseAttribute), result[0].StepType, "The method CheckForNotMatchingPVS doesn't resturn the right StepType");
            Assert.AreEqual(0, result[0].Index, "The method CheckForNotMatchingPVS doesn't resturn the right method index");
        }
        public void GetAllMethodsDescriptions_Should_ReturnTheExpectedListOfFullMethodDescriptionObjects_Given_AStaticComponentWithNestedCallBeforeAttributes()
        {
            ExtensionRunnerBusinessLogicTestFirstStaticComponent component = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestFirstStaticComponent>();

            Component[] components = new Component[1] {
                component
            };

            GameObject gameObject = UnitTestUtility.CreateGameObject();

            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);
            List <FullMethodDescription> resultList    = businessLogic.GetAllMethodsDescriptions(components, null, null, null, null, null, null);

            string expecetdMethod1 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.GivenMethod";
            string expecetdMethod5 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.WhenMethod";

            string expecetdMethod6 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.SecondGivenMethod";
            string expecetdMethod7 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.ThenMethod";
            string expecetdMethod8 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.SecondGivenMethod";
            string expecetdMethod9 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.SecondThenMethod";

            string expecetdMethod10 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.SecondGivenMethod";
            string expecetdMethod11 = "ExtensionRunnerBusinessLogicTestFirstStaticComponent.ThenMethod";

            Assert.AreEqual(8, resultList.Count, "The method GetAllMethodsDescriptions doesn't return the right number of methods.");
            Assert.AreEqual(expecetdMethod1, resultList[0].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod5, resultList[1].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod6, resultList[2].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod7, resultList[3].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod8, resultList[4].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod9, resultList[5].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod10, resultList[6].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
            Assert.AreEqual(expecetdMethod11, resultList[7].GetFullName(), "The method GetAllMethodsDescriptions doesn't return the right methods order.");
        }
예제 #5
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");
        }
예제 #6
0
        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");
        }
        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 Filter_Should_ReturnTrue_Given_AStaticComponentForAGenericMethodFilteringWhenMethods()
        {
            MethodsFilterByExecutionOrderTestStaticComponent component = UnitTestUtility.CreateComponent <MethodsFilterByExecutionOrderTestStaticComponent>();
            MethodInfo methodInfo = component.GetType().GetMethod("SecondWhenMethod");

            MethodsFilterByExecutionOrder methodsFilterByExecutionOrder = new MethodsFilterByExecutionOrder();
            bool result = methodsFilterByExecutionOrder.Filter <WhenBaseAttribute>(methodInfo);

            Assert.AreEqual(false, 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 Filter_Should_ReturnOnlyTheDynamicComponent_Given_TwoObjectsWithTheFirstAsDynamicComponentsAndTheSecondAsANormalMonoBehaviourClass()
        {
            Component[] classes = new Component[2];
            classes[0] = UnitTestUtility.CreateComponent <ComponentsFilterTestFirstDynamicComponent>();
            classes[1] = UnitTestUtility.CreateComponent <ComponentsFilterTestMonoBehaviourClass>();
            ComponentsFilter bddComponentsFilter = new ComponentsFilter();

            Component[] filteredClasses = bddComponentsFilter.Filter(classes);

            Assert.AreEqual(1, filteredClasses.Length, "The BddComponentsFilter doesn't return the right number of classes");
            Assert.IsTrue(typeof(ComponentsFilterTestFirstDynamicComponent).Equals(filteredClasses[0].GetType()), "The BddComponentsFilter doesn't return the right class");
        }
        public void DrawStaticRows_Should_CallTheRightUnityEditoStatements_Given_AStaticComponentWithTwoWhenMethods()
        {
            Component[] bddComponents = new Component[1] {
                UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicStaticRowsTestStaticComponent>()
            };

            IUnityInterfaceWrapper unityInterface = Substitute.For <IUnityInterfaceWrapper>();

            unityInterface.EditorGUIUtilityCurrentViewWidth().Returns <float>(500F);

            BaseMethodDescriptionBuilder methodBuilder = Substitute.For <BaseMethodDescriptionBuilder>();

            BaseMethodDescriptionBuilder  baseMethodDescriptionBuilder  = new BaseMethodDescriptionBuilder();
            MethodsFilterByExecutionOrder methodsFilterByExecutionOrder = new MethodsFilterByExecutionOrder();
            MethodsLoader bddStepMethodsLoader = new MethodsLoader(baseMethodDescriptionBuilder, methodsFilterByExecutionOrder);
            List <BaseMethodDescription> baseMethodDescriptionList = bddStepMethodsLoader.LoadStepMethods <WhenBaseAttribute>(bddComponents);
            MethodInfo whenMethodInfo       = typeof(RunnerEditorBusinessLogicStaticRowsTestStaticComponent).GetMethod("WhenMethod");
            MethodInfo secondWhenMethodInfo = typeof(RunnerEditorBusinessLogicStaticRowsTestStaticComponent).GetMethod("SecondWhenMethod");

            methodBuilder.Build <WhenBaseAttribute>(bddComponents[0], whenMethodInfo).Returns <BaseMethodDescription>(baseMethodDescriptionList[0]);

            methodBuilder.Build <WhenBaseAttribute>(bddComponents[0], secondWhenMethodInfo).Returns <BaseMethodDescription>(baseMethodDescriptionList[1]);

            IMethodsFilter methodFilter = Substitute.For <IMethodsFilter>();

            methodFilter.Filter <WhenBaseAttribute>(whenMethodInfo).Returns(true);
            methodFilter.Filter <WhenBaseAttribute>(secondWhenMethodInfo).Returns(true);

            object[] constructorArguments = new object[2] {
                new BaseMethodDescriptionBuilder(), new MethodsFilterByExecutionOrder()
            };
            MethodsLoader stepMethodsLoader = Substitute.For <MethodsLoader>(constructorArguments);

            stepMethodsLoader.LoadStepMethods <WhenBaseAttribute>(bddComponents).Returns(baseMethodDescriptionList);
            RunnerEditorBusinessLogicStaticRows runnerEditorBusinessLogicStaticRows = new RunnerEditorBusinessLogicStaticRows();

            runnerEditorBusinessLogicStaticRows.DrawStaticRows <WhenBaseAttribute>(unityInterface, stepMethodsLoader, bddComponents, RunnerEditorBusinessLogicData.LabelWidthAbsolute, RunnerEditorBusinessLogicData.ButtonsWidthAbsolute);
            Received.InOrder(() =>
            {
                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUIUtilityCurrentViewWidth();
                unityInterface.EditorGUILayoutLabelField("When", RunnerEditorBusinessLogicData.LabelWidthAbsolute);
                unityInterface.EditorGUILayoutLabelField("When method", 368);
                unityInterface.EditorGUILayoutEndHorizontal();

                unityInterface.EditorGUILayoutBeginHorizontal();
                unityInterface.EditorGUIUtilityCurrentViewWidth();
                unityInterface.EditorGUILayoutLabelField("and", RunnerEditorBusinessLogicData.LabelWidthAbsolute);
                unityInterface.EditorGUILayoutLabelField("Second When method", 368);
                unityInterface.EditorGUILayoutEndHorizontal();
            });
        }
        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.");
        }
예제 #14
0
        public void Filter_Should_ReturnFalse_Given_ADynamicComponentAndTheSecondGivenMethodMethodAndAListOfMethodsThatDoesNotIncludeTheSecondGivenMethodMethod()
        {
            MethodsFilterByMethodsFullNameListTestDynamicComponent component = UnitTestUtility.CreateComponent <MethodsFilterByMethodsFullNameListTestDynamicComponent>();
            MethodInfo methodInfo = component.GetType().GetMethod("SecondGivenMethod");

            string[] methodsFullNamesList = new string[2] {
                "MethodsFilterByMethodsFullNameListUTDynamicBDDForTest.GivenMethod", "MethodsFilterByMethodsFullNameListUTDynamicBDDForTest.ThirdGivenMethod"
            };
            MethodsFilterByMethodsFullNameList methodsFilterByMethodsFullNameList = new MethodsFilterByMethodsFullNameList(methodsFullNamesList);
            bool result = methodsFilterByMethodsFullNameList.Filter <GivenBaseAttribute>(methodInfo);

            Assert.AreEqual(false, result, "The method MethodsFilterByMethodsFullNameList.Filter does not return the right answer");
        }
        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");
        }
예제 #16
0
        public void CheckForMethodNotFound_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_AListOfChosenMethodsAndADynamicComponentWithAllMethodsInTheList()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            string[] chosenMethods = new string[2] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.ThenMethod", "ChosenMethodsCheckerTestFirstDynamicComponent.SecondThenMethod"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForMethodNotFound <ThenBaseAttribute>(chosenMethods, components);

            Assert.AreEqual(0, result.Count, "The method CheckForMethodNotFound doesn't check properly");
        }
        public void Build_Should_ReturnTheExpectedBaseMethodDescriptionObject_Given_ADynamicComponentAndASimpleGivenMethod()
        {
            BaseMethodDescriptionBuilderTestDynamicComponent component = UnitTestUtility.CreateComponent<BaseMethodDescriptionBuilderTestDynamicComponent>();
            MethodInfo methodInfo = component.GetType().GetMethod("GivenMethod");

            BaseMethodDescription expectedBaseMethodDescription = new BaseMethodDescription();
            expectedBaseMethodDescription.ComponentObject = component;
            expectedBaseMethodDescription.Method = methodInfo;
            expectedBaseMethodDescription.StepType = typeof(GivenBaseAttribute);
            expectedBaseMethodDescription.Text = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetStepScenarioText();
            expectedBaseMethodDescription.ExecutionOrder = ((IGivenWhenThenDeclaration)methodInfo.GetCustomAttributes(typeof(GivenBaseAttribute), true)[0]).GetExecutionOrder();

            BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder();
            BaseMethodDescription builderResult = baseMethodDescriptionBuilder.Build<GivenBaseAttribute>(component, methodInfo);

            Assert.IsTrue(expectedBaseMethodDescription.Equals(builderResult), "The method BaseMethodDescriptionBuilder.Build does not return the expected object");
            Assert.AreEqual(expectedBaseMethodDescription.Text, builderResult.Text, "The method BaseMethodDescriptionBuilder.Build does not return the expected Text");
        }
예제 #18
0
        public void BddObjectsHaveChanged_Should_ReturnFalse_GivenTheBDDObjectsArrayIsNotEmptyAndTheCurrentComponentsArrayIsEmpty()
        {
            RunnerEditorBusinessLogicParametersRebuild runnerEditorBusinessLogicParametersRebuild = new RunnerEditorBusinessLogicParametersRebuild();
            RunnerEditorBusinessLogicData runnerBusinessLogicData = new RunnerEditorBusinessLogicData();

            runnerBusinessLogicData.BDDObjects = new Component[1] {
                UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicParametersRebuildUTDynamicBDDForTest>()
            };
            Component[]      currentComponents   = new Component[0];
            ComponentsFilter bddComponentsFilter = Substitute.For <ComponentsFilter>();

            Component[] bddComponentsFilterResult = new Component[0];
            bddComponentsFilter.Filter(currentComponents).Returns <Component[]>(bddComponentsFilterResult);

            bool result = runnerEditorBusinessLogicParametersRebuild.BddObjectsHaveChanged(currentComponents, runnerBusinessLogicData, bddComponentsFilter);

            Assert.IsTrue(result, "The method BddObjectsHaveChanged doesn't return the right state");
        }
예제 #19
0
        public void CheckForNotMatchingParametersIndex_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_TheParametersIndexesAndTheDynamicComponentWithTheCorrespondingMethodsAndParameters()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            string[] chosenMethods = new string[1] {
                "ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod"
            };
            string[] parametersIndex = new string[1] {
                ";System.String,ChosenMethodsCheckerTestFirstDynamicComponent.GivenMethod.stringParam.,stringPVS.Array.data[0];"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForNotMatchingParametersIndex <GivenBaseAttribute>(chosenMethods, parametersIndex, components);

            Assert.AreEqual(0, result.Count, "The method CheckForNotMatchingParametersIndex doesn't check properly");
        }
        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");
        }
예제 #21
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 GetScenarioTextForError_Should_ReturnTheExpectedString_Given_TheListOfTheFullMethodDescriptionObjectsBeteweenThreeDynamicComponentsAndAndTheErrorInACallBeforeMethod()
        {
            ExtensionRunnerBusinessLogicTestFirstDynamicComponent  firstComponent  = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestFirstDynamicComponent>();
            ExtensionRunnerBusinessLogicTestSecondDynamicComponent secondComponent = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestSecondDynamicComponent>();
            ExtensionRunnerBusinessLogicTestThirdDynamicComponent  thirdComponent  = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestThirdDynamicComponent>();

            Component[] components = new Component[3] {
                firstComponent, secondComponent, thirdComponent
            };

            string[] givenMethods = new string[3] {
                "ExtensionRunnerBusinessLogicTestFirstDynamicComponent.GivenMethod", "ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondGivenMethod", "ExtensionRunnerBusinessLogicTestSecondDynamicComponent.GivenMethod"
            };
            string[] givenParameters = new string[3] {
                string.Empty, string.Empty, string.Empty
            };

            string[] whenMethods = new string[2] {
                "ExtensionRunnerBusinessLogicTestFirstDynamicComponent.WhenMethod", "ExtensionRunnerBusinessLogicTestSecondDynamicComponent.WhenMethod"
            };
            string[] whenParameters = new string[2] {
                string.Empty, string.Empty
            };

            string[] thenMethods = new string[2] {
                "ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondThenMethod", "ExtensionRunnerBusinessLogicTestSecondDynamicComponent.ThenMethod"
            };
            string[] thenParameters = new string[2] {
                string.Empty, string.Empty
            };

            GameObject gameObject = UnitTestUtility.CreateGameObject();
            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);
            List <FullMethodDescription> methods       = businessLogic.GetAllMethodsDescriptions(components, givenMethods, givenParameters, whenMethods, whenParameters, thenMethods, thenParameters);

            FullMethodDescription methodDescription = methods[9];

            string expectedString = "\n            Given Given method\n              and Second Given method\n              and Given method\n             when When method\n              and When method\n             then Second Then method\n---------->   and Then method";

            string result = businessLogic.GetScenarioTextForErrorInSpecificMethod(methods, methodDescription);

            Assert.AreEqual(expectedString, result, "The method GetScenarioTextForErrorInSpecificMethod doesn't return the right scenario text");
        }
        public void GetbddMethodLocationForSpecificMethod_Should_ReturnTheExpectedString_Given_AListOfFullMethodDescriptionObjectsAndANestedMethodInError()
        {
            ExtensionRunnerBusinessLogicTestFirstDynamicComponent  firstComponent  = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestFirstDynamicComponent>();
            ExtensionRunnerBusinessLogicTestSecondDynamicComponent secondComponent = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestSecondDynamicComponent>();
            ExtensionRunnerBusinessLogicTestThirdDynamicComponent  thirdComponent  = UnitTestUtility.CreateComponent <ExtensionRunnerBusinessLogicTestThirdDynamicComponent>();

            Component[] components = new Component[3] {
                firstComponent, secondComponent, thirdComponent
            };

            string[] givenMethods = new string[3] {
                "ExtensionRunnerBusinessLogicTestFirstDynamicComponent.GivenMethod", "ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondGivenMethod", "ExtensionRunnerBusinessLogicTestSecondDynamicComponent.GivenMethod"
            };
            string[] givenParameters = new string[3] {
                string.Empty, string.Empty, string.Empty
            };

            string[] whenMethods = new string[2] {
                "ExtensionRunnerBusinessLogicTestFirstDynamicComponent.WhenMethod", "ExtensionRunnerBusinessLogicTestSecondDynamicComponent.WhenMethod"
            };
            string[] whenParameters = new string[2] {
                string.Empty, string.Empty
            };

            string[] thenMethods = new string[2] {
                "ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondThenMethod", "ExtensionRunnerBusinessLogicTestSecondDynamicComponent.ThenMethod"
            };
            string[] thenParameters = new string[2] {
                string.Empty, string.Empty
            };

            GameObject gameObject = UnitTestUtility.CreateGameObject();
            ExtensionRunnerBusinessLogic businessLogic = new ExtensionRunnerBusinessLogic(gameObject);
            List <FullMethodDescription> methods       = businessLogic.GetAllMethodsDescriptions(components, givenMethods, givenParameters, whenMethods, whenParameters, thenMethods, thenParameters);

            FullMethodDescription methodDescription = methods[5];

            string expectedString = "\n           [Given]  ExtensionRunnerBusinessLogicTestFirstDynamicComponent.GivenMethod [Delay= 0 Timeout= 3000]\n           [Given]  ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondGivenMethod [Delay= 0 Timeout= 3000]\n           [Given]  ExtensionRunnerBusinessLogicTestSecondDynamicComponent.GivenMethod [Delay= 0 Timeout= 3000]\n           [ When]  ExtensionRunnerBusinessLogicTestFirstDynamicComponent.WhenMethod [Delay= 21 Timeout= 34]\n           [ When]  ExtensionRunnerBusinessLogicTestSecondDynamicComponent.WhenMethod [Delay= 21 Timeout= 34]\n---------->[ Then]        ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondGivenMethod [Delay= 32 Timeout= 54]\n           [ Then]     ExtensionRunnerBusinessLogicTestThirdDynamicComponent.ThenMethod [Delay= 56 Timeout= 65]\n           [ Then]     ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondGivenMethod [Delay= 65 Timeout= 64]\n           [ Then]  ExtensionRunnerBusinessLogicTestThirdDynamicComponent.SecondThenMethod [Delay= 11 Timeout= 33]\n           [ Then]     ExtensionRunnerBusinessLogicTestSecondDynamicComponent.SecondGivenMethod [Delay= 32 Timeout= 54]\n           [ Then]  ExtensionRunnerBusinessLogicTestSecondDynamicComponent.ThenMethod [Delay= 0 Timeout= 3000]";

            string result = businessLogic.GetbddMethodLocationForSpecificMethod(methods, methodDescription);

            Assert.AreEqual(expectedString, result, "The method GetbddMethodLocationForSpecificMethod doesn't return the right location text");
        }
        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_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");
        }
예제 #26
0
        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 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");
        }
        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");
        }
예제 #29
0
        public void CheckForComponentNotFound_Should_ReturnTheExpectedListOfUnityTestBDDErrorObjects_Given_AListOfChosenMethodsWithoutACorrespondingDynamicComponent()
        {
            Component component = UnitTestUtility.CreateComponent <ChosenMethodsCheckerTestFirstDynamicComponent>();

            Component[] components = new Component[1] {
                component
            };
            string[] chosenMethods = new string[2] {
                "ChosenMethodsCheckerTestFirstDynamicComponentFake.ThenMethod", "ChosenMethodsCheckerTestFirstDynamicComponent.SecondThenMethod"
            };
            ChosenMethodsChecker     checkForErrors = new ChosenMethodsChecker();
            List <UnityTestBDDError> result         = checkForErrors.CheckForComponentNotFound <ThenBaseAttribute>(chosenMethods, components);
            string expectedMessage = "The component for the method ChosenMethodsCheckerTestFirstDynamicComponentFake.ThenMethod is not found  in Then methods at position 1";

            Assert.AreEqual(expectedMessage, result[0].Message, "The method CheckForComponentNotFound doesn't resturn the right message");
            Assert.IsNull(result[0].Component, "The method CheckForComponentNotFound doesn't resturn the right Component");
            Assert.IsNull(result[0].MethodMethodInfo, "The method CheckForComponentNotFound doesn't resturn the right MethodInfo");
            Assert.AreEqual(typeof(ThenBaseAttribute), result[0].StepType, "The method CheckForComponentNotFound doesn't resturn the right StepType");
            Assert.AreEqual(0, result[0].Index, "The method CheckForComponentNotFound doesn't resturn the right method index");
        }
예제 #30
0
        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");
        }