Skip to content

Commit

Permalink
Updated the test to use the ConsoleAssert class
Browse files Browse the repository at this point in the history
  • Loading branch information
twoody0 committed Nov 6, 2024
1 parent 66e6bc8 commit 30a5a17
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/Chapter13.Tests/Listing13.15.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,18 @@ public class ProgramTests
[TestMethod]
public void MainTest()
{
const string expectedInput = "Hello, World!";
const string expectedOutput = "Hello, World!";
const string expectedOutput = "ValidInput";
string simulatedInput = "\n \nValidInput\n";

StringReader reader = new (expectedInput);
StringWriter writer = new ();
try
{
Console.SetIn(reader);
Console.SetOut(writer);
Program.Main();

string actualOutput = writer.ToString().Trim();
Assert.AreEqual(expectedOutput, actualOutput);
}
finally
{
reader.Dispose();
writer.Dispose();
}
IntelliTect.TestTools.Console.ConsoleAssert.Expect(
expectedOutput,
() =>
{
using (StringReader simulatedReader = new (simulatedInput))
{
Console.SetIn(simulatedReader);
Program.Main();
}
});
}
}

0 comments on commit 30a5a17

Please sign in to comment.