diff --git a/Bonsai.Configuration/NativeMethods.cs b/Bonsai.Configuration/NativeMethods.cs index 53fb56fa..62470930 100644 --- a/Bonsai.Configuration/NativeMethods.cs +++ b/Bonsai.Configuration/NativeMethods.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Bonsai.Configuration { diff --git a/Bonsai.Configuration/ScriptExtensions.cs b/Bonsai.Configuration/ScriptExtensions.cs index de7f091b..35a574ed 100644 --- a/Bonsai.Configuration/ScriptExtensions.cs +++ b/Bonsai.Configuration/ScriptExtensions.cs @@ -1,5 +1,4 @@ using NuGet.Configuration; -using NuGet.Packaging; using NuGet.Versioning; using System; using System.Collections.Generic; diff --git a/Bonsai.Editor.Tests/EditorHelper.cs b/Bonsai.Editor.Tests/EditorHelper.cs index ef97a1c7..522627bd 100644 --- a/Bonsai.Editor.Tests/EditorHelper.cs +++ b/Bonsai.Editor.Tests/EditorHelper.cs @@ -25,6 +25,14 @@ internal static ExpressionBuilderGraph CreateEditorGraph(params string[] values) return graph.ToInspectableGraph(); } + internal static TBuilder FindExpressionBuilder(this ExpressionBuilderGraph workflow) where TBuilder : class + { + return (from node in workflow + let builder = node.Value as TBuilder + where builder != null + select builder).FirstOrDefault(); + } + internal static GraphNode FindNode(this WorkflowEditor editor, string name) { var node = editor.Workflow.First(n => ExpressionBuilder.GetElementDisplayName(n.Value) == name); diff --git a/Bonsai.Editor.Tests/NestedSubscribeSubjectWithClosestRedefinition.bonsai b/Bonsai.Editor.Tests/NestedSubscribeSubjectWithClosestRedefinition.bonsai new file mode 100644 index 00000000..6c529d8d --- /dev/null +++ b/Bonsai.Editor.Tests/NestedSubscribeSubjectWithClosestRedefinition.bonsai @@ -0,0 +1,71 @@ + + + + + + + 8 + + + + Values + + + Values + + + + + + Source1 + + + + 2 + + + + Values + + + + PT0S + PT0S + + + + + + + Source1 + + + Values + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Bonsai.Editor.Tests/WorkflowEditorDefinitionTests.cs b/Bonsai.Editor.Tests/WorkflowEditorDefinitionTests.cs new file mode 100644 index 00000000..c99cebfe --- /dev/null +++ b/Bonsai.Editor.Tests/WorkflowEditorDefinitionTests.cs @@ -0,0 +1,22 @@ +using Bonsai.Editor.GraphModel; +using Bonsai.Reactive; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Bonsai.Editor.Tests +{ + public partial class WorkflowEditorTests + { + [TestMethod] + public void GetSubjectDefinition_NestedSubscribeSubject_ReturnsClosestDefinition() + { + var workflowBuilder = LoadEmbeddedWorkflow("NestedSubscribeSubjectWithClosestRedefinition.bonsai"); + var deferBuilder = workflowBuilder.Workflow.FindExpressionBuilder(); + Assert.IsNotNull(deferBuilder); + var selectManyBuilder = deferBuilder.Workflow.FindExpressionBuilder(); + Assert.IsNotNull(selectManyBuilder); + var definition = workflowBuilder.GetSubjectDefinition(selectManyBuilder.Workflow, "Values"); + Assert.IsNotNull(definition); + Assert.AreSame(deferBuilder.Workflow, definition.Root.Key); + } + } +} diff --git a/Bonsai.Editor.Tests/WorkflowEditorTests.cs b/Bonsai.Editor.Tests/WorkflowEditorTests.cs index bf037efd..4b4930d0 100644 --- a/Bonsai.Editor.Tests/WorkflowEditorTests.cs +++ b/Bonsai.Editor.Tests/WorkflowEditorTests.cs @@ -1,11 +1,9 @@ using System; using System.Collections.Generic; -using System.ComponentModel.Design; using System.IO; using System.Linq; using System.Xml; using Bonsai.Dag; -using Bonsai.Design; using Bonsai.Editor.GraphModel; using Bonsai.Expressions; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -13,7 +11,7 @@ namespace Bonsai.Editor.Tests { [TestClass] - public class WorkflowEditorTests + public partial class WorkflowEditorTests { static Stream LoadEmbeddedResource(string name) { diff --git a/Bonsai.Editor/ExportHelper.cs b/Bonsai.Editor/ExportHelper.cs index d8be2591..e5b8cf57 100644 --- a/Bonsai.Editor/ExportHelper.cs +++ b/Bonsai.Editor/ExportHelper.cs @@ -1,5 +1,4 @@ using System.Drawing; -using System.Linq; using System.Windows.Forms; using Bonsai.Editor.GraphModel; using Bonsai.Editor.GraphView; diff --git a/Bonsai.Editor/GraphModel/WorkflowBuilderExtensions.cs b/Bonsai.Editor/GraphModel/WorkflowBuilderExtensions.cs index e529feae..b6b8b8f0 100644 --- a/Bonsai.Editor/GraphModel/WorkflowBuilderExtensions.cs +++ b/Bonsai.Editor/GraphModel/WorkflowBuilderExtensions.cs @@ -51,7 +51,7 @@ from element in level let subjectBuilder = element.Builder as SubjectExpressionBuilder where subjectBuilder != null && subjectBuilder.Name == name select new SubjectDefinition(level, subjectBuilder, element.IsReadOnly)) - .LastOrDefault(); + .FirstOrDefault(); } return null; diff --git a/Bonsai/ScriptExtensionsEnvironment.cs b/Bonsai/ScriptExtensionsEnvironment.cs index f6d54f06..d73e331a 100644 --- a/Bonsai/ScriptExtensionsEnvironment.cs +++ b/Bonsai/ScriptExtensionsEnvironment.cs @@ -1,6 +1,5 @@ using Bonsai.Configuration; using Bonsai.Editor; -using System; using System.Collections.Generic; using System.Reflection;