Skip to content

Commit

Permalink
Merge pull request #157 from SainsburyWellcomeCentre/issue-156
Browse files Browse the repository at this point in the history
Include resource name in unit test serialization errors
  • Loading branch information
glopesdev authored Oct 13, 2023
2 parents cc1c896 + 6aed837 commit a3d7cfd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Aeon.Foraging/Aeon.Foraging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageTags>Bonsai Rx Project Aeon Foraging</PackageTags>
<TargetFramework>net472</TargetFramework>
<VersionPrefix>0.1.0</VersionPrefix>
<VersionSuffix>build231007</VersionSuffix>
<VersionSuffix>build231008</VersionSuffix>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/Aeon.Foraging/LinearDepletion.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<WorkflowBuilder Version="2.7.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aeon="clr-namespace:Aeon.Acquisition;assembly=Aeon.Acquisition"
xmlns:aeon-env="clr-namespace:Aeon.Environment;assembly=Aeon.Environment"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
Expand Down Expand Up @@ -31,7 +32,7 @@
<Selector>Value.Type</Selector>
</Expression>
<Expression xsi:type="Equal">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon:EnvironmentStateType">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon-env:EnvironmentStateType">
<Value>Experiment</Value>
</Operand>
</Expression>
Expand Down Expand Up @@ -92,7 +93,7 @@
<Selector>Value.Type</Selector>
</Expression>
<Expression xsi:type="Equal">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon:EnvironmentSubjectChangeType">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon-env:EnvironmentSubjectChangeType">
<Value>Enter</Value>
</Operand>
</Expression>
Expand Down
5 changes: 3 additions & 2 deletions src/Aeon.Foraging/RandomDepletion.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<WorkflowBuilder Version="2.7.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aeon="clr-namespace:Aeon.Acquisition;assembly=Aeon.Acquisition"
xmlns:aeon-env="clr-namespace:Aeon.Environment;assembly=Aeon.Environment"
xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
Expand Down Expand Up @@ -32,7 +33,7 @@
<Selector>Value.Type</Selector>
</Expression>
<Expression xsi:type="Equal">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon:EnvironmentStateType">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon-env:EnvironmentStateType">
<Value>Experiment</Value>
</Operand>
</Expression>
Expand Down Expand Up @@ -93,7 +94,7 @@
<Selector>Value.Type</Selector>
</Expression>
<Expression xsi:type="Equal">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon:EnvironmentSubjectChangeType">
<Operand xsi:type="WorkflowProperty" TypeArguments="aeon-env:EnvironmentSubjectChangeType">
<Value>Enter</Value>
</Operand>
</Expression>
Expand Down
2 changes: 1 addition & 1 deletion src/Aeon.Tests/Aeon.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<TargetFramework>net472</TargetFramework>
<Version>0.3.0</Version>
<Version>0.5.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
22 changes: 21 additions & 1 deletion src/Aeon.Tests/AssertWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Bonsai.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Aeon.Acquisition;
using System;

namespace Aeon.Tests
{
Expand All @@ -23,7 +24,17 @@ public static void CanBuildEmbeddedResources(Assembly assembly)
using (var reader = XmlReader.Create(workflowStream))
{
reader.MoveToContent();
var workflowBuilder = (WorkflowBuilder)WorkflowBuilder.Serializer.Deserialize(reader);
WorkflowBuilder workflowBuilder;
try { workflowBuilder = (WorkflowBuilder)WorkflowBuilder.Serializer.Deserialize(reader); }
catch (Exception ex)
{
var message = ex.ToString().Split(
new[] { System.Environment.NewLine },
StringSplitOptions.None)[0];
Assert.Fail($"Embedded workflow {name} threw exception:\n{message}");
break;
}

workflowBuilder.Workflow.Convert(builder =>
{
var workflowElement = ExpressionBuilder.GetWorkflowElement(builder);
Expand All @@ -36,6 +47,15 @@ public static void CanBuildEmbeddedResources(Assembly assembly)
assembly.GetManifestResourceStream(resourceName),
$"Embedded workflow: {name}. Missing resource name: {resourceName}");
}
else if (workflowElement is BinaryOperatorBuilder binaryOperator &&
binaryOperator.Operand is WorkflowProperty operand &&
operand.GetType().IsGenericType)
{
var valueType = operand.GetType().GetGenericArguments()[0];
Assert.IsFalse(
typeof(UnknownTypeBuilder).IsAssignableFrom(valueType),
$"Binary operator operand is unknown: {valueType}. Embedded workflow: {name}.");
}
if (workflowElement.GetType().Name != nameof(SpinnakerCapture) &&
workflowElement.GetType().Name != nameof(PylonCapture) &&
Expand Down

0 comments on commit a3d7cfd

Please sign in to comment.