예제 #1
0
 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;
 }
예제 #2
0
        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;
        }
예제 #3
0
        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;
        }
예제 #4
0
        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;
        }
예제 #5
0
파일: Over.cs 프로젝트: simonfox/DDDIntro
        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);
        }
예제 #6
0
파일: Team.cs 프로젝트: simonfox/DDDIntro
        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);
            }
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
파일: Over.cs 프로젝트: simonfox/DDDIntro
 internal Over(TeamInnings battingTeamInnings, Player bowler)
 {
     BattingTeamInnings = battingTeamInnings;
     Bowler = bowler;
 }
예제 #9
0
 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);
 }
예제 #10
0
        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;
            }
        }
예제 #11
0
 internal BowlingSpell(Player bowler)
 {
     this.bowler = bowler;
 }
예제 #12
0
 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;
 }
예제 #13
0
        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;
        }
예제 #14
0
 internal Over(TeamInnings battingTeamInnings, Player bowler)
 {
     this.battingTeamInnings = battingTeamInnings;
     this.bowler = bowler;
 }