Skip to content

Commit

Permalink
fix bug (#13423)
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
mjkkirschner authored Oct 25, 2022
1 parent 08cf03e commit 8c52b67
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -604,6 +604,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
if (obj[NodeLibraryDependenciesPropString] != null)
{
workspaceReferences = obj[NodeLibraryDependenciesPropString].ToObject<IEnumerable<INodeLibraryDependencyInfo>>(serializer);
//if deserialization failed, reset to empty.
if (workspaceReferences == null)
{
workspaceReferences = new List<INodeLibraryDependencyInfo>();
}
}
else
{
Expand Down
23 changes: 22 additions & 1 deletion test/DynamoCoreTests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -650,6 +650,27 @@ public void ConverterDoesNotThrowWithNullEngine()
CurrentDynamoModel.AddHomeWorkspace();
Assert.DoesNotThrow(() => { CurrentDynamoModel.CurrentWorkspace.ToJson(null); });
}
[Test]
public void NullWorkspaceRefsDeserializedAsEmpty()
{

var testFile = Path.Combine(TestDirectory, @"core\serialization\nullWorkspaceRefs.dyn");
var json = File.ReadAllText(testFile);

Assert.DoesNotThrow(() =>
{
var ws = WorkspaceModel.FromJson(
json, this.CurrentDynamoModel.LibraryServices,
null,
null,
this.CurrentDynamoModel.NodeFactory,
true,
true,
this.CurrentDynamoModel.CustomNodeManager);
Assert.NotNull(ws);
});
}

[Test]
public void ReadConverterDoesNotThrowWithNullEngineAndScheduler()
Expand Down
61 changes: 61 additions & 0 deletions test/core/serialization/nullWorkspaceRefs.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"Uuid": "077eb433-543f-4cc7-bc2a-91fcaea5687e",
"IsCustomNode": false,
"Description": "",
"Name": "broken",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [],
"Connectors": [],
"Dependencies": [],
"NodeLibraryDependencies": null,
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.16",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "2.16.0.1926",
"RunType": "Automatic",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"ConnectorPins": [],
"NodeViews": [],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}

0 comments on commit 8c52b67

Please sign in to comment.