/// <summary> /// Draws the button "Rebuild settings.". /// </summary> /// <param name="script">The script.</param> /// <param name="components">The components.</param> private void ForceRebuildParametersButton(BDDExtensionRunner script, Component[] components) { if (GUILayout.Button("Rebuild settings.", EditorStyles.miniButton, GUILayout.Width(100))) { GenericMenu menu = new GenericMenu(); GUIContent optionNotRebuild = new GUIContent("I am not sure. I will try to fix the errors instead."); GUIContent optionRebuild = new GUIContent("Rebuild! Every parameter with errors could be resetted and the values could be lost."); bool on = false; menu.AddItem( optionNotRebuild, on, () => { }); menu.AddItem( optionRebuild, on, () => { RegisterUndoInformation(script, components, "Rebuld settings"); this.RebuildParameters(script, components, runnerBusinessLogicData); runnerBusinessLogicData.BDDObjects = components; runnerBusinessLogicData.SerializedObjects = businessLogicParametersRebuild.RebuildSerializedObjectsList(components, runnerBusinessLogicData.SerializedObjects); }); menu.ShowAsContext(); } }
/// <summary> /// Draws the checkbox for choosing between update and fixed update. /// </summary> /// <param name="script">The script.</param> /// <param name="unityInterface">The unity interface.</param> private void ChooseBetweenUpdateAndFixedUpdate(BDDExtensionRunner script, IUnityInterfaceWrapper unityInterface) { GUIContent label = unityInterface.GUIContent("Run under Fixed Update"); bool result = GUILayout.Toggle(script.UseFixedUpdate, label, GUILayout.ExpandWidth(false)); if (result != script.UseFixedUpdate) { Undo.RecordObject(script, "Change the use of Fixed Update."); script.UseFixedUpdate = result; } }
/// <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> /// Gets the full path of a file inside the BDDExtensionFramework asset. /// </summary> /// <param name="bddExtensionRunner">The BDD extension runner.</param> /// <param name="fileName">Name of the file.</param> /// <returns>The full path of the file inside the BDDExtensionFramework asset. </returns> public static string GetAssetFullPath(BDDExtensionRunner bddExtensionRunner, string fileName) { string result = string.Empty; if (bddExtensionRunner != null) { MonoScript script = MonoScript.FromMonoBehaviour(bddExtensionRunner); string runnerFullPath = AssetDatabase.GetAssetPath(script); string runnerPath = runnerFullPath.Substring(0, runnerFullPath.Length - "BDDExtensionRunner.cs".Length - 1); result = runnerPath + System.IO.Path.DirectorySeparatorChar + "Resources" + System.IO.Path.DirectorySeparatorChar + "Sprites" + System.IO.Path.DirectorySeparatorChar + fileName; } return(result); }
/// <summary> /// Rebuilds the parameters. /// </summary> /// <param name="script">The script.</param> /// <param name="dynamicBDDComponents">The dynamic BDD components.</param> /// <param name="runnerBusinessLogicData">The runner business logic data.</param> private void RebuildParameters(BDDExtensionRunner script, Component[] dynamicBDDComponents, RunnerEditorBusinessLogicData runnerBusinessLogicData) { // Generate the three list of MethodDescription for each step type: Given, When, Then MethodsManagementUtilities methodsManagementUtilities = new MethodsManagementUtilities(); BaseMethodDescriptionBuilder methodBuilder = new BaseMethodDescriptionBuilder(); IMethodsFilter givenMethodFilter = new MethodsFilterByMethodsFullNameList(script.Given); MethodsLoader givenMethodsLoader = new MethodsLoader(methodBuilder, givenMethodFilter); MethodDescriptionBuilder methodDescriptionBuilder = new MethodDescriptionBuilder(); FullMethodDescriptionBuilder fullMethodDescriptionBuilder = new FullMethodDescriptionBuilder(); MethodParametersLoader methodsParametersLoader = new MethodParametersLoader(); List <MethodDescription> givenMethodsDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <GivenBaseAttribute>(dynamicBDDComponents, givenMethodsLoader, methodDescriptionBuilder, methodsParametersLoader, script.Given, script.GivenParametersIndex); List <FullMethodDescription> givenFullMethodsDescriptionList = methodsManagementUtilities.LoadFullMethodsDescriptions <GivenBaseAttribute>(givenMethodsDescriptionList, fullMethodDescriptionBuilder); IMethodsFilter whenMethodFilter = new MethodsFilterByMethodsFullNameList(script.When); MethodsLoader whenMethodsLoader = new MethodsLoader(methodBuilder, whenMethodFilter); List <MethodDescription> whenMethodsDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <WhenBaseAttribute>(dynamicBDDComponents, whenMethodsLoader, methodDescriptionBuilder, methodsParametersLoader, script.When, script.WhenParametersIndex); List <FullMethodDescription> whenFullMethodsDescriptionList = methodsManagementUtilities.LoadFullMethodsDescriptions <WhenBaseAttribute>(whenMethodsDescriptionList, fullMethodDescriptionBuilder); IMethodsFilter thenMethodFilter = new MethodsFilterByMethodsFullNameList(script.Then); MethodsLoader thenMethodsLoader = new MethodsLoader(methodBuilder, thenMethodFilter); List <MethodDescription> thenMethodsDescriptionList = methodsManagementUtilities.LoadMethodsDescriptionsFromChosenMethods <ThenBaseAttribute>(dynamicBDDComponents, thenMethodsLoader, methodDescriptionBuilder, methodsParametersLoader, script.Then, script.ThenParametersIndex); List <FullMethodDescription> thenFullMethodsDescriptionList = methodsManagementUtilities.LoadFullMethodsDescriptions <ThenBaseAttribute>(thenMethodsDescriptionList, fullMethodDescriptionBuilder); // Reset the valuesArrayStorages for each component ArrayStorageUtilities arrayStorageUtilities = new ArrayStorageUtilities(); arrayStorageUtilities.ResetAllArrayStorage(dynamicBDDComponents); // Rebuild the parameters indexes and locations for each list of MethodDescription RunnerEditorBusinessLogicParametersLocationsBuilder parametersLocationsBuilder = new RunnerEditorBusinessLogicParametersLocationsBuilder(); parametersLocationsBuilder.BuildParametersLocation(givenFullMethodsDescriptionList); parametersLocationsBuilder.BuildParametersLocation(whenFullMethodsDescriptionList); parametersLocationsBuilder.BuildParametersLocation(thenFullMethodsDescriptionList); // Rebuild the parameters Indexes arrays script.GivenParametersIndex = parametersLocationsBuilder.RebuildParametersIndexesArrays(givenFullMethodsDescriptionList, script.Given); script.WhenParametersIndex = parametersLocationsBuilder.RebuildParametersIndexesArrays(whenFullMethodsDescriptionList, script.When); script.ThenParametersIndex = parametersLocationsBuilder.RebuildParametersIndexesArrays(thenFullMethodsDescriptionList, script.Then); }
/// <summary> /// Implement this function to make a custom inspector. /// </summary> public override void OnInspectorGUI() { BDDExtensionRunner bddExtensionRunner = ((Component)target).gameObject.GetComponent <BDDExtensionRunner>(); string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.MainTexturePath); BaseBDDComponent script = (BaseBDDComponent)target; if (EditorApplication.isCompiling) { script.Checking = true; } BDDExtensionRunner runner = script.gameObject.GetComponent <BDDExtensionRunner>(); if (runner != null) { this.unityInterface.EditorGUILayoutBeginHorizontal(); Texture2D texture = this.unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[1] { this.unityInterface.GUILayoutHeight(70) }; GUIContent label = new GUIContent(texture); EditorGUILayout.LabelField(label, options); this.unityInterface.EditorGUILayoutEndHorizontal(); ComponentsChecker checkForErrors = new ComponentsChecker(); script.Errors = checkForErrors.Check(script); if (script.Errors.Count > 0) { BaseBDDComponentEditorBusinessLogic businessLogic = new BaseBDDComponentEditorBusinessLogic(script); businessLogic.Errors(script.Errors, this.unityInterface); } else { this.DrawDefaultInspector(); } script.Checking = false; } else { this.DrawDefaultInspector(); } }
/// <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; }
/// <summary> /// Draws the cog button. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="methodDescription">The method description.</param> /// <param name="bddExtensionRunner">The BDD extension runner.</param> internal void DrawCogButton(IUnityInterfaceWrapper unityInterface, MethodDescription methodDescription, BDDExtensionRunner bddExtensionRunner) { string cogTexture = @"cog.png"; string cogTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, cogTexture); Texture2D inputTexture = unityInterface.AssetDatabaseLoadAssetAtPath(cogTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(16), unityInterface.GUILayoutHeight(16) }; if (unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, options)) { GenericMenu menu = new GenericMenu(); GUIContent content = new GUIContent("Open method source"); bool on = false; MethodInfo method = null; if (methodDescription != null) { on = true; method = methodDescription.Method; menu.AddItem(content, on, () => { SourcesManagement.OpenMethodSourceCode(method, unityInterface); }); } else { menu.AddDisabledItem(content); } menu.ShowAsContext(); } }
/// <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); } } }
/// <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 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(); } }
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(); }); }