Let's first check the registration. We start with the bare
minimum, username and password, and add other personal details later.
Building on the skills gained with the previous story test,
we write two ColumnFixture classes: one
to register a player and one to verify the stored username and
new account balance.
Tristan/test/PlayerRegistration.cs
17 public class PlayerRegisters : ColumnFixture
18 {
19 public string Username;
20 public string Password;
21 public int PlayerId()
22 {
23 PlayerRegistrationInfo reg = new PlayerRegistrationInfo();
24 reg.Username = Username;
25 reg.Password = Password;
26 return SetUpTestEnvironment.playerManager.RegisterPlayer(reg);
27 }
28 }
29 public class CheckStoredDetails : ColumnFixture
30 {
31 public int PlayerId;
32 public string Username
33 {
34 get
35 {
36 return SetUpTestEnvironment.playerManager.
37 GetPlayer(PlayerId).Username;
38 }
39 }
40 public decimal Balance
41 {
42 get
43 {
44 return SetUpTestEnvironment.playerManager.
45 GetPlayer(PlayerId).Balance;
46 }
47 }
48 }
To check whether a player can log in, we can wrap the
PlayerManager.LogIn
method into a
bool
function.
Tristan/test/PlayerRegistration.cs
49 public class CheckLogIn:ColumnFixture{
50 public string Username;
51 public string Password;
52 public bool CanLogIn()
53 {
54 try
55 {
56 SetUpTestEnvironment.playerManager.LogIn(Username, Password);
57 return true;
58 }
59 catch (ApplicationException)
60 {
61 return false;
62 }
63 }
64 }
Now we can write the test tables, simply connecting them with symbols.
In order to make the test more customer-friendly, use
keywords
yes
and
no
instead of
true and
false in test tables.
Remember to add the setup for .NET test runner and your DLL path.
9 !|Set Up Test Environment| 10 11 !|Player Registers| 12 |username|password|player id?| 13 |johnsmith|test123|>>player| 14 15 !|Check Stored Details| 16 |player id|username?|balance?| 17 |<Notice that FitNesse shows actual values next to symbol names when the test is executed (Figure 5.1, “Registration tests - first attempt”), enabling us to review what really went on during the test run.




