internal BatterInnings(TeamInnings teamInnings, Player batter) { if (teamInnings == null) throw new ArgumentNullException("teamInnings"); if (batter == null) throw new ArgumentNullException("batter"); this.teamInnings = teamInnings; this.batter = batter; notOut = true; startTime = DateTime.Now; }
public virtual BatterInnings GetBatterInnings(Player batter) { if (batter == null) throw new ArgumentNullException("batter"); var foundBatterInnings = batterInnings.SingleOrDefault(b => b.Batter.Equals(batter)); if (foundBatterInnings == null) throw new InvalidOperationException("Batting not commenced for player: " + batter); return foundBatterInnings; }
internal Delivery(Player bowler, Player batter, int runsScored) { if (bowler == null) throw new ArgumentNullException("bowler"); if (batter == null) throw new ArgumentNullException("batter"); if (runsScored < 0) throw new ArgumentOutOfRangeException("runsScored", @"Cannot score less than 0 runs!"); Bowler = bowler; Batter = batter; RunsScored = runsScored; }
public virtual BatterInnings CommenceBatterInnings(Player batter) { if (batter == null) throw new ArgumentNullException("batter"); if (! BattingTeam.Members.Contains(batter)) throw new InvalidOperationException("Player not on batting team!"); if (batterInnings.Any(b => b.Batter.Equals(batter))) throw new InvalidOperationException("Player already commenced batting!"); var batterInningsSingular = new BatterInnings(this, batter); batterInnings.Add(batterInningsSingular); return batterInningsSingular; }
public virtual void RecordDelivery(Player batter, int runsScored) { if (batter == null) throw new ArgumentNullException("batter"); if (IsOver()) throw new InvalidOperationException("Over is over so can't fit more deliveries!"); var batterInnings = BattingTeamInnings.GetBatterInnings(batter); if (! batterInnings.NotOut) throw new InvalidOperationException("Batter is out!"); var delivery = new Delivery(Bowler, batter, runsScored); deliveries.Add(delivery); batterInnings.BallFaced(delivery); }
public virtual void RemoveMember(Player player) { if (! IsPlayerAlreadyInTeam(player)) throw new InvalidOperationException("Player not in team!"); if (player.Equals(TwelfthMan)) { TwelfthMan = null; } else { members.Remove(player); } }
public virtual void AddMember(Player player) { if (IsPlayerAlreadyInTeam(player)) throw new ArgumentException("Player is already in the team!"); if (IsTeamComplete()) throw new InvalidOperationException("Maximum of 11 players in a team, plus 12th man"); if (members.Count < 11) { members.Add(player); } else { twelfthMan = player; } }
internal Over(TeamInnings battingTeamInnings, Player bowler) { BattingTeamInnings = battingTeamInnings; Bowler = bowler; }
public virtual bool IsPlayerAlreadyInTeam(Player player) { // notice I can use Contains() and Equals() instead of digging down to ID's. // this also works for value objects. Implement Equals()! return members.Contains(player) || player.Equals(TwelfthMan); }
public Player SetUpPlayer(string firstName, string lastName, string countryName) { using (var uow = unitOfWorkFactory.BeginUnitOfWork()) { var country = uow.Query<Country>().Single(x => x.Name == countryName); var player = new Player(firstName, lastName, country); uow.Add(player); uow.Complete(); return player; } }
internal BowlingSpell(Player bowler) { this.bowler = bowler; }
private BowlingSpell GetBowlingSpell(Player bowler) { var bowlingSpell = bowlingSpells.SingleOrDefault(bs => bs.Bowler.Equals(bowler)); if (bowlingSpell == null) { bowlingSpell = new BowlingSpell(bowler); bowlingSpells.Add(bowlingSpell); } return bowlingSpell; }
public virtual Over NewOver(Player bowler) { if (bowler == null) throw new ArgumentNullException("bowler"); if (! FieldingTeam.Members.Contains(bowler)) throw new InvalidOperationException("Player not a member of the fielding team! " + bowler); var over = new Over(this, bowler); overs.Add(over); GetBowlingSpell(bowler).RecordOverCommenced(over); return over; }
internal Over(TeamInnings battingTeamInnings, Player bowler) { this.battingTeamInnings = battingTeamInnings; this.bowler = bowler; }