Пример #1
0
        void AdvanceToNextInningTeamBatter()
        {
            if (AdvanceToNextHalfInning == true)
            {
                AdvanceToNextInningTeam();
            }
            else
            {
                if (CurrentGameInning != null && CurrentGameInningTeam != null)
                {
                    Guid?nextPlayerToBat = GameInningTeamBatter.GetNextGameBatterPlayerId(GameId, AtBatTeamId);
                    if (nextPlayerToBat.HasValue)
                    {
                        int batterSequence = CurrentGameInningTeamBatter != null ? CurrentGameInningTeamBatter.Sequence + 1 : 0;

                        GameInningTeamBatterDto gameInningTeamBatter = new GameInningTeamBatterDto()
                        {
                            PlayerId         = nextPlayerToBat.Value,
                            GameInningTeamId = CurrentGameInningTeam.GameInningTeamId,
                            EventType        = (int)EventType.Unknown,
                            RBIs             = 0,
                            Sequence         = InningBatterSequence
                        };
                        GameInningTeamBatter.Save(gameInningTeamBatter);
                        FillCurrentAtBatTeamPlayer();
                    }
                }
            }
        }
Пример #2
0
        public void NextGameInningTeamBatterTest()
        {
            //seed teams
            Guid teamOneId = SeedTeam();
            Guid teamTwoId = SeedTeamTwo();

            //seed players
            Guid playerOneId   = SeedPlayer();
            Guid playerTwoId   = SeedPlayerTwo();
            Guid playerThreeId = SeedPlayerThree();
            Guid playerFourId  = SeedPlayerFour();

            //seed team lineups
            List <Guid> teamOneLineup = new List <Guid> {
                playerOneId, playerTwoId, playerThreeId, playerFourId
            };

            SeedTeamPlayerLineup(teamOneId, teamOneLineup);

            List <Guid> teamTwoLineup = new List <Guid> {
                playerFourId, playerThreeId, playerTwoId, playerOneId
            };

            SeedTeamPlayerLineup(teamTwoId, teamTwoLineup);

            //seed game
            Guid gameId        = SeedGame();
            Guid gameTeamOneId = SeedGameTeam(gameId, teamOneId, battingSequence: 0);
            Guid gameTeamTwoId = SeedGameTeam(gameId, teamTwoId, battingSequence: 1);

            GameInningDto gameInningDto = new GameInningDto()
            {
                InningNumber = 1,
                GameId       = gameId,
                GameInningId = Guid.NewGuid()
            };

            GameInning.AddNew(gameInningDto);

            GameInningTeamDto gameInningTeamDto = new GameInningTeamDto()
            {
                GameTeamId       = gameTeamOneId,
                GameInningId     = gameInningDto.GameInningId,
                GameInningTeamId = Guid.NewGuid()
            };

            GameInningTeam.AddNew(gameInningTeamDto);

            //see if the first player in the linup is selected
            Guid?nextBatterId = GameInningTeamBatter.GetNextGameBatterPlayerId(gameId, teamOneId);

            Assert.AreEqual(nextBatterId, playerOneId);

            GameInningTeamBatterDto gameInningTeamBatterDto = new GameInningTeamBatterDto()
            {
                GameInningTeamId       = gameInningTeamDto.GameInningTeamId,
                PlayerId               = playerOneId,
                EventType              = (int)EventType.Out,
                GameInningTeamBatterId = Guid.NewGuid(),
                Sequence               = 0
            };

            GameInningTeamBatter.AddNew(gameInningTeamBatterDto);

            //see if the second player in the lineup is selected
            nextBatterId = GameInningTeamBatter.GetNextGameBatterPlayerId(gameId, teamOneId);
            Assert.AreEqual(nextBatterId, playerTwoId);

            GameInningTeamBatterDto gameInningTeamBatter2Dto = new GameInningTeamBatterDto()
            {
                GameInningTeamId       = gameInningTeamDto.GameInningTeamId,
                PlayerId               = playerTwoId,
                EventType              = (int)EventType.Single,
                GameInningTeamBatterId = Guid.NewGuid(),
                Sequence               = 1
            };

            GameInningTeamBatter.AddNew(gameInningTeamBatter2Dto);

            //see if the thrid batter is selected
            nextBatterId = GameInningTeamBatter.GetNextGameBatterPlayerId(gameId, teamOneId);
            Assert.AreEqual(nextBatterId, playerThreeId);

            GameInningTeamBatterDto gameInningTeamBatter3Dto = new GameInningTeamBatterDto()
            {
                GameInningTeamId       = gameInningTeamDto.GameInningTeamId,
                PlayerId               = playerThreeId,
                EventType              = (int)EventType.Single,
                GameInningTeamBatterId = Guid.NewGuid(),
                Sequence               = 2
            };

            GameInningTeamBatter.AddNew(gameInningTeamBatter3Dto);

            //see if fourth batter is selected
            nextBatterId = GameInningTeamBatter.GetNextGameBatterPlayerId(gameId, teamOneId);
            Assert.AreEqual(nextBatterId, playerFourId);

            GameInningTeamBatterDto gameInningTeamBatter4Dto = new GameInningTeamBatterDto()
            {
                GameInningTeamId       = gameInningTeamDto.GameInningTeamId,
                PlayerId               = playerFourId,
                EventType              = (int)EventType.Single,
                GameInningTeamBatterId = Guid.NewGuid(),
                Sequence               = 3
            };

            GameInningTeamBatter.AddNew(gameInningTeamBatter4Dto);

            //see if first batter is up again
            nextBatterId = GameInningTeamBatter.GetNextGameBatterPlayerId(gameId, teamOneId);
            Assert.AreEqual(nextBatterId, playerOneId);

            //cleanup test data
            DeleteSeededTeam(teamOneId);
            DeleteSeededTeam(teamTwoId);
            DeleteSeededTeamPlayerLineup(teamOneId);
            DeleteSeededTeamPlayerLineup(teamTwoId);
            DeleteSeededGame(gameId);
            DeleteSeededPlayer(playerOneId);
            DeleteSeededPlayer(playerTwoId);
            DeleteSeededPlayer(playerThreeId);
            DeleteSeededPlayer(playerFourId);
        }