-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineOutputHandlerTests.cs
More file actions
99 lines (82 loc) · 2.09 KB
/
LineOutputHandlerTests.cs
File metadata and controls
99 lines (82 loc) · 2.09 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
// Copyright (c) ktsu.dev
// All rights reserved.
// Licensed under the MIT license.
namespace ktsu.RunCommand.Test;
[TestClass]
public class LineOutputHandlerTests
{
[TestMethod]
public void HandleStandardOutputDataShouldProcessLinesCorrectly()
{
// Arrange
string data = "Line1\nLine2\nLine3\n";
string[] expectedLines = ["Line1", "Line2", "Line3"];
int index = 0;
LineOutputHandler handler = new(
onStandardOutput: line =>
{
Assert.AreEqual(expectedLines[index], line);
index++;
});
// Act
handler.HandleStandardOutputData(data);
// Assert
Assert.AreEqual(expectedLines.Length, index);
}
[TestMethod]
public void HandleStandardErrorDataShouldProcessLinesCorrectly()
{
// Arrange
string data = "Error1\nError2\nError3\n";
string[] expectedLines = ["Error1", "Error2", "Error3"];
int index = 0;
LineOutputHandler handler = new(
onStandardError: line =>
{
Assert.AreEqual(expectedLines[index], line);
index++;
});
// Act
handler.HandleStandardErrorData(data);
// Assert
Assert.AreEqual(expectedLines.Length, index);
}
[TestMethod]
public void HandleStandardOutputDataShouldBufferIncompleteLines()
{
// Arrange
string data = "Line1\nLine2\nIncomplete";
string[] expectedLines = ["Line1", "Line2"];
int index = 0;
LineOutputHandler handler = new(
onStandardOutput: line =>
{
Assert.AreEqual(expectedLines[index], line);
index++;
});
// Act
handler.HandleStandardOutputData(data);
// Assert
Assert.AreEqual(expectedLines.Length, index);
Assert.AreEqual("Incomplete", handler.outputBuffer);
}
[TestMethod]
public void HandleStandardErrorDataShouldBufferIncompleteLines()
{
// Arrange
string data = "Error1\nError2\nIncomplete";
string[] expectedLines = ["Error1", "Error2"];
int index = 0;
LineOutputHandler handler = new(
onStandardError: line =>
{
Assert.AreEqual(expectedLines[index], line);
index++;
});
// Act
handler.HandleStandardErrorData(data);
// Assert
Assert.AreEqual(expectedLines.Length, index);
Assert.AreEqual("Incomplete", handler.errorBuffer);
}
}