Skip to content

Commit 7476c70

Browse files
committed
Add regression test for finding closest definition
1 parent d2f621a commit 7476c70

4 files changed

+102
-1
lines changed

Bonsai.Editor.Tests/EditorHelper.cs

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ internal static ExpressionBuilderGraph CreateEditorGraph(params string[] values)
2525
return graph.ToInspectableGraph();
2626
}
2727

28+
internal static TBuilder FindExpressionBuilder<TBuilder>(this ExpressionBuilderGraph workflow) where TBuilder : class
29+
{
30+
return (from node in workflow
31+
let builder = node.Value as TBuilder
32+
where builder != null
33+
select builder).FirstOrDefault();
34+
}
35+
2836
internal static GraphNode FindNode(this WorkflowEditor editor, string name)
2937
{
3038
var node = editor.Workflow.First(n => ExpressionBuilder.GetElementDisplayName(n.Value) == name);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<WorkflowBuilder Version="2.8.1"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
5+
xmlns="https://bonsai-rx.org/2018/workflow">
6+
<Workflow>
7+
<Nodes>
8+
<Expression xsi:type="Combinator">
9+
<Combinator xsi:type="IntProperty">
10+
<Value>8</Value>
11+
</Combinator>
12+
</Expression>
13+
<Expression xsi:type="rx:PublishSubject">
14+
<Name>Values</Name>
15+
</Expression>
16+
<Expression xsi:type="SubscribeSubject">
17+
<Name>Values</Name>
18+
</Expression>
19+
<Expression xsi:type="rx:Defer">
20+
<Workflow>
21+
<Nodes>
22+
<Expression xsi:type="WorkflowInput">
23+
<Name>Source1</Name>
24+
</Expression>
25+
<Expression xsi:type="Multiply">
26+
<Operand xsi:type="IntProperty">
27+
<Value>2</Value>
28+
</Operand>
29+
</Expression>
30+
<Expression xsi:type="rx:PublishSubject">
31+
<Name>Values</Name>
32+
</Expression>
33+
<Expression xsi:type="Combinator">
34+
<Combinator xsi:type="rx:Timer">
35+
<rx:DueTime>PT0S</rx:DueTime>
36+
<rx:Period>PT0S</rx:Period>
37+
</Combinator>
38+
</Expression>
39+
<Expression xsi:type="rx:SelectMany">
40+
<Workflow>
41+
<Nodes>
42+
<Expression xsi:type="WorkflowInput">
43+
<Name>Source1</Name>
44+
</Expression>
45+
<Expression xsi:type="SubscribeSubject">
46+
<Name>Values</Name>
47+
</Expression>
48+
<Expression xsi:type="WorkflowOutput" />
49+
</Nodes>
50+
<Edges>
51+
<Edge From="1" To="2" Label="Source1" />
52+
</Edges>
53+
</Workflow>
54+
</Expression>
55+
<Expression xsi:type="WorkflowOutput" />
56+
</Nodes>
57+
<Edges>
58+
<Edge From="0" To="1" Label="Source1" />
59+
<Edge From="1" To="2" Label="Source1" />
60+
<Edge From="3" To="4" Label="Source1" />
61+
<Edge From="4" To="5" Label="Source1" />
62+
</Edges>
63+
</Workflow>
64+
</Expression>
65+
</Nodes>
66+
<Edges>
67+
<Edge From="0" To="1" Label="Source1" />
68+
<Edge From="2" To="3" Label="Source1" />
69+
</Edges>
70+
</Workflow>
71+
</WorkflowBuilder>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Bonsai.Editor.GraphModel;
2+
using Bonsai.Reactive;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace Bonsai.Editor.Tests
6+
{
7+
public partial class WorkflowEditorTests
8+
{
9+
[TestMethod]
10+
public void GetSubjectDefinition_NestedSubscribeSubject_ReturnsClosestDefinition()
11+
{
12+
var workflowBuilder = LoadEmbeddedWorkflow("NestedSubscribeSubjectWithClosestRedefinition.bonsai");
13+
var deferBuilder = workflowBuilder.Workflow.FindExpressionBuilder<Defer>();
14+
Assert.IsNotNull(deferBuilder);
15+
var selectManyBuilder = deferBuilder.Workflow.FindExpressionBuilder<SelectMany>();
16+
Assert.IsNotNull(selectManyBuilder);
17+
var definition = workflowBuilder.GetSubjectDefinition(selectManyBuilder.Workflow, "Values");
18+
Assert.IsNotNull(definition);
19+
Assert.AreSame(deferBuilder.Workflow, definition.Root.Key);
20+
}
21+
}
22+
}

Bonsai.Editor.Tests/WorkflowEditorTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace Bonsai.Editor.Tests
1212
{
1313
[TestClass]
14-
public class WorkflowEditorTests
14+
public partial class WorkflowEditorTests
1515
{
1616
static Stream LoadEmbeddedResource(string name)
1717
{

0 commit comments

Comments
 (0)