private void CompareWorkspaceViews(WorkspaceViewComparisonData a, WorkspaceViewComparisonData b) { //first compare the model data serializationTestUtils.CompareWorkspaceModels(a, b, this.modelsGuidToIdMap); Assert.IsTrue(Math.Abs(a.X - b.X) < .00001, "The workspaces don't have the same X offset."); Assert.IsTrue(Math.Abs(a.X - b.X) < .00001, "The workspaces don't have the same Y offset."); Assert.IsTrue(Math.Abs(a.Zoom - b.Zoom) < .00001, "The workspaces don't have the same Zoom."); Assert.AreEqual(a.Camera, b.Camera); Assert.AreEqual(a.Guid, b.Guid); Assert.AreEqual(a.NodeViewCount, b.NodeViewCount, "The workspaces don't have the same number of node views."); Assert.AreEqual(a.ConnectorViewCount, b.ConnectorViewCount, "The workspaces don't have the same number of connector views."); Assert.AreEqual(a.AnnotationMap.Count, b.AnnotationMap.Count); foreach (var annotationKVP in a.AnnotationMap) { var dataA = a.AnnotationMap[annotationKVP.Key]; var dataB = b.AnnotationMap[annotationKVP.Key]; Assert.AreEqual(dataA, dataB); } foreach (var kvp in a.NodeViewDataMap) { var valueA = kvp.Value; var valueB = b.NodeViewDataMap[kvp.Key]; Assert.AreEqual(valueA, valueB, string.Format("Node View Data:{0} value, {1} is not equal to {2}", a.NodeViewDataMap[kvp.Key].Name, valueA, valueB)); } }
private void CompareWorkspaceViewsDifferentGuids(WorkspaceViewComparisonData a, WorkspaceViewComparisonData b) { //first compare the model data serializationTestUtils.CompareWorkspacesDifferentGuids(a, b, this.modelsGuidToIdMap); Assert.IsTrue(Math.Abs(a.X - b.X) < .00001, "The workspaces don't have the same X offset."); Assert.IsTrue(Math.Abs(a.X - b.X) < .00001, "The workspaces don't have the same Y offset."); Assert.IsTrue(Math.Abs(a.Zoom - b.Zoom) < .00001, "The workspaces don't have the same Zoom."); Assert.AreEqual(a.Camera, b.Camera); Assert.AreEqual(a.Guid, b.Guid); Assert.AreEqual(a.NodeViewCount, b.NodeViewCount, "The workspaces don't have the same number of node views."); Assert.AreEqual(a.ConnectorViewCount, b.ConnectorViewCount, "The workspaces don't have the same number of connector views."); Assert.AreEqual(a.AnnotationMap.Count, b.AnnotationMap.Count); foreach (var annotationKVP in a.AnnotationMap) { var valueA = annotationKVP.Value; //convert the old guid to the new guid var newGuid = GuidUtility.Create(GuidUtility.UrlNamespace, this.modelsGuidToIdMap[annotationKVP.Key]); var valueB = b.AnnotationMap[newGuid]; //set the id explicitly since we know it will have changed and should be this id. valueB.Id = valueA.Id.ToString(); //check at least that number of referenced nodes is correct. Assert.AreEqual(valueB.Nodes.Count(), valueA.Nodes.Count()); //ignore this list because all node ids will have changed. valueB.Nodes = valueA.Nodes; Assert.AreEqual(valueA, valueB); } foreach (var kvp in a.NodeViewDataMap) { 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.NodeViewDataMap[newGuid]; //set the id explicitly since we know it will have changed and should be this id. valueB.ID = valueA.ID.ToString(); Assert.AreEqual(valueA, valueB, string.Format("Node View Data:{0} value, {1} is not equal to {2}", a.NodeViewDataMap[kvp.Key].Name, valueA, valueB)); } }
private void DoWorkspaceOpenAndCompareView(string filePath, string dirName, Func <DynamoViewModel, string, string> saveFunction, Action <WorkspaceViewComparisonData, WorkspaceViewComparisonData> workspaceViewCompareFunction, Action <WorkspaceViewComparisonData, string, TimeSpan, Dictionary <Guid, string> > workspaceViewDataSaveFunction) { var openPath = filePath; DoWorkspaceOpen(openPath); var ws1 = ViewModel.CurrentSpaceViewModel; var wcd1 = new WorkspaceViewComparisonData(ws1, ViewModel.Model.EngineController); var dirPath = Path.Combine(Path.GetTempPath(), dirName); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); } var fi = new FileInfo(filePath); var filePathBase = dirPath + @"\" + Path.GetFileNameWithoutExtension(fi.Name); //no longer do this, as its done in model serialization tests. //ConvertCurrentWorkspaceToDesignScriptAndSave(filePathBase); string json = saveFunction(this.ViewModel, filePath); workspaceViewDataSaveFunction(wcd1, filePathBase, lastExecutionDuration, this.modelsGuidToIdMap); lastExecutionDuration = new TimeSpan(); // Open JSON .dyn or .dyf var fileExtension = Path.GetExtension(filePath); this.ViewModel.OpenCommand.Execute(filePathBase + fileExtension); var ws2 = ViewModel.CurrentSpaceViewModel; Assert.NotNull(ws2); var dummyNodes = ws2.Nodes.Select(x => x.NodeModel).Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.Name).ToArray())); } if (((HomeWorkspaceModel)ws2.Model).RunSettings.RunType == RunType.Manual) { RunCurrentModel(); } var wcd2 = new WorkspaceViewComparisonData(ws2, this.ViewModel.EngineController); workspaceViewCompareFunction(wcd1, wcd2); //TODO remove this after we merge notes and annotations - //this is done here so we don't need to modify the workspaceComparison classes //and it's simple to remove soon. var index = 0; foreach (var noteView in ws1.Notes) { var matchingNote = ws2.Notes[index]; Assert.IsTrue(noteView.Model.Text == matchingNote.Model.Text); Assert.Less(Math.Abs(noteView.Model.X - matchingNote.Model.X), 0001); Assert.Less(Math.Abs(noteView.Model.Y - matchingNote.Model.Y), 0001); index = index + 1; } }
private void DoWorkspaceOpenAndCompareView(string filePath, string dirName, Func <DynamoViewModel, string, string> saveFunction, Action <WorkspaceViewComparisonData, WorkspaceViewComparisonData> workspaceViewCompareFunction, Action <WorkspaceViewComparisonData, string, TimeSpan, Dictionary <Guid, string> > workspaceViewDataSaveFunction) { var openPath = filePath; if (Dynamo.Tests.SerializationTests.bannedTests.Any(t => filePath.Contains(t))) { Assert.Inconclusive("Skipping test known to kill the test framework..."); } OpenModel(openPath); var model = this.ViewModel.Model; var ws1 = ViewModel.CurrentSpaceViewModel; ws1.Model.Description = "TestDescription"; var dummyNodes = ws1.Nodes.Select(x => x.NodeModel).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.NodeModel is CodeBlockNodeModel && n.NodeModel.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.Model).RunSettings.RunType == RunType.Manual) { RunCurrentModel(); } var wcd1 = new WorkspaceViewComparisonData(ws1, model.EngineController); var dirPath = Path.Combine(Path.GetTempPath(), dirName); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); } var fi = new FileInfo(filePath); var filePathBase = dirPath + @"\" + Path.GetFileNameWithoutExtension(fi.Name); //no longer do this, as its done in model serialization tests. //ConvertCurrentWorkspaceToDesignScriptAndSave(filePathBase); string json = saveFunction(this.ViewModel, filePathBase); workspaceViewDataSaveFunction(wcd1, filePathBase, lastExecutionDuration, this.modelsGuidToIdMap); lastExecutionDuration = new TimeSpan(); //make sure we're opening the json here this.ViewModel.OpenCommand.Execute(filePathBase + ".dyn"); var ws2 = ViewModel.CurrentSpaceViewModel; Assert.NotNull(ws2); dummyNodes = ws2.Nodes.Select(x => x.NodeModel).Where(n => n is DummyNode); if (dummyNodes.Any()) { Assert.Inconclusive("The Workspace contains dummy nodes for: " + string.Join(",", dummyNodes.Select(n => n.Name).ToArray())); } if (((HomeWorkspaceModel)ws2.Model).RunSettings.RunType == RunType.Manual) { RunCurrentModel(); } var wcd2 = new WorkspaceViewComparisonData(ws2, this.ViewModel.EngineController); workspaceViewCompareFunction(wcd1, wcd2); //TODO remove this after we merge notes and annotations - //this is done here so we don't need to modify the workspaceComparison classes //and it's simple to remove soon. var index = 0; foreach (var noteView in ws1.Notes) { var matchingNote = ws2.Notes[index]; Assert.IsTrue(noteView.Model.Text == matchingNote.Model.Text); Assert.Less(Math.Abs(noteView.Model.X - matchingNote.Model.X), 0001); Assert.Less(Math.Abs(noteView.Model.Y - matchingNote.Model.Y), 0001); index = index + 1; } }