/// <summary>
 /// Disposes the game settings and starts a new game.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <param name="game">The game, whose methods Dispose and Play are used.</param>
 public override void ProcessCommand(string command, BullsAndCowsGame game)
 {
     if (command == RestartCommand)
     {
         game.Dispose();
         game.Play();
     }
     else if (this.Successor != null)
     {
         this.Successor.ProcessCommand(command, game);
     }
     else
     {
         throw new ArgumentNullException(NullExceptionText);
     }
 }
Esempio n. 2
0
        public void TestPlay()
        {
            BullsAndCowsGame          game     = new BullsAndCowsGame();
            BullsAndCowsGame_Accessor accessor = new BullsAndCowsGame_Accessor();
            StringBuilder             sb       = new StringBuilder();
            StringWriter writer = new StringWriter(sb);

            Console.SetOut(writer);
            StringReader reader = new StringReader("exit");

            Console.SetIn(reader);
            game.Play();
            writer.Close();
            reader.Close();

            string expected = Environment.NewLine + accessor.WelcomeMsg +
                              Environment.NewLine + "Enter your guess or command: " +
                              "Good bye!" + Environment.NewLine;
            string actual = sb.ToString();

            Assert.AreEqual <string>(expected, actual,
                                     EXECUTING_COMMAND_ERROR_MSG);
        }