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(); }); }
/// <summary> /// Draws the parameters rows. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="foldout">If set to <c>true</c> [foldout].</param> /// <param name="fullMethodDescription">The full method description.</param> /// <param name="serializedObjects">The serialized objects.</param> /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param> public void DrawParametersRows(IUnityInterfaceWrapper unityInterface, bool foldout, FullMethodDescription fullMethodDescription, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, bool lockParametersRows) { if (fullMethodDescription != null && foldout && !lockParametersRows) { ISerializedObjectWrapper serializedObject = null; serializedObjects.TryGetValue(fullMethodDescription.ComponentObject.GetType(), out serializedObject); foreach (MethodParameter parameter in fullMethodDescription.Parameters.Parameters) { string parameterName = parameter.ParameterInfoObject.Name; ParameterLocation parameterLocation = parameter.ParameterLocation; // "given.Array.data[0]" string parameterLocationString = parameterLocation.ParameterArrayLocation.ArrayName + ".Array.data[" + parameterLocation.ParameterArrayLocation.ArrayIndex + "]"; GUIContent label = unityInterface.GUIContent(parameterName); ISerializedPropertyWrapper property = serializedObject.FindProperty(parameterLocationString); unityInterface.EditorGUILayoutPropertyField(property, label); } } if (fullMethodDescription != null && foldout && lockParametersRows) { float labelWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); unityInterface.EditorGUILayoutLabelField("When there are some errors the parameters are protected to avoid data lost.", labelWidth); } }
/// <summary> /// Draws the parameters rows. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="foldout">If set to <c>true</c> [foldout].</param> /// <param name="fullMethodDescriptionsList">The full method descriptions list.</param> /// <param name="serializedObjects">The serialized objects.</param> /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param> public void DrawParametersRows(IUnityInterfaceWrapper unityInterface, bool foldout, List <FullMethodDescription> fullMethodDescriptionsList, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, bool lockParametersRows) { if (fullMethodDescriptionsList != null && fullMethodDescriptionsList.Count > 0 && foldout /* && !lockParametersRows*/) { bool theCallBeforeMethodsHaveParameters = false; foreach (FullMethodDescription fullMethodDescription in fullMethodDescriptionsList) { if (fullMethodDescription.Parameters.Parameters.Length > 0) { if (fullMethodDescription.MainMethod != null) { theCallBeforeMethodsHaveParameters = true; } if (theCallBeforeMethodsHaveParameters) { unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutBeginHorizontal(); float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); string text = this.GetHeaderTextForFullMethodDescription(fullMethodDescription); unityInterface.EditorGUILayoutLabelFieldTruncate(text, currentViewWidth); unityInterface.EditorGUILayoutEndHorizontal(); } this.DrawParametersRows(unityInterface, foldout, fullMethodDescription, serializedObjects, lockParametersRows); } } unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); } }
/// <summary> /// Draws the given errors. /// </summary> /// <param name="errors">The errors.</param> /// <param name="unityInterface">The unity interface.</param> public void Errors(List <UnityTestBDDError> errors, IUnityInterfaceWrapper unityInterface) { BDDExtensionRunner bddExtensionRunner = this.component.gameObject.GetComponent <BDDExtensionRunner>(); string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.OpenComponentButtonTextureFileName); string errorTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.ErrorTextureFileName); foreach (UnityTestBDDError error in errors) { unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutEndHorizontal(); unityInterface.EditorGUILayoutBeginHorizontal(); float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); Texture2D errorTexture = unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)); GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; unityInterface.EditorGUILayoutLabelField(errorTexture, errorTextureOptions); float labelWidth = currentViewWidth - 100; unityInterface.EditorGUILayoutLabelField(error.Message, labelWidth); Texture2D openComponentButtonTexture = unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; if (unityInterface.GUILayoutButton(openComponentButtonTexture, EditorStyles.label, options)) { if (error.MethodMethodInfo != null) { SourcesManagement.OpenMethodSourceCode(error.MethodMethodInfo, unityInterface); } else if (error.Component != null) { SourcesManagement.OpenSourceCode(error.Component, unityInterface); } else { MethodInfo[] methods = this.component.GetType().GetMethods(); foreach (MethodInfo method in methods) { if (method.DeclaringType.Name.Equals(this.component.GetType().Name)) { SourcesManagement.OpenSourceCode(method, unityInterface); } } } } unityInterface.EditorGUILayoutEndHorizontal(); } }
/// <summary> /// Draws the given errors. /// </summary> /// <param name="errors">The errors.</param> /// <param name="unityInterface">The unity interface.</param> /// <param name="bddExtensionRunner">The BDD extension runner.</param> public void Errors(List <UnityTestBDDError> errors, IUnityInterfaceWrapper unityInterface, BDDExtensionRunner bddExtensionRunner) { string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.OpenComponentButtonTextureFileName); string errorTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.ErrorTextureFileName); foreach (UnityTestBDDError error in errors) { unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutEndHorizontal(); unityInterface.EditorGUILayoutBeginHorizontal(); float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); if (error.ShowRedExclamationMark) { Texture2D errorTexture = unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)); GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; unityInterface.EditorGUILayoutLabelField(errorTexture, errorTextureOptions); } float labelWidth = currentViewWidth - 100; unityInterface.EditorGUILayoutLabelField(error.Message, labelWidth); Texture2D openComponentButtonTexture = unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; if (error.ShowButton) { if (unityInterface.GUILayoutButton(openComponentButtonTexture, EditorStyles.label, options)) { if (error.MethodMethodInfo != null) { SourcesManagement.OpenMethodSourceCode(error.MethodMethodInfo, unityInterface); } else if (error.Component != null) { SourcesManagement.OpenSourceCode(error.Component, unityInterface); } } } unityInterface.EditorGUILayoutEndHorizontal(); } }
/// <summary> /// Draws the options. /// </summary> /// <param name="businessLogicData">The business logic data.</param> /// <param name="isStaticScenario">If set to <c>true</c> [is static scenario].</param> /// <param name="script">The script.</param> /// <param name="unityInterface">The unity interface.</param> /// <param name="bddComponents">The BDD components.</param> private void DrawOptions(RunnerEditorBusinessLogicData businessLogicData, bool isStaticScenario, BDDExtensionRunner script, IUnityInterfaceWrapper unityInterface, Component[] bddComponents) { Rect rect = unityInterface.EditorGUILayoutGetControlRect(); businessLogicData.OptionsFoldout = unityInterface.EditorGUIFoldout(rect, businessLogicData.OptionsFoldout, "Options"); if (businessLogicData.OptionsFoldout) { if (!isStaticScenario) { this.ForceRebuildParametersButton(script, bddComponents); } unityInterface.EditorGUILayoutSeparator(); this.ChooseBetweenUpdateAndFixedUpdate(script, this.unityIntefaceWrapper); float width = unityInterface.EditorGUIUtilityCurrentViewWidth(); int numberOfSeparatorChars = (int)width / 7; string text = string.Empty.PadLeft(numberOfSeparatorChars, '_'); unityInterface.EditorGUILayoutLabelFieldTruncate(text, width); } }
/// <summary> /// Draws the static rows. /// </summary> /// <typeparam name="T">The Step Methods type.</typeparam> /// <param name="unityInterface">The unity interface.</param> /// <param name="stepMethodsLoader">The step methods loader.</param> /// <param name="bddComponents">The BDD components.</param> /// <param name="labelWidthAbsolute">The label width absolute.</param> /// <param name="buttonsWidthAbsolute">The buttons width absolute.</param> public void DrawStaticRows <T>(IUnityInterfaceWrapper unityInterface, MethodsLoader stepMethodsLoader, Component[] bddComponents, float labelWidthAbsolute, float buttonsWidthAbsolute) where T : IGivenWhenThenDeclaration { List <BaseMethodDescription> methodsList = stepMethodsLoader.LoadStepMethods <T>(bddComponents); for (int index = 0; index < methodsList.Count; index++) { unityInterface.EditorGUILayoutBeginHorizontal(); float rowWidth = unityInterface.EditorGUIUtilityCurrentViewWidth() - labelWidthAbsolute - buttonsWidthAbsolute; float textSize = rowWidth - 20; string label = StepMethodUtilities.GetStepMethodName <T>(); if (index > 0) { label = "and"; } unityInterface.EditorGUILayoutLabelField(label, labelWidthAbsolute); string description = string.Empty; description = methodsList[index].Text; unityInterface.EditorGUILayoutLabelField(description, textSize); this.DrawCogButton(unityInterface, methodsList[index]); unityInterface.EditorGUILayoutEndHorizontal(); } }
public void Errors_Should_CallTheExpectedUnityEditorStatements_Given_OneErrorOnAComponent() { UnityTestBDDComponentBaseEditorBusinessLogicTestFirstDynamicComponent component = UnitTestUtility.CreateComponent <UnityTestBDDComponentBaseEditorBusinessLogicTestFirstDynamicComponent>(); BDDExtensionRunner runner = UnitTestUtility.CreateComponent <BDDExtensionRunner>(component.gameObject); BaseBDDComponentEditorBusinessLogic unityTestBDDComponentBaseEditorBusinessLogic = new BaseBDDComponentEditorBusinessLogic(component); string expectedMessage = "Message"; List <UnityTestBDDError> errors = new List <UnityTestBDDError>(); UnityTestBDDError error = new UnityTestBDDError(); error.Message = expectedMessage; error.Component = component; error.MethodMethodInfo = null; errors.Add(error); string errorTextureFullPath = Utilities.GetAssetFullPath(runner, unityTestBDDComponentBaseEditorBusinessLogic.ErrorTextureFileName); string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(runner, unityTestBDDComponentBaseEditorBusinessLogic.OpenComponentButtonTextureFileName); IUnityInterfaceWrapper unityInterface = Substitute.For <IUnityInterfaceWrapper>(); unityInterface.EditorGUIUtilityCurrentViewWidth().Returns(600f); float labelWidth = 500f; Texture2D inputTexture = new Texture2D(10, 10); unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)).Returns(inputTexture); Texture2D errorTexture = new Texture2D(10, 10); unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)).Returns(errorTexture); GUILayoutOption buttonWidth = GUILayout.Width(16); unityInterface.GUILayoutWidth(24).Returns(buttonWidth); GUILayoutOption buttonHeight = GUILayout.Height(16); unityInterface.GUILayoutHeight(24).Returns(buttonHeight); GUILayoutOption[] options = new GUILayoutOption[2]; options[0] = buttonWidth; options[1] = buttonHeight; unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, options).Returns(false); GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2]; errorTextureOptions[0] = buttonWidth; errorTextureOptions[1] = buttonHeight; unityTestBDDComponentBaseEditorBusinessLogic.Errors(errors, unityInterface); Received.InOrder(() => { unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutEndHorizontal(); unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUIUtilityCurrentViewWidth(); unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)); unityInterface.GUILayoutWidth(24); unityInterface.GUILayoutHeight(24); unityInterface.EditorGUILayoutLabelField(errorTexture, Arg.Is <GUILayoutOption[]>(x => x.SequenceEqual(errorTextureOptions) == true)); unityInterface.EditorGUILayoutLabelField(expectedMessage, labelWidth); unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); unityInterface.GUILayoutWidth(24); unityInterface.GUILayoutHeight(24); unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, Arg.Is <GUILayoutOption[]>(x => x.SequenceEqual(options) == true)); unityInterface.EditorGUILayoutEndHorizontal(); }); }
/// <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); }