-
Notifications
You must be signed in to change notification settings - Fork 670
Expand file tree
/
Copy pathFilePathMutator.cs
More file actions
122 lines (103 loc) · 4.06 KB
/
FilePathMutator.cs
File metadata and controls
122 lines (103 loc) · 4.06 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using Dynamo.Engine;
using Dynamo.Graph.Nodes;
using Dynamo.Models;
using Dynamo.ViewModels;
namespace Dynamo.TestInfrastructure
{
[MutationTest("FilePathMutator")]
class FilePathMutator : AbstractMutator
{
public FilePathMutator(DynamoViewModel viewModel)
: base(viewModel)
{
}
public override Type GetNodeType()
{
string assemblyPath = Assembly.GetExecutingAssembly().Location;
string assemblyDir = Path.GetDirectoryName(assemblyPath);
string pathToNodesDll = assemblyDir + "\\nodes\\CoreNodeModels.dll";
Assembly assembly = Dynamo.Utilities.AssemblyHelper.LoadInALCFrom(pathToNodesDll);
Type type = assembly.GetType("DSCore.File.Filename");
return type;
}
public override bool RunTest(NodeModel node, EngineController engine, StreamWriter writer)
{
bool pass = false;
var valueMap = new Dictionary<Guid, String>();
if (node.OutPorts.Count > 0)
{
Guid guid = node.GUID;
Object data = node.GetValue(0, engine).Data;
String val = data != null ? data.ToString() : "null";
valueMap.Add(guid, val);
writer.WriteLine(guid + " :: " + val);
writer.Flush();
}
int numberOfUndosNeeded = Mutate(node);
Thread.Sleep(10);
writer.WriteLine("### - Beginning undo");
for (int iUndo = 0; iUndo < numberOfUndosNeeded; iUndo++)
{
DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
{
DynamoModel.UndoRedoCommand undoCommand =
new DynamoModel.UndoRedoCommand(
DynamoModel.UndoRedoCommand.Operation.Undo);
DynamoViewModel.ExecuteCommand(undoCommand);
}));
Thread.Sleep(100);
}
writer.WriteLine("### - undo complete");
writer.Flush();
writer.WriteLine("### - Beginning re-exec");
ExecuteAndWait();
writer.WriteLine("### - re-exec complete");
writer.Flush();
writer.WriteLine("### - Beginning readback");
writer.WriteLine("### - Beginning test of FilePath");
if (node.OutPorts.Count > 0)
{
try
{
String valmap = valueMap[node.GUID].ToString();
Object data = node.GetValue(0, engine).Data;
String nodeVal = data != null ? data.ToString() : "null";
if (valmap != nodeVal)
{
writer.WriteLine("!!!!!!!!!!! - test of FilePath is failed");
writer.WriteLine(node.GUID);
writer.WriteLine("Was: " + nodeVal);
writer.WriteLine("Should have been: " + valmap);
writer.Flush();
return pass;
}
}
catch (Exception)
{
writer.WriteLine("!!!!!!!!!!! - test of FilePath is failed");
writer.Flush();
return pass;
}
}
writer.WriteLine("### - test of FilePath complete");
writer.Flush();
return pass = true;
}
public override int Mutate(NodeModel node)
{
string assemblyPath = Assembly.GetExecutingAssembly().Location;
DynamoViewModel.UIDispatcher.Invoke(new Action(() =>
{
DynamoModel.UpdateModelValueCommand updateValue =
new DynamoModel.UpdateModelValueCommand(System.Guid.Empty, node.GUID, "Value", assemblyPath);
DynamoViewModel.ExecuteCommand(updateValue);
}));
return 1;
}
}
}