-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM630Tests.cs
99 lines (84 loc) · 3.77 KB
/
M630Tests.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
using GSendAnalyzer;
using GSendAnalyzer.Internal;
using GSendCommon.MCodeOverrides;
using GSendShared;
using GSendShared.Models;
using GSendTests.Mocks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace GSendTests.MCodeOverrideTests
{
[ExcludeFromCodeCoverage]
[TestClass]
public class M630Tests
{
[TestMethod]
public void Process_M630CodeNotFound_Returns_False()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M604");
analyses.Analyse();
gCodeLine.Commands.AddRange(analyses.Commands);
MachineStateModel machineStateModel = new();
machineStateModel.Overrides.OverridesDisabled = false;
MockOverrideContext context = new(machineStateModel)
{
GCode = gCodeLine
};
M630Override sut = new(new MockRunProgram());
bool result = sut.Process(context, CancellationToken.None);
Assert.IsFalse(result);
}
[TestMethod]
public void Process_M630CodeFound_WithoutArgs_Returns_True()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M630;myprog.exe");
analyses.Analyse();
gCodeLine.Commands.AddRange(analyses.Commands);
MachineStateModel machineStateModel = new();
machineStateModel.Overrides.OverridesDisabled = false;
MockOverrideContext context = new(machineStateModel)
{
GCode = gCodeLine
};
MockRunProgram mockRunProgram = new();
M630Override sut = new(mockRunProgram);
bool result = sut.Process(context, CancellationToken.None);
Assert.IsTrue(result);
Assert.AreEqual("myprog.exe", mockRunProgram.ProgramName);
Assert.IsNull(mockRunProgram.Parameters);
Assert.IsTrue(mockRunProgram.UseShellExecute);
Assert.IsFalse(mockRunProgram.WaitForFinish);
Assert.AreEqual(Int32.MinValue, mockRunProgram.ReturnValue);
}
[TestMethod]
public void Process_M630CodeFound_WithArgsPrefix_Returns_True()
{
IGCodeLine gCodeLine = new GCodeLine(new MockGCodeAnalyses());
GCodeParser gCodeParser = new(new MockPluginClassesService(), new MockSubprograms());
IGCodeAnalyses analyses = gCodeParser.Parse("M630.1;-p /m\nM630;myprog.exe");
analyses.Analyse();
gCodeLine.Commands.AddRange(analyses.Commands);
MachineStateModel machineStateModel = new();
machineStateModel.Overrides.OverridesDisabled = false;
MockOverrideContext context = new(machineStateModel)
{
GCode = gCodeLine
};
MockRunProgram mockRunProgram = new();
M630Override sut = new(mockRunProgram);
bool result = sut.Process(context, CancellationToken.None);
Assert.IsTrue(result);
Assert.AreEqual("myprog.exe", mockRunProgram.ProgramName);
Assert.AreEqual("-p /m", mockRunProgram.Parameters);
Assert.IsTrue(mockRunProgram.UseShellExecute);
Assert.IsFalse(mockRunProgram.WaitForFinish);
Assert.AreEqual(Int32.MinValue, mockRunProgram.ReturnValue);
}
}
}