Source

RockPaperScissors / RockPaperScissors.Specs / GameSpecs.cs

Full commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Machine.Specifications;

namespace RockPaperScissors.Specs
{
  [Subject( "Round" )]
  public class when_playing_a_round
  {
    static Player winner1;
    static Player winner2;
    static Player winner3;
    static Player winner4;
    static Player winner5;
    static Player winner6;

    Because of = () =>
    {
      RockPaperScissors rps = new RockPaperScissors();
      winner1 = rps.Play( "R", "S" );
      winner2 = rps.Play( "S", "R" );

      winner3 = rps.Play( "S", "P" );
      winner4 = rps.Play( "P", "S" );

      winner5 = rps.Play( "P", "R" );
      winner6 = rps.Play( "R", "P" );
    };

    It should_pick_rock_over_scissors = () =>
    {
      winner1.ShouldEqual( Player.First );
      winner2.ShouldEqual( Player.Second );
    };

    It should_pick_scissors_over_paper = () =>
    {
      winner3.ShouldEqual( Player.First );
      winner4.ShouldEqual( Player.Second );
    };

    It should_pick_paper_over_rock = () =>
    {
      winner5.ShouldEqual( Player.First );
      winner6.ShouldEqual( Player.Second );
    };
  }

  [Subject( "Single Round" )]
  public class when_playing_a_single_round_game
  {
    static bool shouldPlayAgainIfNoGamesPlayed;
    static bool shouldPlayAgainIfOneGamePlayed;
    static Player whoWon;

    Because of = () =>
    {
      List<Player> gameResults = new List<Player>();
      SingleRoundStrategy srs = new SingleRoundStrategy();

      shouldPlayAgainIfNoGamesPlayed = srs.ShouldPlayAgain( gameResults );

      gameResults.Add( Player.First );

      shouldPlayAgainIfOneGamePlayed = srs.ShouldPlayAgain( gameResults );

      whoWon = srs.GetWhoWon( gameResults );
    };

    It should_play_again_if_no_games_played = () =>
      shouldPlayAgainIfNoGamesPlayed.ShouldBeTrue();

    It should_not_play_again_if_one_game_played = () =>
      shouldPlayAgainIfOneGamePlayed.ShouldBeFalse();

    It should_know_who_won = () =>
      whoWon.ShouldEqual( Player.First );
  }
}