Skip to content

Commit 30a5a17

Browse files
committed
Updated the test to use the ConsoleAssert class
1 parent 66e6bc8 commit 30a5a17

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/Chapter13.Tests/Listing13.15.Tests.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,18 @@ public class ProgramTests
77
[TestMethod]
88
public void MainTest()
99
{
10-
const string expectedInput = "Hello, World!";
11-
const string expectedOutput = "Hello, World!";
10+
const string expectedOutput = "ValidInput";
11+
string simulatedInput = "\n \nValidInput\n";
1212

13-
StringReader reader = new (expectedInput);
14-
StringWriter writer = new ();
15-
try
16-
{
17-
Console.SetIn(reader);
18-
Console.SetOut(writer);
19-
Program.Main();
20-
21-
string actualOutput = writer.ToString().Trim();
22-
Assert.AreEqual(expectedOutput, actualOutput);
23-
}
24-
finally
25-
{
26-
reader.Dispose();
27-
writer.Dispose();
28-
}
13+
IntelliTect.TestTools.Console.ConsoleAssert.Expect(
14+
expectedOutput,
15+
() =>
16+
{
17+
using (StringReader simulatedReader = new (simulatedInput))
18+
{
19+
Console.SetIn(simulatedReader);
20+
Program.Main();
21+
}
22+
});
2923
}
3024
}

0 commit comments

Comments
 (0)