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 AddMissedMethodNameToMethodsNames_Should_AddAtTheEndOfTheStringArrayAnotherElementWithThePassedString() { string[] methodsNames = new string[3] { "FirstMethodName", "SecondMethodName", "ThirdMethodName" }; string methodName = "MissedMethodName"; RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities(); string[] result = methodsUtilities.AddMissedMethodNameToMethodsNames(methodName, methodsNames); Assert.AreEqual(4, result.Length, "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.AddMissedMethodNameToMethodsNames doesn't return the right amount of elements."); Assert.AreEqual(methodsNames[0], result[0], "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.AddMissedMethodNameToMethodsNames doesn't return the right elements."); Assert.AreEqual(methodsNames[1], result[1], "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.AddMissedMethodNameToMethodsNames doesn't return the right elements."); Assert.AreEqual(methodsNames[2], result[2], "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.AddMissedMethodNameToMethodsNames doesn't return the right elements."); Assert.AreEqual(methodName, result[3], "The method UnityTestToolsBDDExtensionRunnerEditorBusinessLogic.AddMissedMethodNameToMethodsNames doesn't add the new method name at the end of the array."); }
public void UpdateDataIfNewMethodIsChosen_Should_UpdateTheExpectedDataAndReturnTrue_Given_TheCurrentChosenMethodIsDifferenToThePrevious() { RunnerEditorBusinessLogicMethodsUtilities methodsUtilities = new RunnerEditorBusinessLogicMethodsUtilities(); string[] expectedChosenMethodsNames = new string[3] { "DynamicBDDForTest.SecondWhenMethod", "DynamicBDDForTest.SecondWhenMethod", string.Empty }; string[] expectedChosenMethodsParametersIndex = new string[3] { "FirstParametersIndex", "SecondParametersIndex", string.Empty }; bool[] expectedFoldouts = new bool[10] { false, true, true, true, true, true, true, true, true, true }; bool expectedRebuild = true; string newChosenMethod = "DynamicBDDForTest.SecondWhenMethod"; ChosenMethods chosenMethods = new ChosenMethods(); chosenMethods.ChosenMethodsNames = new string[3] { "DynamicBDDForTest.WhenMethod", "DynamicBDDForTest.SecondWhenMethod", string.Empty }; chosenMethods.ChosenMethodsParametersIndex = new string[3] { "FirstParametersIndex", "SecondParametersIndex", string.Empty }; bool[] foldouts = new bool[10] { true, true, true, true, true, true, true, true, true, true }; int index = 0; bool rebuild = false; string undoText = string.Empty; rebuild = methodsUtilities.UpdateDataIfNewMethodIsChosen(newChosenMethod, chosenMethods, foldouts, index, rebuild, out undoText); Assert.AreEqual(expectedChosenMethodsNames, chosenMethods.ChosenMethodsNames, "The method UpdateDataIfNewMethodIsChosen does not return the right ChosenMethods object"); Assert.AreEqual(expectedChosenMethodsParametersIndex, chosenMethods.ChosenMethodsParametersIndex, "The method UpdateDataIfNewMethodIsChosen does not return the right ChosenMethods object"); Assert.AreEqual(expectedFoldouts, foldouts, "The method UpdateDataIfNewMethodIsChosen does not return the right foldout state"); Assert.AreEqual(expectedRebuild, rebuild, "The method UpdateDataIfNewMethodIsChosen does not return the right rebuild state"); }
/// <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; }
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."); }
/// <summary> /// Draws the dynamic rows. /// </summary> /// <typeparam name="T">The type of the Step Methods.</typeparam> /// <param name="unityInterface">The unity interface.</param> /// <param name="methodsLoader">The methods loader.</param> /// <param name="methodDescriptionBuilder">The method description builder.</param> /// <param name="parametersLoader">The parameters loader.</param> /// <param name="bddComponents">The BDD components.</param> /// <param name="chosenMethods">The chosen methods.</param> /// <param name="foldouts">The foldouts.</param> /// <param name="serializedObjects">The serialized objects.</param> /// <param name="target">The target.</param> /// <param name="methodsUtilities">The methods utilities.</param> /// <param name="dynamicRowsElements">The dynamic rows elements.</param> /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param> /// <param name="rebuild">If set to <c>true</c> [rebuild].</param> /// <param name="updatedChosenMethodsList">The updated chosen methods list.</param> /// <param name="updatedFoldouts">The updated foldouts.</param> /// <param name="dirtyStatus">If set to <c>true</c> [dirty status].</param> /// <param name="undoText">The undo text.</param> /// <returns>True if a rebuild of the parameters index is requested.</returns> public bool DrawDynamicRows <T>( IUnityInterfaceWrapper unityInterface, MethodsLoader methodsLoader, MethodDescriptionBuilder methodDescriptionBuilder, MethodParametersLoader parametersLoader, Component[] bddComponents, ChosenMethods chosenMethods, bool[] foldouts, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, UnityEngine.Object target, RunnerEditorBusinessLogicMethodsUtilities methodsUtilities, RunnerEditorBusinessLogicDynamicRowsElements dynamicRowsElements, bool lockParametersRows, bool rebuild, out ChosenMethods updatedChosenMethodsList, out bool[] updatedFoldouts, out bool dirtyStatus, out string undoText) where T : IGivenWhenThenDeclaration { updatedChosenMethodsList = (ChosenMethods)chosenMethods.Clone(); updatedFoldouts = new bool[foldouts.Length]; Array.Copy(foldouts, updatedFoldouts, foldouts.Length); undoText = string.Empty; dirtyStatus = false; List <BaseMethodDescription> methodsList = methodsLoader.LoadStepMethods <T>(bddComponents); string[] methodsNames = methodsUtilities.GetMethodsNames(methodsList); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); for (int index = 0; index < chosenMethods.ChosenMethodsNames.Length; index++) { MethodDescription methodDescription = methodsUtilities.GetMethodDescription(methodDescriptionBuilder, parametersLoader, chosenMethods, methodsList, index); methodsNames = methodsUtilities.CheckMissedMethod(chosenMethods, methodsNames, index, methodDescription); List <FullMethodDescription> fullMethodDescriptionsList = fullMethodDescriptionBuilder.Build(methodDescription, (uint)index + 1); unityInterface.EditorGUILayoutBeginHorizontal(); dynamicRowsElements.DrawFoldoutSymbol(unityInterface, updatedFoldouts, index, fullMethodDescriptionsList); dynamicRowsElements.DrawLabel <T>(unityInterface, index); float textSize = (unityInterface.EditorGUIUtilityCurrentViewWidth() - RunnerEditorBusinessLogicData.LabelWidthAbsolute - RunnerEditorBusinessLogicData.ButtonsWidthAbsolute) * RunnerEditorBusinessLogicData.TextWidthPercent; dynamicRowsElements.DrawDescription(unityInterface, chosenMethods.ChosenMethodsNames[index], methodDescription, textSize); string newChosenMethod = dynamicRowsElements.DrawComboBox(unityInterface, chosenMethods.ChosenMethodsNames[index], methodsNames); rebuild = methodsUtilities.UpdateDataIfNewMethodIsChosen(newChosenMethod, updatedChosenMethodsList, updatedFoldouts, index, rebuild, out undoText); dirtyStatus = dirtyStatus || dynamicRowsElements.DrawAddRowButton(unityInterface, index, updatedChosenMethodsList, target, undoText, out updatedChosenMethodsList, out undoText); dirtyStatus = dirtyStatus || dynamicRowsElements.DrawRemoveRowButton(unityInterface, index, updatedChosenMethodsList, target, undoText, out updatedChosenMethodsList, out undoText); if (dirtyStatus) { break; } dynamicRowsElements.DrawCogButton(unityInterface, methodDescription, (BDDExtensionRunner)target); unityInterface.EditorGUILayoutEndHorizontal(); dynamicRowsElements.DrawParametersRows(unityInterface, foldouts[index], fullMethodDescriptionsList, serializedObjects, lockParametersRows); } return(rebuild); }