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 GetMethodDescriptionForTheChosenMethod_Should_ReturnTheExpectedMethodDescriptionObject_Given_ADynamicComponentAndTheMethodFullNameAndTheParametersIndexes() { MethodDescriptionBuilder methodDescriptionBuilder = Substitute.For <MethodDescriptionBuilder>(); MethodParametersLoader parametersLoader = Substitute.For <MethodParametersLoader>(); RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent component = UnitTestUtility.CreateComponent <RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent>(); ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); FieldInfo firstStringArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(string)); firstStringArrayStorage.SetValue(component, new string[2] { "FirstValue", "SecondValue" }); FieldInfo firstIntArrayStorage = arrayStorageUtilities.GetArrayStorageFieldInfoByType(component, typeof(int)); firstIntArrayStorage.SetValue(component, new int[2] { 33, 14 }); MethodInfo method = component.GetType().GetMethod("WhenMethod"); string parametersIndex = ";string,RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod.whenStringParam.,stringPVS.Array.data[0];int,RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod.whenIntParam.,intPVS.Array.data[0];"; MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); MethodParameters methodParameters = methodParametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex); parametersLoader.LoadMethodParameters(component, method, string.Empty, parametersIndex).Returns(methodParameters); BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder(); BaseMethodDescription baseMethodDescription = baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, method); MethodDescriptionBuilder methodDescriptionBuilderInstance = new MethodDescriptionBuilder(); MethodDescription methodDescription = methodDescriptionBuilderInstance.Build(parametersLoader, baseMethodDescription, parametersIndex); methodDescriptionBuilder.Build(parametersLoader, baseMethodDescription, parametersIndex).Returns(methodDescription); string chosenMethodName = "RunnerEditorBusinessLogicMethodsUtilitiesTestDynamicComponent.WhenMethod"; string chosenMethodParametersIndex = parametersIndex; List <BaseMethodDescription> methodList = new List <BaseMethodDescription>(); methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("SecondWhenMethod"))); methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("WhenMethod"))); methodList.Add(baseMethodDescriptionBuilder.Build <WhenBaseAttribute>(component, component.GetType().GetMethod("ThirdWhenMethod"))); RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities(); MethodDescription result = methodsUtilities.GetMethodDescriptionForTheChosenMethod(methodDescriptionBuilder, parametersLoader, chosenMethodName, chosenMethodParametersIndex, methodList); Assert.IsTrue(methodDescription.Equals(result), "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.GetMethodDescriptionForTheChosenMethod doesn't return the right object"); }
public void LoadFullMethodsDescriptions_Should_ReturnTheExpectedListOfFullMethodDescriptionObjects_Given_AListOfMethodDescriptionObjectsOfMethodsContainingCallBeforeAttributes() { // Create the MethodDescription MethodsManagementUtilitiesUTDynamicBDDForTestForCallBeforeMethodsList component = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesUTDynamicBDDForTestForCallBeforeMethodsList>(); MethodInfo mainMethodInfo = component.GetType().GetMethod("SecondThenMethod"); MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); MethodParametersLoader methodParametersLoader = new MethodParametersLoader(); BaseMethodDescriptionBuilder baseMethodDescriptionBuilder = new BaseMethodDescriptionBuilder(); BaseMethodDescription mainBaseMethodDescription = baseMethodDescriptionBuilder.Build <ThenBaseAttribute>(component, mainMethodInfo); string parametersIndex = string.Empty; MethodDescription firstChosenMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, mainBaseMethodDescription, parametersIndex); // Create the expected FullMethodDescription MethodInfo firstCallBeforeMethodInfo = component.GetType().GetMethod("ThenMethod"); BaseMethodDescription firstCallBeforeBaseMethodDescription = baseMethodDescriptionBuilder.Build <ThenBaseAttribute>(component, firstCallBeforeMethodInfo); MethodDescription secondChosenMethodDescription = methodDescriptionBuilder.Build(methodParametersLoader, firstCallBeforeBaseMethodDescription, parametersIndex); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); List <FullMethodDescription> firstChosenFullMethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(firstChosenMethodDescription, 1); List <FullMethodDescription> seconChosenFullMethodDescriptionsList = fullMethodDescriptionBuilder.BuildFromBaseMethodDescription(secondChosenMethodDescription, 2); List <FullMethodDescription> expectedFullMethodDescriptionsList = new List <FullMethodDescription>(); expectedFullMethodDescriptionsList.AddRange(firstChosenFullMethodDescriptionsList); expectedFullMethodDescriptionsList.AddRange(seconChosenFullMethodDescriptionsList); // Build the fullMethodDescription List <MethodDescription> methodsDescriptionsList = new List <MethodDescription>(); methodsDescriptionsList.Add(firstChosenMethodDescription); methodsDescriptionsList.Add(secondChosenMethodDescription); MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); List <FullMethodDescription> result = methodsManagementUtilities.LoadFullMethodsDescriptions <ThenBaseAttribute>(methodsDescriptionsList, fullMethodDescriptionBuilder); // Compare the FullMethodDescriptions Assert.AreEqual(6, 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"); Assert.AreEqual(expectedFullMethodDescriptionsList[2], result[2], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[3], result[3], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[4], result[4], "The method build doesn't return the right fullMethodDescription"); Assert.AreEqual(expectedFullMethodDescriptionsList[5], result[5], "The method build doesn't return the right fullMethodDescription"); }
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"); }
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"); }