-
Notifications
You must be signed in to change notification settings - Fork 635
/
RecordedTests.cs
5654 lines (4668 loc) · 229 KB
/
RecordedTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Threading;
using CoreNodeModels.Input;
using Dynamo;
using Dynamo.Configuration;
using Dynamo.Controls;
using Dynamo.Graph;
using Dynamo.Graph.Connectors;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Notes;
using Dynamo.Graph.Workspaces;
using Dynamo.Models;
using Dynamo.Scheduler;
using Dynamo.Tests;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using DynamoShapeManager;
using NUnit.Framework;
using ProtoCore;
using PythonNodeModels;
using SystemTestServices;
using TestServices;
namespace DynamoCoreWpfTests
{
public delegate void CommandCallback(string commandTag);
public class RecordedUnitTestBase : DynamoViewModelUnitTest
{
#region Generic Set-up Routines and Data Members
protected System.Random randomizer = null;
private IEnumerable<string> customNodesToBeLoaded;
private CommandCallback commandCallback;
// Geometry preloading related members.
protected bool preloadGeometry;
// For access within test cases.
protected DynamoView dynamoView = null;
protected WorkspaceModel workspace = null;
protected WorkspaceViewModel workspaceViewModel = null;
protected double tolerance = 1e-6;
protected double codeBlockPortHeight = Configurations.PortHeightInPixels;
public override void Setup()
{
base.Setup();
// Fixed seed randomizer for predictability.
randomizer = new System.Random(123456);
}
public override void Cleanup()
{
commandCallback = null;
base.Cleanup();
}
#endregion
#region Private Helper Methods
protected ModelBase GetNode(string guid)
{
Guid id = Guid.Parse(guid);
return ViewModel.Model.CurrentWorkspace.GetModelInternal(id);
}
/// <summary>
/// Call this method to load custom nodes from their file paths. This
/// call, if made, must precede the call to RunCommandsFromFile. This
/// call cannot be made more than once for a single test case. If more
/// than one custom node files are needed for the test case, they must
/// be specified in the same call.
/// </summary>
/// <param name="customNodeFilePaths">And array of custom node file paths.
/// This array cannot be null or empty.</param>
///
protected void LoadCustomNodes(string[] customNodeFilePaths)
{
if (customNodeFilePaths == null || (customNodeFilePaths.Length <= 0))
{
var message = "Argument must be one or more valid file paths";
throw new ArgumentException(message);
}
if (this.customNodesToBeLoaded != null)
throw new InvalidOperationException("LoadCustomNodes called twice");
if (this.ViewModel != null)
{
var message = "'LoadCustomNodes' should be called before 'RunCommandsFromFile'";
throw new InvalidOperationException(message);
}
var fileList = new List<string>();
foreach (var customNodeFilePath in customNodeFilePaths)
{
if (File.Exists(customNodeFilePath) != false)
{
fileList.Add(customNodeFilePath);
continue;
}
var message = "Custom node file not found";
throw new System.IO.FileNotFoundException(message, customNodeFilePath);
}
this.customNodesToBeLoaded = fileList;
}
protected override void GetLibrariesToPreload(List<string> libraries)
{
libraries.Add("DesignScriptBuiltin.dll");
libraries.Add("DSCoreNodes.dll");
libraries.Add("FFITarget.dll");
libraries.Add("DSCPython.dll");
base.GetLibrariesToPreload(libraries);
}
protected void RunCommandsFromFile(string commandFileName, CommandCallback commandCallback = null)
{
string commandFilePath = SystemTestBase.GetTestDirectory(ExecutingDirectory);
commandFilePath = Path.Combine(commandFilePath, @"core\recorded\");
commandFilePath = Path.Combine(commandFilePath, commandFileName);
CommandFilePath = commandFilePath;
ViewModel.HomeSpace.RunSettings.RunType = RunType.Automatic;
ViewModel.InitializeAutomationSettings(CommandFilePath);
// Load all custom nodes if there is any specified for this test.
if (this.customNodesToBeLoaded != null)
{
foreach (var customNode in this.customNodesToBeLoaded)
{
CustomNodeInfo info;
if (!ViewModel.Model.CustomNodeManager.AddUninitializedCustomNode(customNode, true, out info))
{
throw new System.IO.FileFormatException(string.Format(
"Failed to load custom node: {0}", customNode));
}
}
}
RegisterCommandCallback(commandCallback);
// Create the view.
// dynamoView will be closed by the ViewModel's automationSettings object.
dynamoView = new DynamoView(this.ViewModel);
dynamoView.ShowDialog();
Assert.IsNotNull(this.ViewModel);
Assert.IsNotNull(this.ViewModel.Model);
Assert.IsNotNull(this.ViewModel.Model.CurrentWorkspace);
workspace = this.ViewModel.Model.CurrentWorkspace;
workspaceViewModel = this.ViewModel.CurrentSpaceViewModel;
var automation = this.ViewModel.Automation;
if (automation != null)
{
automation.PlaybackStateChanged -= OnAutomationPlaybackStateChanged;
}
}
private void RegisterCommandCallback(CommandCallback commandCallback)
{
if (commandCallback == null)
return;
if (this.commandCallback != null)
throw new InvalidOperationException("RunCommandsFromFile called twice");
this.commandCallback = commandCallback;
var automation = this.ViewModel.Automation;
automation.PlaybackStateChanged += OnAutomationPlaybackStateChanged;
}
private void OnAutomationPlaybackStateChanged(object sender, PlaybackStateChangedEventArgs e)
{
if (e.OldState == AutomationSettings.State.Paused)
{
if (e.NewState == AutomationSettings.State.Playing)
{
// Call back to the delegate registered by the test case. We
// only handle command transition from Paused to Playing. Note
// that "commandCallback" is not checked against "null" value
// because "OnAutomationPlaybackStateChanged" would not have
// been called if the "commandCallback" was not registered.
//
this.commandCallback(e.NewTag);
}
}
}
protected CmdType DuplicateAndCompare<CmdType>(CmdType command)
where CmdType : DynamoModel.RecordableCommand
{
Assert.IsNotNull(command); // Ensure we have an input command.
// Serialize the command into an XmlElement.
XmlDocument xmlDocument = new XmlDocument();
XmlElement element = command.Serialize(xmlDocument);
Assert.IsNotNull(element);
// Deserialized the XmlElement into a new instance of the command.
var duplicate = DynamoModel.RecordableCommand.Deserialize(element);
Assert.IsNotNull(duplicate);
Assert.IsTrue(duplicate is CmdType);
return duplicate as CmdType;
}
#endregion
}
[TestFixture]
public class RecordedTests : RecordedUnitTestBase
{
#region Recorded Test Cases for Command Framework
[Test, Apartment(ApartmentState.STA)]
public void _SnowPeashooter()
{
RunCommandsFromFile("SnowPeashooter.xml");
Assert.AreEqual(1, workspace.Nodes.Count());
Assert.AreEqual(0, workspace.Connectors.Count());
var number = GetNode("045decd1-7454-4b85-b92e-d59d35f31ab2") as DoubleInput;
Assert.AreEqual("12.34", number.Value);
//Assert.Inconclusive("Porting : DoubleInput");
}
[Test, Apartment(ApartmentState.STA)]
public void TestPausePlaybackCommand()
{
int pauseDurationInMs = randomizer.Next(2000);
var cmdOne = new DynamoModel.PausePlaybackCommand(pauseDurationInMs);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.PauseDurationInMs, cmdTwo.PauseDurationInMs);
}
[Test, Apartment(ApartmentState.STA)]
public void TestRunCancelCommand()
{
bool showErrors = randomizer.Next(2) == 0;
bool cancelRun = randomizer.Next(2) == 0;
var cmdOne = new DynamoModel.RunCancelCommand(showErrors, cancelRun);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.ShowErrors, cmdTwo.ShowErrors);
Assert.AreEqual(cmdOne.CancelRun, cmdTwo.CancelRun);
}
[Test, Apartment(ApartmentState.STA)]
public void TestCreateNodeCommand()
{
// Create the command in completely unpredictable states. These
// states should properly be serialized and deserialized across
// two instances of the same command.
//
Guid nodeId = Guid.NewGuid();
string name = randomizer.Next().ToString();
double x = randomizer.NextDouble() * 1000;
double y = randomizer.NextDouble() * 1000;
bool defaultPos = randomizer.Next(2) == 0;
bool transfPos = randomizer.Next(2) == 0;
var cmdOne = new DynamoModel.CreateNodeCommand(
null, x, y, defaultPos, transfPos);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.X, cmdTwo.X, 0.000001);
Assert.AreEqual(cmdOne.Y, cmdTwo.Y, 0.000001);
Assert.AreEqual(cmdOne.DefaultPosition, cmdTwo.DefaultPosition);
Assert.AreEqual(cmdOne.TransformCoordinates, cmdTwo.TransformCoordinates);
// A RecordableCommand should be created in "recording mode" by default,
// and only deserialized commands should be marked as "in playback mode".
Assert.AreEqual(false, cmdOne.IsInPlaybackMode);
Assert.AreEqual(true, cmdTwo.IsInPlaybackMode);
}
[Test, Apartment(ApartmentState.STA)]
public void TestCreateAndConnectNodeCommand()
{
// Create the command in completely unpredictable states. These
// states should properly be serialized and deserialized across
// two instances of the same command.
//
Guid newNodeGuid = Guid.NewGuid();
Guid existingNodeGuid = Guid.NewGuid();
double x = randomizer.NextDouble() * 1000;
double y = randomizer.NextDouble() * 1000;
var cmdOne = new DynamoModel.CreateAndConnectNodeCommand(newNodeGuid, existingNodeGuid,
"dummyNode", 0, 1, x, y, false, false);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.NewNodeName, cmdTwo.NewNodeName);
Assert.AreEqual(cmdOne.X, cmdTwo.X, 0.000001);
Assert.AreEqual(cmdOne.Y, cmdTwo.Y, 0.000001);
Assert.AreEqual(cmdOne.InputPortIndex, cmdTwo.InputPortIndex);
Assert.AreEqual(cmdOne.OutputPortIndex, cmdTwo.OutputPortIndex);
Assert.AreEqual(cmdOne.CreateAsDownstreamNode, cmdTwo.CreateAsDownstreamNode);
Assert.AreEqual(cmdOne.AddNewNodeToSelection, cmdTwo.AddNewNodeToSelection);
Assert.AreEqual(cmdOne.ModelGuid, cmdTwo.ModelGuid);
Assert.AreEqual(cmdOne.ModelGuids.ElementAt(1), cmdTwo.ModelGuids.ElementAt(1));
// A RecordableCommand should be created in "recording mode" by default,
// and only deserialized commands should be marked as "in playback mode".
Assert.AreEqual(false, cmdOne.IsInPlaybackMode);
Assert.AreEqual(true, cmdTwo.IsInPlaybackMode);
}
[Test, Apartment(ApartmentState.STA)]
public void TestCreateNoteCommand()
{
// Create the command in completely unpredictable states. These
// states should properly be serialized and deserialized across
// two instances of the same command.
//
Guid nodeId = Guid.NewGuid();
string text = randomizer.Next().ToString();
double x = randomizer.NextDouble() * 1000;
double y = randomizer.NextDouble() * 1000;
bool defaultPos = randomizer.Next(2) == 0;
var cmdOne = new DynamoModel.CreateNoteCommand(nodeId, text, x, y, defaultPos);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.ModelGuid, cmdTwo.ModelGuid);
Assert.AreEqual(cmdOne.NoteText, cmdTwo.NoteText);
Assert.AreEqual(cmdOne.X, cmdTwo.X, 0.000001);
Assert.AreEqual(cmdOne.Y, cmdTwo.Y, 0.000001);
Assert.AreEqual(cmdOne.DefaultPosition, cmdTwo.DefaultPosition);
}
[Test, Apartment(ApartmentState.STA)]
public void TestSelectModelCommand()
{
Guid modelGuid = Guid.NewGuid();
Dynamo.Utilities.ModifierKeys modifiers = ((randomizer.Next(2) == 0) ?
Dynamo.Utilities.ModifierKeys.Control : Dynamo.Utilities.ModifierKeys.Alt);
var cmdOne = new DynamoModel.SelectModelCommand(modelGuid, modifiers);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.ModelGuid, cmdTwo.ModelGuid);
Assert.AreEqual(cmdOne.Modifiers, cmdTwo.Modifiers);
}
[Test, Apartment(ApartmentState.STA)]
public void TestSelectInRegionCommand()
{
var region = new Rect2D(
randomizer.NextDouble() * 100,
randomizer.NextDouble() * 100,
randomizer.NextDouble() * 100,
randomizer.NextDouble() * 100);
bool isCrossSelection = randomizer.Next(2) == 0;
var cmdOne = new DynamoModel.SelectInRegionCommand(region, isCrossSelection);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.Region.X, cmdTwo.Region.X, 0.000001);
Assert.AreEqual(cmdOne.Region.Y, cmdTwo.Region.Y, 0.000001);
Assert.AreEqual(cmdOne.Region.Width, cmdTwo.Region.Width, 0.000001);
Assert.AreEqual(cmdOne.Region.Height, cmdTwo.Region.Height, 0.000001);
Assert.AreEqual(cmdOne.IsCrossSelection, cmdTwo.IsCrossSelection);
}
[Test, Apartment(ApartmentState.STA)]
public void TestDragSelectionCommand()
{
var point = new Point2D(
randomizer.NextDouble() * 100,
randomizer.NextDouble() * 100);
var operation = ((randomizer.Next(2) == 0) ?
DynamoModel.DragSelectionCommand.Operation.BeginDrag :
DynamoModel.DragSelectionCommand.Operation.EndDrag);
var cmdOne = new DynamoModel.DragSelectionCommand(point, operation);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.MouseCursor.X, cmdTwo.MouseCursor.X, 0.000001);
Assert.AreEqual(cmdOne.MouseCursor.Y, cmdTwo.MouseCursor.Y, 0.000001);
Assert.AreEqual(cmdOne.DragOperation, cmdTwo.DragOperation);
}
[Test, Apartment(ApartmentState.STA)]
public void TestMakeConnectionCommand()
{
Guid nodeId = Guid.NewGuid();
int portIndex = randomizer.Next();
var portType = ((PortType)randomizer.Next(2));
var mode = ((DynamoModel.MakeConnectionCommand.Mode)randomizer.Next(3));
var cmdOne = new DynamoModel.MakeConnectionCommand(
nodeId, portIndex, portType, mode);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.ModelGuid, cmdTwo.ModelGuid);
Assert.AreEqual(cmdOne.PortIndex, cmdTwo.PortIndex);
Assert.AreEqual(cmdOne.Type, cmdTwo.Type);
Assert.AreEqual(cmdOne.ConnectionMode, cmdTwo.ConnectionMode);
}
[Test, Apartment(ApartmentState.STA)]
public void TestDeleteModelCommand()
{
Guid modelGuid = Guid.NewGuid();
var cmdOne = new DynamoModel.DeleteModelCommand(modelGuid);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.ModelGuid, cmdTwo.ModelGuid);
}
[Test, Apartment(ApartmentState.STA)]
public void TestUndoRedoCommand()
{
var operation = ((DynamoModel.UndoRedoCommand.Operation)randomizer.Next(2));
var cmdOne = new DynamoModel.UndoRedoCommand(operation);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.CmdOperation, cmdTwo.CmdOperation);
}
[Test, Apartment(ApartmentState.STA)]
public void TestUpdateModelValueCommand0()
{
Guid modelGuid = Guid.NewGuid();
string name = randomizer.Next().ToString();
string value = randomizer.Next().ToString();
var cmdOne = new DynamoModel.UpdateModelValueCommand(System.Guid.Empty, modelGuid, name, value);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.IsTrue(cmdOne.ModelGuids.SequenceEqual(cmdTwo.ModelGuids));
Assert.AreEqual(cmdOne.Name, cmdTwo.Name);
Assert.AreEqual(cmdOne.Value, cmdTwo.Value);
}
[Test, Apartment(ApartmentState.STA)]
public void TestUpdateModelValueCommand1()
{
var modelGuids = new[]
{
Guid.NewGuid(),
Guid.NewGuid(),
Guid.NewGuid(),
Guid.NewGuid(),
Guid.NewGuid(),
Guid.NewGuid()
};
string name = randomizer.Next().ToString();
string value = randomizer.Next().ToString();
var cmdOne = new DynamoModel.UpdateModelValueCommand(System.Guid.Empty, modelGuids, name, value);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.IsTrue(cmdOne.ModelGuids.SequenceEqual(cmdTwo.ModelGuids));
Assert.AreEqual(cmdOne.Name, cmdTwo.Name);
Assert.AreEqual(cmdOne.Value, cmdTwo.Value);
}
[Test, Apartment(ApartmentState.STA)]
public void TestCreateCustomNodeCommand()
{
Guid modelGuid = Guid.NewGuid();
string name = randomizer.Next().ToString();
string category = randomizer.Next().ToString();
string description = randomizer.Next().ToString();
bool makeCurrent = randomizer.Next(2) == 0;
var cmdOne = new DynamoModel.CreateCustomNodeCommand(
modelGuid, name, category, description, makeCurrent);
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.ModelGuid, cmdTwo.ModelGuid);
Assert.AreEqual(cmdOne.Name, cmdTwo.Name);
Assert.AreEqual(cmdOne.Category, cmdTwo.Category);
Assert.AreEqual(cmdOne.Description, cmdTwo.Description);
Assert.AreEqual(cmdOne.MakeCurrent, cmdTwo.MakeCurrent);
}
[Test, Apartment(ApartmentState.STA)]
public void Defect_MAGN_6821_withoutInput()
{
//Custom Node without Input
//Scenario:
//1. Create CBN and convert that into CustomNode
//2. Place this custom node and execute
//3. Verify the results of custom node instance are correct
// http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-6821
RunCommandsFromFile("Defect_MAGN_6821_withoutInput.xml", (commandTag) =>
{
var workspace = ViewModel.Model.CurrentWorkspace;
var cbn = GetNode("66c0f6b3-e9a0-495e-b3e1-c02b4615c71c") as Function;
if (commandTag == "Run")
{
// check for number of Nodes and Connectors
Assert.AreEqual(1, workspace.Nodes.Count());
Assert.AreEqual(0, workspace.Connectors.Count());
AssertPreviewValue("66c0f6b3-e9a0-495e-b3e1-c02b4615c71c", 12);
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void Defect_MAGN_6821_withInput()
{
//Create one input node
//Scenario
//1. Create one input node
//2. Create one output node
//3. Connect the above with single node in between
//4. Place the custom node instance and connect with relavant inputs
// http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-6821
RunCommandsFromFile("Defect_MAGN_6821_withInput.xml", (commandTag) =>
{
var workspace = ViewModel.Model.CurrentWorkspace;
if (commandTag == "Run")
{
Assert.AreEqual(3, workspace.Nodes.Count());
Assert.AreEqual(2, workspace.Connectors.Count());
AssertPreviewValue("fb5bf7c3-8312-42e8-85cb-e17fbee1fbae", 2);
AssertPreviewValue("fb9c8be5-7fc2-4735-a33c-c1c9b2a97f18", 2);
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void Defect_MAGN_6821_multipleInput()
{
// Create Multiple Input nodes
//Scenario:
//1. Create custom node with multiple input nodes
//2. Connect them to complete the graph
//3. Create instance of custom node and Execute.
// http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-6821
RunCommandsFromFile("Defect_MAGN_6821_multipleInput.xml", (commandTag) =>
{
var workspace = ViewModel.Model.CurrentWorkspace;
if (commandTag == "Run")
{
AssertPreviewValue("9eb488ec-c232-4048-a30c-e610f10deeb5", 4);
Assert.AreEqual(4, workspace.Nodes.Count());
Assert.AreEqual(3, workspace.Connectors.Count());
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void Defect_MAGN_6821_multipleInstance()
{
//Create Multiple Instances nodes
//Scenario:
//1. Create custom node with multiple input nodes
//2. Connect them to complete the graph
//3. Create multiple instances of custom node and Execute.
//4. verify the results are correct
// http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-6821
RunCommandsFromFile("Defect_MAGN_6821_multipleInstance.xml", (commandTag) =>
{
var workspace = ViewModel.Model.CurrentWorkspace;
if (commandTag == "Run")
{
AssertPreviewValue("d48647e8-0129-4e16-9fa8-7c4d8f20c1be", 4);
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void Defect_MAGN_6821_nestedCustomNode()
{
// Single Instance
//Scenario: Create a custom node inside another one
// http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-6821
RunCommandsFromFile("Defect_MAGN_6821_nestedCustomNode.xml", (commandTag) =>
{
var workspace = ViewModel.Model.CurrentWorkspace;
if (commandTag == "Run")
{
AssertPreviewValue("2088ab88-dd22-4963-8fe9-2f393328aa56", 2);
AssertPreviewValue("f89e3e11-aa50-408e-97a0-c48d11b64d4f", 2);
}
});
}
[Test]
public void TestCustomNode()
{
RunCommandsFromFile("TestCustomNode.xml");
var workspaces = this.ViewModel.Model.Workspaces;
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count()); // 1 custom node + 1 home space
// 1 custom node + 1 number node
Assert.AreEqual(1, workspace.Connectors.Count());
Assert.AreEqual(2, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
// 1 inputs + 1 output
Assert.AreEqual(1, customWorkspace.Connectors.Count());
Assert.AreEqual(2, customWorkspace.Nodes.Count());
var node = customWorkspace.Nodes.First();
var outports = node.OutPorts;
AssertPreviewValue("04f6dab5-0a0b-4563-9f20-d0e58fcae7a5", 1.0);
}
[Test]
public void TestCustomNodeSyntaxError_DoesNotCrash()
{
//Create custom node
//Scenario:
//1. Create custom node
//2. Create code block node
//3. Type in a range expression (1..10) and commit the node
//4. Update the code block by introducing syntax error like "1...10"
//5. Test for crash
Assert.DoesNotThrow(() => RunCommandsFromFile("CreateCustomNodeSyntaxError.xml"));
}
[Test]
public void TestCustomNodeUI()
{
RunCommandsFromFile("CustomNodeUI.xml", (commandTag) =>
{
var workspaces = ViewModel.Model.Workspaces;
if (commandTag == "FirstRun")
{
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count()); // 1 custom node + 1 home space
// 1 custom node + 1 number node
Assert.AreEqual(2, workspace.Connectors.Count());
Assert.AreEqual(3, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
// 2 inputs + 1 output
Assert.AreEqual(3, customWorkspace.Connectors.Count());
Assert.AreEqual(4, customWorkspace.Nodes.Count());
var node = GetNode("6cec1997-ed61-4277-a1a8-3f3e4eb4321d") as NodeModel;
Assert.AreEqual(2, node.InPorts.Count);
Assert.AreEqual(1, node.OutPorts.Count);
AssertPreviewValue("6cec1997-ed61-4277-a1a8-3f3e4eb4321d", 7.6);
}
else if (commandTag == "SecondRun")
{
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count()); // 1 custom node + 1 home space
// 1 custom node + 1 number node
Assert.AreEqual(3, workspace.Connectors.Count());
Assert.AreEqual(4, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
// 2 inputs + 1 output
Assert.AreEqual(2, customWorkspace.Connectors.Count());
Assert.AreEqual(1, customWorkspace.Nodes.Count());
var node = GetNode("6cec1997-ed61-4277-a1a8-3f3e4eb4321d") as NodeModel;
Assert.AreEqual(3, node.InPorts.Count);
Assert.AreEqual(1, node.OutPorts.Count);
AssertPreviewValue("6cec1997-ed61-4277-a1a8-3f3e4eb4321d", 11.5);
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void TestRunEnabledButtonCanBeDisabled()
{
RunCommandsFromFile("TestRunEnabledButtonCanBeDisabled.xml", (commandTag) =>
{
//This test case is to verify that when RunEnabled is changed to false from the model,
//the Run button is disabled. The strategy here is to directly modify the RunEnabled value
//in the model. But at that time, the view has not yet had a chance to refresh its button.
//So the process is separated into two steps. At the second step. the button status is checked.
if (commandTag == "OpenFile")
{
ViewModel.HomeSpace.RunSettings.RunEnabled = false;
}
else if (commandTag == "CheckButtonIsDisabled")
{
Assert.IsFalse(dynamoView.RunSettingsControl.RunButton.IsEnabled);
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void Defect_MAGN_1143_CN()
{
// modify the name of the input node
RunCommandsFromFile("Defect_MAGN_1143_CN.xml", (commandTag) =>
{
var workspaces = ViewModel.Model.Workspaces;
if (commandTag == "FirstRun")
{
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count());
Assert.AreEqual(2, workspace.Connectors.Count());
Assert.AreEqual(1, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
Assert.AreEqual(2, customWorkspace.Connectors.Count());
Assert.AreEqual(1, customWorkspace.Nodes.Count());
var node = GetNode("6cec1997-ed61-4277-a1a8-3f3e4eb4321d") as NodeModel;
}
else if (commandTag == "SecondRun")
{
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count());
Assert.AreEqual(2, workspace.Connectors.Count());
Assert.AreEqual(1, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
Assert.AreEqual(2, customWorkspace.Connectors.Count());
Assert.AreEqual(1, customWorkspace.Nodes.Count());
}
});
}
[Test]
public void Defect_MAGN_2144_CN()
{
RunCommandsFromFile("Defect_MAGN_2144_CN.xml", (commandTag) =>
{
var workspaces = ViewModel.Model.Workspaces;
if (commandTag == "FirstRun")
{
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count()); // 1 custom node + 1 home space
// 1 custom node + 1 number node
Assert.AreEqual(1, workspace.Connectors.Count());
Assert.AreEqual(2, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
// 2 inputs + 1 output
Assert.AreEqual(2, customWorkspace.Connectors.Count());
Assert.AreEqual(3, customWorkspace.Nodes.Count());
var node = GetNode("6cec1997-ed61-4277-a1a8-3f3e4eb4321d") as NodeModel;
AssertPreviewValue("6cec1997-ed61-4277-a1a8-3f3e4eb4321d", 1);
}
else if (commandTag == "SecondRun")
{
Assert.IsNotNull(workspaces);
Assert.AreEqual(2, workspaces.Count()); // 1 custom node + 1 home space
// 1 custom node + 1 number node
Assert.AreEqual(1, workspace.Connectors.Count());
Assert.AreEqual(2, workspace.Nodes.Count());
var customWorkspace = workspaces.ElementAt(1);
Assert.IsNotNull(customWorkspace);
// 2 inputs + 1 output
Assert.AreEqual(2, customWorkspace.Connectors.Count());
Assert.AreEqual(3, customWorkspace.Nodes.Count());
var node = GetNode("6cec1997-ed61-4277-a1a8-3f3e4eb4321d") as NodeModel;
Assert.AreEqual(2, node.InPorts.Count);
Assert.AreEqual(3, node.OutPorts.Count);
AssertPreviewValue("6cec1997-ed61-4277-a1a8-3f3e4eb4321d", 1);
}
});
}
[Test, Apartment(ApartmentState.STA)]
public void TestSwitchTabCommand()
{
var cmdOne = new DynamoModel.SwitchTabCommand(randomizer.Next());
var cmdTwo = DuplicateAndCompare(cmdOne);
Assert.AreEqual(cmdOne.WorkspaceModelIndex, cmdTwo.WorkspaceModelIndex);
}
[Test, Apartment(ApartmentState.STA)]
public void TestCreateNodeCommandWithMultiGuids()
{
RunCommandsFromFile("TestCreateNodeCommandWithMultyGuids.xml");
// 1 Number node + 1 CodeBlock node
Assert.AreEqual(2, workspace.Nodes.Count());
// 1 connection between them
Assert.AreEqual(1, workspace.Connectors.Count());
// Check if guids correct
var node = GetNode("612e4917-9b8d-4660-906d-972bb620dd68");
Assert.NotNull(node);
node = GetNode("25409e47-e381-41b1-9dfa-d25a32807017");
Assert.NotNull(node);
}
[Test, Apartment(ApartmentState.STA)]
public void TestCreateNoteCommandWithMultiGuids()
{
RunCommandsFromFile("TestCreateNoteCommandWithMultiGuids.xml");
// Should be only 1 note
Assert.AreEqual(1, workspace.Notes.Count());
// Check if guid correct
var node = GetNode("682adbae-629f-4c15-b1b4-8af22c2f850c");
Assert.NotNull(node);
}
[Test, Apartment(ApartmentState.STA)]
public void TestSelectModelCommandWithMultiGuids()
{
RunCommandsFromFile("TestSelectModelCommandWithMultiGuids.xml");
// Should be 2 selected nodes
Assert.AreEqual(2, Dynamo.Selection.DynamoSelection.Instance.Selection.Count);
// Check if guids correct
var node = GetNode("f4e3437f-7512-42dc-a5be-539ad9cfee98");
Assert.NotNull(node);
node = GetNode("cd8fe247-6caf-47df-aef8-c8a90ee03b4e");
Assert.NotNull(node);
node = GetNode("a5f66fe1-816e-497a-b422-18f60b675eac");
Assert.NotNull(node);
}
[Test, Apartment(ApartmentState.STA)]
public void TestMakeConnectionCommandWithMultiGuids()
{
RunCommandsFromFile("TestMakeConnectionCommandWithMultiGuids.xml");
// 1 Number node + 1 CodeBlock node
Assert.AreEqual(2, workspace.Nodes.Count());
// Should be only 1 connection
Assert.AreEqual(1, workspace.Connectors.Count());
}
[Test, Apartment(ApartmentState.STA)]
public void TestDeleteModelCommandWithMultiGuids()
{
RunCommandsFromFile("TestDeleteModelCommandWithMultiGuids.xml");
// Only 1 node should left after multiple deletion
Assert.AreEqual(1, workspace.Nodes.Count());
var node = GetNode("184470e6-e4d2-47de-bfc7-2d39bdc011b4");
Assert.NotNull(node);
}
[Test, Apartment(ApartmentState.STA)]
public void TestModelEventCommandWithMultiGuids()
{
RunCommandsFromFile("TestModelEventCommandWithMultiGuids.xml");
// 2 nodes
Assert.AreEqual(2, workspace.Nodes.Count());
// Sould contain 3 Input ports
var node = GetNode("4ac8c08a-da16-422d-a40d-ff465bac90d8") as NodeModel;
Assert.AreEqual(3, node.InPorts.Count);
// Sould contain 2 Input ports
node = GetNode("9aa1af8a-d16d-4cb8-92d9-db9dc7bd0e98") as NodeModel;
Assert.AreEqual(2, node.InPorts.Count);
}
[Test, Apartment(ApartmentState.STA)]
public void TestUpdateModelValueCommandWithMultiGuids()
{
RunCommandsFromFile("TestUpdateModelValueCommandWithMultiGuids.xml");
// 3 nodes
Assert.AreEqual(3, workspace.Nodes.Count());
// All Number nodes should contain value 5
Assert.AreEqual(3, workspace.Nodes.OfType<DoubleInput>().Count(node => node.Value == "5"));
}
[Test, Apartment(ApartmentState.STA)]
public void TestUngroupModelCommandWithMultiGuids()
{
RunCommandsFromFile("TestUngroupModelCommandWithMultiGuids.xml");
// 3 nodes
Assert.AreEqual(3, workspace.Nodes.Count());
// 1 group
Assert.AreEqual(1, workspace.Annotations.Count());
var group = workspace.Annotations.First();
// Should contain only 1 NodeModel
Assert.AreEqual(1, group.Nodes.Count());
Assert.IsTrue(group.Nodes.Any(m => m.GUID == Guid.Parse("7dc3b638-284f-4296-a793-8185ef42cd71")));
}
[Test, Apartment(ApartmentState.STA)]
public void TestNodeDeletionWhileMakingConnectionToOtherNode()
{
RunCommandsFromFile("DeleteNodeWhileConnecting.xml");
// 1 node and no connectors
Assert.AreEqual(1, workspace.Nodes.Count());
Assert.AreEqual(false, workspace.Connectors.Any());
}
/// <summary>
/// The following tests exercise the following steps:
///
/// 1. Create two number nodes and one add node
/// 2. Connect the first number node to the two input ports of the add node (2 connectors)
/// 3. Reconnect the 2 wires to the second number node using shift + click
///
/// </summary>
[Test, Apartment(ApartmentState.STA)]
public void TestShiftReconnections()
{
RunCommandsFromFile("TestShiftReconnections.xml");
Assert.AreEqual(3, workspace.Nodes.Count()); // 2 number nodes + 1 add node
Assert.AreEqual(2, workspace.Connectors.Count()); // 2 connections from output port of one number node to 2 input ports of the add node
AssertPreviewValue("b4df09e1-0041-4e4c-b417-325f27224e6c", 5.0);
}
[Test, Apartment(ApartmentState.STA)]
public void TestShiftReconnectionsUndo()
{
RunCommandsFromFile("TestShiftReconnectionsUndo.xml");
//do undo to obtain previous connections
Assert.AreEqual(3, workspace.Nodes.Count());
Assert.AreEqual(2, workspace.Connectors.Count());
AssertPreviewValue("7552b4cd-13b2-4921-aff8-682ec0dfd6fb", 2.0);
}
[Test, Apartment(ApartmentState.STA)]
public void TestShiftReconnectionsUndoRedo()
{
RunCommandsFromFile("TestShiftReconnectionsUndoRedo.xml");
//do undo and redo once each
Assert.AreEqual(3, workspace.Nodes.Count());
Assert.AreEqual(2, workspace.Connectors.Count());
AssertPreviewValue("837d3ed0-b8f5-408d-a16d-ed7094a14217", 5.0);
}
/// <summary>
/// The following tests exercise the following steps: