/// <summary> /// Gets the list of <see cref="FullMethodDescription"/> objects to run. /// </summary> /// <param name="allComponents">All components.</param> /// <param name="givenMethods">The given methods.</param> /// <param name="givenParameters">The given parameters.</param> /// <param name="whenMethods">The when methods.</param> /// <param name="whenParameters">The when parameters.</param> /// <param name="thenMethods">The then methods.</param> /// <param name="thenParameters">The then parameters.</param> /// <returns>The list of <see cref="FullMethodDescription"/> objects to run.</returns> public List <FullMethodDescription> GetAllMethodsDescriptions( Component[] allComponents, string[] givenMethods, string[] givenParameters, string[] whenMethods, string[] whenParameters, string[] thenMethods, string[] thenParameters) { List <FullMethodDescription> result = new List <FullMethodDescription>(); ComponentsFilter componentsFilter = new ComponentsFilter(); Component[] components = componentsFilter.Filter(allComponents); MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); if (methodsManagementUtilities.IsStaticBDDScenario(components)) { result.AddRange(this.GetAllStaticFullMethodsDescriptions <GivenBaseAttribute>(components, methodsManagementUtilities)); result.AddRange(this.GetAllStaticFullMethodsDescriptions <WhenBaseAttribute>(components, methodsManagementUtilities)); result.AddRange(this.GetAllStaticFullMethodsDescriptions <ThenBaseAttribute>(components, methodsManagementUtilities)); } else { result.AddRange(this.GetAllDynamicFullMethodsDescriptions <GivenBaseAttribute>(components, methodsManagementUtilities, givenMethods, givenParameters)); result.AddRange(this.GetAllDynamicFullMethodsDescriptions <WhenBaseAttribute>(components, methodsManagementUtilities, whenMethods, whenParameters)); result.AddRange(this.GetAllDynamicFullMethodsDescriptions <ThenBaseAttribute>(components, methodsManagementUtilities, thenMethods, thenParameters)); } return(result); }
public void IsStaticBDDScenario_Should_ReturnFalse_Given_AListOfDynamicComponents() { MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); MethodsManagementUtilitiesTestFirstDynamicComponent dynamicBDDComponent1 = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestFirstDynamicComponent>(); MethodsManagementUtilitiesTestSecondDynamicComponent dynamicBDDComponent2 = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestSecondDynamicComponent>(); Component[] components = new Component[2] { dynamicBDDComponent1, dynamicBDDComponent2 }; bool result = methodsManagementUtilities.IsStaticBDDScenario(components); Assert.IsFalse(result, "THe method IsStaticBDDScenario does not return the right state"); }
public void IsStaticBDDScenario_Should_ReturnTrue_Given_AListOfComponentsWhereTwoOfThemAreDynamicComponentsAndOneIsAStaticComponent() { MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); MethodsManagementUtilitiesTestFirstDynamicComponent dynamicBDDComponent1 = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestFirstDynamicComponent>(); MethodsManagementUtilitiesTestStaticComponent staticComponent = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestStaticComponent>(); MethodsManagementUtilitiesTestSecondDynamicComponent dynamicBDDComponent2 = UnitTestUtility.CreateComponent <MethodsManagementUtilitiesTestSecondDynamicComponent>(); Component[] components = new Component[3] { dynamicBDDComponent1, staticComponent, dynamicBDDComponent2 }; bool result = methodsManagementUtilities.IsStaticBDDScenario(components); Assert.IsTrue(result, "THe method IsStaticBDDScenario does not return the right state"); }
/// <summary> /// Implement this function to make a custom inspector. /// </summary> public override void OnInspectorGUI() { BDDExtensionRunner script = (BDDExtensionRunner)target; serializedObject.Update(); Component[] components = script.gameObject.GetComponents <Component>(); List <UnityTestBDDError> errors = new List <UnityTestBDDError>(); ComponentsFilter bddComponentsFilter = new ComponentsFilter(); Component[] bddComponents = bddComponentsFilter.Filter(components); ComponentsChecker checkForComponentsErrors = new ComponentsChecker(); errors.AddRange(checkForComponentsErrors.Check(bddComponents)); if (!this.RunnerInspectorIsLockedOnErrors(errors) && bddComponents.Length > 0) { foreach (Component component in bddComponents) { if (((BaseBDDComponent)component).Errors.Count > 0) { UnityTestBDDError error = new UnityTestBDDError(); error.Message = "There are some errors in the BDDComponents. Please, check and resolve them before continue."; error.MethodMethodInfo = null; error.Component = null; error.LockRunnerInspectorOnErrors = true; error.ShowButton = false; error.Index = 0; error.LockBuildParameters = true; error.LockParametersRows = true; error.ShowRedExclamationMark = true; error.StepType = null; errors.Add(error); break; } } } if (!this.RunnerInspectorIsLockedOnErrors(errors) && !this.IsStaticScenario(components)) { ChosenMethodsChecker checkForErrors = new ChosenMethodsChecker(); errors.AddRange(checkForErrors.Check(script.Given, script.GivenParametersIndex, script.When, script.WhenParametersIndex, script.Then, script.ThenParametersIndex, bddComponents)); } RunnerEditorBusinessLogicErrorsManagement runnerEditorBusinessLogicErrorsManagement = new RunnerEditorBusinessLogicErrorsManagement(); runnerEditorBusinessLogicErrorsManagement.Errors(errors, this.unityIntefaceWrapper, script); MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); bool isStaticScenario = methodsManagementUtilities.IsStaticBDDScenario(bddComponents); SetSucceedOnAssertions(script.gameObject); if (!this.RunnerInspectorIsLockedOnErrors(errors)) { this.DrawOptions(this.runnerBusinessLogicData, isStaticScenario, script, this.unityIntefaceWrapper, bddComponents); if (!isStaticScenario) { if (!this.BuildParametersIsLocked(errors)) { bool isParametersRebuildNeeded = this.businessLogicParametersRebuild.IsParametersRebuildNeeded(this.unityIntefaceWrapper, this.runnerBusinessLogicData, bddComponents, bddComponentsFilter); if (isParametersRebuildNeeded) { this.RebuildParameters(script, bddComponents, this.runnerBusinessLogicData); this.runnerBusinessLogicData.BDDObjects = bddComponents; this.runnerBusinessLogicData.SerializedObjects = this.businessLogicParametersRebuild.RebuildSerializedObjectsList(bddComponents, this.runnerBusinessLogicData.SerializedObjects); } } } if (Event.current.type == EventType.Layout || this.dirtyStatus == false) { this.dirtyStatus = false; if (this.runnerBusinessLogicData.SerializedObjects != null) { foreach (ISerializedObjectWrapper so in this.runnerBusinessLogicData.SerializedObjects.Values) { so.Update(); } } if (methodsManagementUtilities.IsStaticBDDScenario(bddComponents)) { this.BuildStaticScenario(bddComponents); } else { this.BuildDynamicScenario(script, bddComponents, this.LockParametersRows(errors), out this.dirtyStatus); } serializedObject.ApplyModifiedProperties(); if (this.runnerBusinessLogicData.SerializedObjects != null) { foreach (ISerializedObjectWrapper so in this.runnerBusinessLogicData.SerializedObjects.Values) { so.ApplyModifiedProperties(); } } } else { this.unityIntefaceWrapper.EditorUtilitySetDirty(script); } } }