A REFACTORING EXAMPLE
Suppose that one of your friends is developing a tic-tac-toe game. He has created the front end that allows users to manage turns and to pick the square in which to place their mark. For this example, he has asked you to create a service that he can use to determine if either player has won by placing his or her mark in three adjacent squares to form a row horizontally, vertically, or diagonally.
By way of requirements, your friend tells you that he plans to represent the game board by creating a 3-by-3 multidimensional array of char data types, with the x-axis representing horizontal rows and the y-axis representing vertical columns. This array will be passed into the method you will write as the input parameter. Your friend wants the library to return the mark of the winning player (an X or an O) or a space character if neither player wins.
To follow along with the example shown here, download the code from www.wrox.com.
The First Feature
For this task you create a blank solution in Visual Studio called TicTacToe. To that solution you add a class library called TicTacToe.UnitTests that contains a class called GameWinnerServiceTests (which makes the fully qualified name of this class TicTacToe.UnitTests.GameWinnerServiceTests). You also add a reference to NUnit, which will serve as your unit test framework (see Figure 4-1).
The first feature your friend asks ...
Get Professional Test-Driven Development with C#: Developing Real World Applications with TDD now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.