private static void SaveWorkspaceComparisonData(WorkspaceComparisonData wcd1, string filePathBase, TimeSpan executionDuration) { var nodeData = new Dictionary <string, Dictionary <string, object> >(); foreach (var d in wcd1.NodeDataMap) { var t = wcd1.NodeTypeMap[d.Key]; var nodeDataDict = new Dictionary <string, object>(); nodeDataDict.Add("nodeType", t.ToString()); nodeDataDict.Add("portValues", d.Value); nodeData.Add(d.Key.ToString(), nodeDataDict); } var workspaceDataDict = new Dictionary <string, object>(); workspaceDataDict.Add("nodeData", nodeData); workspaceDataDict.Add("executionDuration", executionDuration.TotalSeconds); var dataMapStr = JsonConvert.SerializeObject(workspaceDataDict, new JsonSerializerSettings() { Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var dataPath = filePathBase + ".data"; if (File.Exists(dataPath)) { File.Delete(dataPath); } File.WriteAllText(dataPath, dataMapStr); }
private void CompareWorkspacesDifferentGuids(WorkspaceComparisonData a, WorkspaceComparisonData b) { var nodeDiff = a.NodeTypeMap.Select(x => x.Value).Except(b.NodeTypeMap.Select(x => x.Value)); if (nodeDiff.Any()) { Assert.Fail("The workspaces don't have the same number of nodes. The json workspace is missing: " + string.Join(",", nodeDiff.Select(i => i.ToString()))); } Assert.AreEqual(a.NodeCount, b.NodeCount, "The workspaces don't have the same number of nodes."); Assert.AreEqual(a.ConnectorCount, b.ConnectorCount, "The workspaces don't have the same number of connectors."); foreach (var kvp in a.InportCountMap) { var countA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var countB = b.InportCountMap[newGuid]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} inports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.OutportCountMap) { var countA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var countB = b.OutportCountMap[newGuid]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} outports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.NodeDataMap) { var valueA = kvp.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[kvp.Key]); var valueB = b.NodeDataMap[newGuid]; Assert.AreEqual(a.NodeTypeMap[kvp.Key], b.NodeTypeMap[newGuid]); try { // When values are geometry, sometimes the creation // of the string representation for forming this message // fails. Assert.AreEqual(valueA, valueB, string.Format("Node Type:{0} value, {1} is not equal to {2}", a.NodeTypeMap[kvp.Key], valueA, valueB)); } catch { continue; } } }
private void CompareWorkspaces(WorkspaceComparisonData a, WorkspaceComparisonData b) { var nodeDiff = a.NodeTypeMap.Except(b.NodeTypeMap); if (nodeDiff.Any()) { Assert.Fail("The workspaces don't have the same number of nodes. The json workspace is missing: " + string.Join(",", nodeDiff.Select(i => i.Value.ToString()))); } Assert.AreEqual(a.Description, b.Description, "The workspaces don't have the same description."); Assert.AreEqual(a.NodeCount, b.NodeCount, "The workspaces don't have the same number of nodes."); Assert.AreEqual(a.ConnectorCount, b.ConnectorCount, "The workspaces don't have the same number of connectors."); //TODO: Annotations / Note tests should be in viewmodel serialization tests. // Assert.AreEqual(a.GroupCount, b.GroupCount, "The workspaces don't have the same number of groups."); // Assert.AreEqual(a.NoteCount, b.NoteCount, "The workspaces don't have the same number of notes."); foreach (var kvp in a.InportCountMap) { var countA = kvp.Value; var countB = b.InportCountMap[kvp.Key]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} inports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.OutportCountMap) { var countA = kvp.Value; var countB = b.OutportCountMap[kvp.Key]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} outports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.NodeDataMap) { var valueA = kvp.Value; var valueB = b.NodeDataMap[kvp.Key]; Assert.AreEqual(a.NodeTypeMap[kvp.Key], b.NodeTypeMap[kvp.Key]); try { // When values are geometry, sometimes the creation // of the string representation for forming this message // fails. Assert.AreEqual(valueA, valueB, string.Format("Node Type:{0} value, {1} is not equal to {2}", a.NodeTypeMap[kvp.Key], valueA, valueB)); } catch { continue; } } }
private void CompareWorkspaces(WorkspaceComparisonData a, WorkspaceComparisonData b) { var nodeDiff = a.NodeTypeMap.Except(b.NodeTypeMap); if (nodeDiff.Any()) { Assert.Fail("The workspaces don't have the same number of nodes. The json workspace is missing: " + string.Join(",", nodeDiff.Select(i => i.Value.ToString()))); } Assert.AreEqual(a.NodeCount, b.NodeCount, "The workspaces don't have the same number of nodes."); Assert.AreEqual(a.ConnectorCount, b.ConnectorCount, "The workspaces don't have the same number of connectors."); Assert.AreEqual(a.GroupCount, b.GroupCount, "The workspaces don't have the same number of groups."); Assert.AreEqual(a.NoteCount, b.NoteCount, "The workspaces don't have the same number of notes."); foreach(var kvp in a.InportCountMap) { var countA = kvp.Value; var countB = b.InportCountMap[kvp.Key]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} inports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.OutportCountMap) { var countA = kvp.Value; var countB = b.OutportCountMap[kvp.Key]; Assert.AreEqual(countA, countB, string.Format("One {0} node has {1} outports, while the other has {2}", a.NodeTypeMap[kvp.Key], countA, countB)); } foreach (var kvp in a.NodeDataMap) { var valueA = kvp.Value; var valueB = b.NodeDataMap[kvp.Key]; Assert.AreEqual(a.NodeTypeMap[kvp.Key], b.NodeTypeMap[kvp.Key]); try { // When values are geometry, sometimes the creation // of the string representation for forming this message // fails. Assert.AreEqual(valueA, valueB, string.Format("Node Type:{0} value, {1} is not equal to {2}", a.NodeTypeMap[kvp.Key], valueA, valueB)); } catch { continue; } } }
private void SaveWorkspaceComparisonDataWithNonGuidIds(WorkspaceComparisonData wcd1, string filePathBase, TimeSpan executionDuration) { var nodeData = new Dictionary <string, Dictionary <string, object> >(); foreach (var d in wcd1.NodeDataMap) { var t = wcd1.NodeTypeMap[d.Key]; var nodeDataDict = new Dictionary <string, object>(); nodeDataDict.Add("nodeType", t.ToString()); nodeDataDict.Add("portValues", d.Value); nodeData.Add(d.Key.ToString(), nodeDataDict); } var workspaceDataDict = new Dictionary <string, object>(); workspaceDataDict.Add("nodeData", nodeData); workspaceDataDict.Add("executionDuration", executionDuration.TotalSeconds); var dataMapStr = JsonConvert.SerializeObject(workspaceDataDict, new JsonSerializerSettings() { Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); //replace all the guids in the data file with all of our remapped ids. foreach (var guidKey in modelsGuidToIdMap.Keys) { dataMapStr = dataMapStr.Replace(guidKey.ToString(), modelsGuidToIdMap[guidKey]); } var dataPath = filePathBase + ".data"; if (File.Exists(dataPath)) { File.Delete(dataPath); } File.WriteAllText(dataPath, dataMapStr); }
private void DoWorkspaceOpenAndCompare(string filePath) { var openPath = filePath; if (bannedTests.Any(t => filePath.Contains(t))) { Assert.Inconclusive("Skipping test known to kill the test framework..."); } OpenModel(openPath); var model = CurrentDynamoModel; var ws1 = model.CurrentWorkspace; var dummyNodes = ws1.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } var cbnErrorNodes = ws1.Nodes.Where(n => n is CodeBlockNodeModel && n.State == ElementState.Error); if (cbnErrorNodes.Any()) { Assert.Inconclusive("The Workspace contains code block nodes in error state due to which rest " + "of the graph will not execute; skipping test ..."); } if (((HomeWorkspaceModel)ws1).RunSettings.RunType == Models.RunType.Manual) { RunCurrentModel(); } var wcd1 = new WorkspaceComparisonData(ws1, CurrentDynamoModel.EngineController); var dirPath = Path.Combine(Path.GetTempPath(), "json"); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var fi = new FileInfo(filePath); var filePathBase = dirPath + @"\" + Path.GetFileNameWithoutExtension(fi.Name); ConvertCurrentWorkspaceToDesignScriptAndSave(filePathBase); string json = ConvertCurrentWorkspaceToJsonAndSave(model, filePathBase); SaveWorkspaceComparisonData(wcd1, filePathBase, lastExecutionDuration); lastExecutionDuration = new TimeSpan(); var ws2 = Autodesk.Workspaces.Utilities.LoadWorkspaceFromJson(json, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); if (ws2 is CustomNodeWorkspaceModel) { model.AddCustomNodeWorkspace((CustomNodeWorkspaceModel)ws2); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner, "The node is not set for the start of connector " + c.GUID + ". The end node is " + c.End.Owner + "."); Assert.NotNull(c.End.Owner, "The node is not set for the end of connector " + c.GUID + ". The start node is " + c.Start.Owner + "."); } // The following logic is taken from the DynamoModel.Open method. // It assumes a single home workspace model. So, we remove all // others, before adding a new one. if (ws2 is HomeWorkspaceModel) { var currentHomeSpaces = model.Workspaces.OfType <HomeWorkspaceModel>().ToList(); if (currentHomeSpaces.Any()) { var end = ws2 is HomeWorkspaceModel ? 0 : 1; for (var i = currentHomeSpaces.Count - 1; i >= end; i--) { model.RemoveWorkspace(currentHomeSpaces[i]); } } model.AddWorkspace(ws2); var hws = ws2 as HomeWorkspaceModel; if (hws != null) { model.ResetEngine(); if (hws.RunSettings.RunType == RunType.Periodic) { hws.StartPeriodicEvaluation(); } } model.CurrentWorkspace = ws2; } Assert.NotNull(ws2); dummyNodes = ws2.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } var wcd2 = new WorkspaceComparisonData(ws2, CurrentDynamoModel.EngineController); CompareWorkspaces(wcd1, wcd2); var functionNodes = ws2.Nodes.Where(n => n is Function).Cast <Function>(); if (functionNodes.Any()) { Assert.True(functionNodes.All(n => CurrentDynamoModel.CustomNodeManager.LoadedDefinitions.Contains(n.Definition))); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner); Assert.NotNull(c.End.Owner); Assert.True(ws2.Nodes.Contains(c.Start.Owner)); Assert.True(ws2.Nodes.Contains(c.End.Owner)); } }
private void DoWorkspaceOpenAndCompare(string filePath) { var openPath = filePath; var bannedTests = new List<string>() { "NestedIF", "recorded", "excel", "CASE", "WatchPreviewBubble", "visualization", "migration", "missing_custom_node", "Dummy.dyn", // Tests which require late initialization // of custom nodes... "noro.dyn", "Number1.dyn", "MultipleIF", "packageTest" }; if (bannedTests.Any(t=>filePath.Contains(t))) { Assert.Inconclusive("Skipping test known to kill the test framework..."); } // Find the version in the root /*var xmlDoc = new XmlDocument(); xmlDoc.Load(openPath); WorkspaceInfo info; if(WorkspaceInfo.FromXmlDocument(xmlDoc, openPath, false, false, CurrentDynamoModel.Logger, out info)) { if (Version.Parse(info.Version) < new Version(1, 0)) { Assert.Inconclusive("The test file was from before version 1.0."); } }*/ OpenModel(openPath); var model = CurrentDynamoModel; var ws1 = model.CurrentWorkspace; var dummyNodes = ws1.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } if (((HomeWorkspaceModel)ws1).RunSettings.RunType== Models.RunType.Manual) { RunCurrentModel(); } var wcd1 = new WorkspaceComparisonData(ws1); var json = Autodesk.Workspaces.Utilities.SaveWorkspaceToJson(model.CurrentWorkspace, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); Assert.IsNotNullOrEmpty(json); var fi = new FileInfo(filePath); var tempPath = Path.GetTempPath(); var jsonFolder = Path.Combine(tempPath, "json"); if (!Directory.Exists(jsonFolder)) { Directory.CreateDirectory(jsonFolder); } var jsonPath = Path.Combine(Path.GetTempPath() + @"\json\" + Path.GetFileNameWithoutExtension(fi.Name) + ".json"); if (File.Exists(jsonPath)) { File.Delete(jsonPath); } File.WriteAllText(jsonPath, json); var ws2 = Autodesk.Workspaces.Utilities.LoadWorkspaceFromJson(json, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); if (ws2 is CustomNodeWorkspaceModel) { model.AddCustomNodeWorkspace((CustomNodeWorkspaceModel)ws2); } foreach(var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner, "The node is not set for the start of connector " + c.GUID + ". The end node is " + c.End.Owner + "."); Assert.NotNull(c.End.Owner, "The node is not set for the end of connector " + c.GUID + ". The start node is " + c.Start.Owner + "."); } // The following logic is taken from the DynamoModel.Open method. // It assumes a single home workspace model. So, we remove all // others, before adding a new one. if (ws2 is HomeWorkspaceModel) { var currentHomeSpaces = model.Workspaces.OfType<HomeWorkspaceModel>().ToList(); if (currentHomeSpaces.Any()) { var end = ws2 is HomeWorkspaceModel ? 0 : 1; for (var i = currentHomeSpaces.Count - 1; i >= end; i--) { model.RemoveWorkspace(currentHomeSpaces[i]); } } model.AddWorkspace(ws2); var hws = ws2 as HomeWorkspaceModel; if (hws != null) { model.ResetEngine(); if (hws.RunSettings.RunType == RunType.Periodic) { hws.StartPeriodicEvaluation(); } } model.CurrentWorkspace = ws2; } Assert.NotNull(ws2); dummyNodes = ws2.Nodes.Where(n => n is DummyNode); if(dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",",dummyNodes.Select(n=>n.NickName).ToArray())); } var wcd2 = new WorkspaceComparisonData(ws2); CompareWorkspaces(wcd1, wcd2); var functionNodes = ws2.Nodes.Where(n => n is Function).Cast<Function>(); if(functionNodes.Any()) { Assert.True(functionNodes.All(n => CurrentDynamoModel.CustomNodeManager.LoadedDefinitions.Contains(n.Definition))); } foreach(var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner); Assert.NotNull(c.End.Owner); Assert.True(ws2.Nodes.Contains(c.Start.Owner)); Assert.True(ws2.Nodes.Contains(c.End.Owner)); } }
private void DoWorkspaceOpenAndCompare(string filePath) { var openPath = filePath; var bannedTests = new List <string>() { "NestedIF", "recorded", "excel", "CASE", "WatchPreviewBubble", "visualization", "migration", "missing_custom_node", "Dummy.dyn", // Tests which require late initialization // of custom nodes... "noro.dyn", "Number1.dyn", "MultipleIF", "packageTest" }; if (bannedTests.Any(t => filePath.Contains(t))) { Assert.Inconclusive("Skipping test known to kill the test framework..."); } // Find the version in the root /*var xmlDoc = new XmlDocument(); * xmlDoc.Load(openPath); * WorkspaceInfo info; * if(WorkspaceInfo.FromXmlDocument(xmlDoc, openPath, false, false, CurrentDynamoModel.Logger, out info)) * { * if (Version.Parse(info.Version) < new Version(1, 0)) * { * Assert.Inconclusive("The test file was from before version 1.0."); * } * }*/ OpenModel(openPath); var model = CurrentDynamoModel; var ws1 = model.CurrentWorkspace; var dummyNodes = ws1.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } if (((HomeWorkspaceModel)ws1).RunSettings.RunType == Models.RunType.Manual) { RunCurrentModel(); } var wcd1 = new WorkspaceComparisonData(ws1); var json = Autodesk.Workspaces.Utilities.SaveWorkspaceToJson(model.CurrentWorkspace, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); Assert.IsNotNullOrEmpty(json); var fi = new FileInfo(filePath); var tempPath = Path.GetTempPath(); var jsonFolder = Path.Combine(tempPath, "json"); if (!Directory.Exists(jsonFolder)) { Directory.CreateDirectory(jsonFolder); } var jsonPath = Path.Combine(Path.GetTempPath() + @"\json\" + Path.GetFileNameWithoutExtension(fi.Name) + ".json"); if (File.Exists(jsonPath)) { File.Delete(jsonPath); } File.WriteAllText(jsonPath, json); var ws2 = Autodesk.Workspaces.Utilities.LoadWorkspaceFromJson(json, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); if (ws2 is CustomNodeWorkspaceModel) { model.AddCustomNodeWorkspace((CustomNodeWorkspaceModel)ws2); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner, "The node is not set for the start of connector " + c.GUID + ". The end node is " + c.End.Owner + "."); Assert.NotNull(c.End.Owner, "The node is not set for the end of connector " + c.GUID + ". The start node is " + c.Start.Owner + "."); } // The following logic is taken from the DynamoModel.Open method. // It assumes a single home workspace model. So, we remove all // others, before adding a new one. if (ws2 is HomeWorkspaceModel) { var currentHomeSpaces = model.Workspaces.OfType <HomeWorkspaceModel>().ToList(); if (currentHomeSpaces.Any()) { var end = ws2 is HomeWorkspaceModel ? 0 : 1; for (var i = currentHomeSpaces.Count - 1; i >= end; i--) { model.RemoveWorkspace(currentHomeSpaces[i]); } } model.AddWorkspace(ws2); var hws = ws2 as HomeWorkspaceModel; if (hws != null) { model.ResetEngine(); if (hws.RunSettings.RunType == RunType.Periodic) { hws.StartPeriodicEvaluation(); } } model.CurrentWorkspace = ws2; } Assert.NotNull(ws2); dummyNodes = ws2.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } var wcd2 = new WorkspaceComparisonData(ws2); CompareWorkspaces(wcd1, wcd2); var functionNodes = ws2.Nodes.Where(n => n is Function).Cast <Function>(); if (functionNodes.Any()) { Assert.True(functionNodes.All(n => CurrentDynamoModel.CustomNodeManager.LoadedDefinitions.Contains(n.Definition))); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner); Assert.NotNull(c.End.Owner); Assert.True(ws2.Nodes.Contains(c.Start.Owner)); Assert.True(ws2.Nodes.Contains(c.End.Owner)); } }
private void DoWorkspaceOpenAndCompare(string filePath, string dirName, Func <DynamoModel, string, string> saveFunction, Action <WorkspaceComparisonData, WorkspaceComparisonData> workspaceCompareFunction, Action <WorkspaceComparisonData, string, TimeSpan> workspaceDataSaveFunction) { var openPath = filePath; if (bannedTests.Any(t => filePath.Contains(t))) { Assert.Inconclusive("Skipping test known to kill the test framework..."); } OpenModel(openPath); var model = CurrentDynamoModel; var ws1 = model.CurrentWorkspace; ws1.Description = "TestDescription"; var dummyNodes = ws1.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.Name).ToArray())); } var cbnErrorNodes = ws1.Nodes.Where(n => n is CodeBlockNodeModel && n.State == ElementState.Error); if (cbnErrorNodes.Any()) { Assert.Inconclusive("The Workspace contains code block nodes in error state due to which rest " + "of the graph will not execute; skipping test ..."); } if (((HomeWorkspaceModel)ws1).RunSettings.RunType == Models.RunType.Manual) { RunCurrentModel(); } var wcd1 = new WorkspaceComparisonData(ws1, CurrentDynamoModel.EngineController); var dirPath = Path.Combine(Path.GetTempPath(), dirName); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } var fi = new FileInfo(filePath); var filePathBase = dirPath + @"\" + Path.GetFileNameWithoutExtension(fi.Name); ConvertCurrentWorkspaceToDesignScriptAndSave(filePathBase); string json = saveFunction(model, filePathBase); workspaceDataSaveFunction(wcd1, filePathBase, lastExecutionDuration); lastExecutionDuration = new TimeSpan(); var ws2 = WorkspaceModel.FromJson(json, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); if (ws2 is CustomNodeWorkspaceModel) { model.AddCustomNodeWorkspace((CustomNodeWorkspaceModel)ws2); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner, "The node is not set for the start of connector " + c.GUID + ". The end node is " + c.End.Owner + "."); Assert.NotNull(c.End.Owner, "The node is not set for the end of connector " + c.GUID + ". The start node is " + c.Start.Owner + "."); } // The following logic is taken from the DynamoModel.Open method. // It assumes a single home workspace model. So, we remove all // others, before adding a new one. if (ws2 is HomeWorkspaceModel) { var currentHomeSpaces = model.Workspaces.OfType <HomeWorkspaceModel>().ToList(); if (currentHomeSpaces.Any()) { var end = ws2 is HomeWorkspaceModel ? 0 : 1; for (var i = currentHomeSpaces.Count - 1; i >= end; i--) { model.RemoveWorkspace(currentHomeSpaces[i]); } } model.AddWorkspace(ws2); var hws = ws2 as HomeWorkspaceModel; if (hws != null) { model.ResetEngine(); if (hws.RunSettings.RunType == RunType.Periodic) { hws.StartPeriodicEvaluation(); } } model.CurrentWorkspace = ws2; } Assert.NotNull(ws2); dummyNodes = ws2.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.Name).ToArray())); } var wcd2 = new WorkspaceComparisonData(ws2, CurrentDynamoModel.EngineController); workspaceCompareFunction(wcd1, wcd2); var functionNodes = ws2.Nodes.Where(n => n is Function).Cast <Function>(); if (functionNodes.Any()) { Assert.True(functionNodes.All(n => CurrentDynamoModel.CustomNodeManager.LoadedDefinitions.Contains(n.Definition))); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner); Assert.NotNull(c.End.Owner); Assert.True(ws2.Nodes.Contains(c.Start.Owner)); Assert.True(ws2.Nodes.Contains(c.End.Owner)); } //assert that the inputs in the saved json file are the same as those we can gather from the //grah at runtime - because we don't deserialize these directly we check the json itself. var jObject = JObject.Parse(json); var jToken = jObject["Inputs"]; var inputs = jToken.ToArray().Select(x => x.ToObject <NodeInputData>()).ToList(); var inputs2 = ws1.Nodes.Where(x => x.IsSetAsInput == true).Select(input => input.InputData).ToList(); Assert.IsTrue(inputs.SequenceEqual(inputs2)); }
private static void SaveWorkspaceComparisonData(WorkspaceComparisonData wcd1, string filePathBase, TimeSpan executionDuration) { var nodeData = new Dictionary<string, Dictionary<string, object>>(); foreach(var d in wcd1.NodeDataMap) { var t = wcd1.NodeTypeMap[d.Key]; var nodeDataDict = new Dictionary<string, object>(); nodeDataDict.Add("nodeType", t.ToString()); nodeDataDict.Add("portValues", d.Value); nodeData.Add(d.Key.ToString(), nodeDataDict); } var workspaceDataDict = new Dictionary<string, object>(); workspaceDataDict.Add("nodeData", nodeData); workspaceDataDict.Add("executionDuration", executionDuration); var dataMapStr = JsonConvert.SerializeObject(workspaceDataDict, new JsonSerializerSettings() { Formatting = Formatting.Indented, ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); var dataPath = filePathBase + ".data"; if (File.Exists(dataPath)) { File.Delete(dataPath); } File.WriteAllText(dataPath, dataMapStr); }
private void DoWorkspaceOpenAndCompare(string filePath) { var openPath = filePath; if (bannedTests.Any(t => filePath.Contains(t))) { Assert.Inconclusive("Skipping test known to kill the test framework..."); } OpenModel(openPath); var model = CurrentDynamoModel; var ws1 = model.CurrentWorkspace; var dummyNodes = ws1.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } var cbnErrorNodes = ws1.Nodes.Where(n => n is CodeBlockNodeModel && n.State == ElementState.Error); if (cbnErrorNodes.Any()) { Assert.Inconclusive("The Workspace contains code block nodes in error state due to which rest " + "of the graph will not execute; skipping test ..."); } if (((HomeWorkspaceModel)ws1).RunSettings.RunType== Models.RunType.Manual) { RunCurrentModel(); } var wcd1 = new WorkspaceComparisonData(ws1, CurrentDynamoModel.EngineController); var fi = new FileInfo(filePath); var filePathBase = Path.Combine(Path.GetTempPath() + @"\json\" + Path.GetFileNameWithoutExtension(fi.Name)); ConvertCurrentWorkspaceToDesignScriptAndSave(filePathBase); string json = ConvertCurrentWorkspaceToJsonAndSave(model, filePathBase); SaveWorkspaceComparisonData(wcd1, filePathBase, lastExecutionDuration); lastExecutionDuration = new TimeSpan(); var ws2 = Autodesk.Workspaces.Utilities.LoadWorkspaceFromJson(json, model.LibraryServices, model.EngineController, model.Scheduler, model.NodeFactory, DynamoModel.IsTestMode, false, model.CustomNodeManager); if (ws2 is CustomNodeWorkspaceModel) { model.AddCustomNodeWorkspace((CustomNodeWorkspaceModel)ws2); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner, "The node is not set for the start of connector " + c.GUID + ". The end node is " + c.End.Owner + "."); Assert.NotNull(c.End.Owner, "The node is not set for the end of connector " + c.GUID + ". The start node is " + c.Start.Owner + "."); } // The following logic is taken from the DynamoModel.Open method. // It assumes a single home workspace model. So, we remove all // others, before adding a new one. if (ws2 is HomeWorkspaceModel) { var currentHomeSpaces = model.Workspaces.OfType<HomeWorkspaceModel>().ToList(); if (currentHomeSpaces.Any()) { var end = ws2 is HomeWorkspaceModel ? 0 : 1; for (var i = currentHomeSpaces.Count - 1; i >= end; i--) { model.RemoveWorkspace(currentHomeSpaces[i]); } } model.AddWorkspace(ws2); var hws = ws2 as HomeWorkspaceModel; if (hws != null) { model.ResetEngine(); if (hws.RunSettings.RunType == RunType.Periodic) { hws.StartPeriodicEvaluation(); } } model.CurrentWorkspace = ws2; } Assert.NotNull(ws2); dummyNodes = ws2.Nodes.Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.NickName).ToArray())); } var wcd2 = new WorkspaceComparisonData(ws2, CurrentDynamoModel.EngineController); CompareWorkspaces(wcd1, wcd2); var functionNodes = ws2.Nodes.Where(n => n is Function).Cast<Function>(); if (functionNodes.Any()) { Assert.True(functionNodes.All(n => CurrentDynamoModel.CustomNodeManager.LoadedDefinitions.Contains(n.Definition))); } foreach (var c in ws2.Connectors) { Assert.NotNull(c.Start.Owner); Assert.NotNull(c.End.Owner); Assert.True(ws2.Nodes.Contains(c.Start.Owner)); Assert.True(ws2.Nodes.Contains(c.End.Owner)); } }