using System.Collections.Generic; using NUnit.Framework; using PokerTournamentManager.Framework; [TestFixture] public class TableTests { #region SeatPlayers [Test] public void SeatPlayersWithZeroPlayers() { SeatPlayers(new Table(), 0); } [Test] public void SeatPlayersWithEqualPlayersAsAvailableSeats() { Table table = new Table(); SeatPlayers(table, table.AvailableSeats); } [Test] public void SeatPlayersWithLessPlayersThanAvailableSeats() { Table table = new Table(); SeatPlayers(table, table.AvailableSeats - 1); } [Test] [ExpectedException(typeof(NoAvailableSeatsException))] public void SeatPlayersWithMorePlayersThanAvailableSeats() { Table table = new Table(); SeatPlayers(table, table.AvailableSeats + 1); } private static void SeatPlayers(Table table, int numberOfPlayers) { // Create less number of players than there are seats List players = CreatePlayers(numberOfPlayers); // Set the available sets at the current available seats // minus the one's we're filling. int expectedAvailableSeats = table.AvailableSeats - players.Count; // Try to seat 'em table.SeatPlayers(players); // Make sure we have as many seats left as we expect Assert.AreEqual(expectedAvailableSeats, table.AvailableSeats); } private static List CreatePlayers(int numPlayers) { List players = new List(); for (int i = 0; i < numPlayers; i++) { players.Add(new Player()); } Assert.AreEqual(players.Count, numPlayers); return players; } #endregion } [TestFixture] public class SeatTests { #region IsAvailable [Test] public void IsAvailableIsFalseWhenCurrentPlayerIsNull() { Seat seat = new Seat(); Assert.IsNull(seat.CurrentPlayer); Assert.IsTrue(seat.IsAvailable); } [Test] public void IsAvailableIsTrueWhenCurrentPlayerIsNotNull() { Seat seat = new Seat(); Assert.IsNull(seat.CurrentPlayer); seat.CurrentPlayer = new Player(); Assert.IsFalse(seat.IsAvailable); } #endregion }