O'Reilly logo

Practical Test-Driven Development using C# 7 by Clayton Hunt, John Callaway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Unexpected Input

While replacing calls to Console with calls to our injected class, we found two use cases that we did not plan for. The first use case is fairly involved and has a couple parameters we need to handle:

Console.Write("+", c = c + 1);

The second use case is more simple and doesn't take any parameters:

Console.WriteLine();

The second use case is the easiest to deal with, so let us write a quick test for that now.

In the file WriteLineTests.cs:

[Fact]public void ItCanWriteABlankLine(){  // Arrange  var inout = new MockInputOutput();  // Act  inout.WriteLine();  // Assert  Assert.Single(inout.OutFeed);  Assert.Equal(Environment.NewLine, inout.OutFeed.First());}

In the file IInputOutput.cs:

void WriteLine(string text = null);

In the file ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required