コード例 #1
0
        public void AddUpdateGameInningTest()
        {
            Guid seedGameId = SeedGame();

            GameInningDto dto = new GameInningDto()
            {
                GameId       = seedGameId,
                InningNumber = TEST_INNING_NUMBER
            };

            var addResult = GameInning.AddNew(dto);

            Assert.IsTrue(addResult.IsSuccess);

            var item = GameInning.GetGameInning(seedGameId, TEST_INNING_NUMBER);

            Assert.IsNotNull(item);
            Assert.AreEqual(seedGameId, item.GameId);
            Assert.AreEqual(TEST_INNING_NUMBER, item.InningNumber);

            dto.InningNumber = 4;
            addResult        = GameInning.AddNew(dto);
            Assert.IsTrue(addResult.IsSuccess);

            item = GameInning.GetGameInning(seedGameId, inningNumber: 4);

            dto.GameInningId = item.GameInningId;
            dto.DeleteDate   = DateTime.UtcNow;
            var updateResult = GameInning.Update(dto);

            Assert.IsTrue(updateResult.IsSuccess);

            item = GameInning.GetGameInning(seedGameId, inningNumber: 4);
            Assert.IsNotNull(item);
            Assert.IsNotNull(item.DeleteDate);

            dto.DeleteDate = null;
            updateResult   = GameInning.Update(dto);
            Assert.IsTrue(updateResult.IsSuccess);

            item = GameInning.GetGameInning(seedGameId, inningNumber: 4);
            Assert.IsNotNull(item);
            Assert.IsNull(item.DeleteDate);

            var items = GameInning.GetGameInnings(seedGameId);

            Assert.IsTrue(items.Count >= 1);

            foreach (var i in items)
            {
                var removeResult = GameInning.Remove(i.GameId, i.InningNumber);
                Assert.IsTrue(removeResult.IsSuccess);
            }

            items = GameInning.GetGameInnings(seedGameId);
            Assert.IsTrue(items.Count == 0);

            DeleteSeededGame(seedGameId);
        }
コード例 #2
0
        private void UpdateGameInning(GameInningDto gameInning)
        {
            string updateQuery = @"UPDATE GameInning
            SET GameInningId = @GameInningId,
            DeleteDate = @DeleteDate 
            WHERE GameId = @GameId AND InningNumber = @InningNumber";

            Connection.BeginTransaction();
            Connection.Execute(updateQuery, gameInning);
            Connection.Commit();
        }
コード例 #3
0
 /// <summary>
 /// data layer will determine add vs update
 /// </summary>
 /// <param name="gameInning"></param>
 public void Save(GameInningDto gameInning)
 {
     if (ExistsInDb(gameInning))
     {
         Update(gameInning);
     }
     else
     {
         AddNew(gameInning);
     }
 }
コード例 #4
0
        public void GameNextInningTeamTest()
        {
            Guid teamOneId = SeedTeam();
            Guid teamTwoId = SeedTeamTwo();

            var teamOne = Team.GetTeam(teamOneId);
            var teamTwo = Team.GetTeam(teamTwoId);

            Assert.IsNotNull(teamOne);
            Assert.IsNotNull(teamTwo);

            Guid gameId = SeedGame();

            Guid gtOneId = SeedGameTeam(gameId, teamOne.TeamId, battingSequence: 0);
            Guid gtTwoId = SeedGameTeam(gameId, teamTwo.TeamId, battingSequence: 1);

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

            GameInning.AddNew(gameInningDto);

            Guid?nextTeamId = GameInningTeam.GetNextAtBatTeamId(gameId);

            Assert.AreEqual(nextTeamId, teamOne.TeamId);

            GameInningTeamDto dto = new GameInningTeamDto()
            {
                GameInningTeamId = Guid.NewGuid(),
                GameTeamId       = gtOneId,
                GameInningId     = gameInningDto.GameInningId,
                Outs             = 0,
                Score            = 0
            };

            GameInningTeam.AddNew(dto);

            nextTeamId = GameInningTeam.GetNextAtBatTeamId(gameId);
            Assert.AreEqual(nextTeamId, teamTwo.TeamId);

            gameInningDto.InningNumber = 2;
            gameInningDto.GameInningId = Guid.NewGuid();
            GameInning.AddNew(gameInningDto);

            nextTeamId = GameInningTeam.GetNextAtBatTeamId(gameId);
            Assert.AreEqual(teamOne.TeamId, nextTeamId);

            DeleteSeededGame(gameId);
            DeleteSeededTeam(teamOneId);
            DeleteSeededTeam(teamTwoId);
        }
コード例 #5
0
        public void InvalidGameIdTest()
        {
            GameInningDto dto = new GameInningDto()
            {
                InningNumber = TEST_INNING_NUMBER
            };

            var result = GameInning.AddNew(dto);

            Assert.IsFalse(result.IsSuccess);
        }
コード例 #6
0
        public bool ExistsInDb(GameInningDto gameInning)
        {
            Connection.BeginTransaction();

            var rows = Connection.Query <int>(@"SELECT COUNT(1) as 'Count' FROM GameInning 
            WHERE GameId = @GameId AND InningNumber = @InningNumber",
                                              new { gameInning.GameId, gameInning.InningNumber });

            Connection.Commit();

            return(rows.First() > 0);
        }
コード例 #7
0
        void AdvanceToNextInning(bool isBeginningOfGame = false)
        {
            GameInningDto gameInning = new GameInningDto()
            {
                InningNumber = GameInning.GetNextGameInningNumber(GameId),
                GameId       = GameId
            };

            GameInning.Save(gameInning);
            FillCurrentInning();
            AdvanceToNextInningTeam(isBeginningOfGame);
        }
コード例 #8
0
        public void InvalidGameInningIdTest()
        {
            GameInningDto dto = new GameInningDto()
            {
                GameId       = Guid.NewGuid(),
                InningNumber = TEST_INNING_NUMBER
            };

            var result = GameInning.Update(dto);

            Assert.IsFalse(result.IsSuccess);
        }
コード例 #9
0
        public void InvalidInningNumberTest()
        {
            GameInningDto dto = new GameInningDto()
            {
                GameId       = Guid.NewGuid(),
                InningNumber = -2
            };

            var result = GameInning.AddNew(dto);

            Assert.IsFalse(result.IsSuccess);
        }
コード例 #10
0
        private void InsertGameInning(GameInningDto gameInning)
        {
            string insertQuery = @"INSERT INTO GameInning
                    (GameInningId, GameId, InningNumber, DeleteDate)
                    VALUES(
                        @GameInningId, 
                        @GameId, 
                        @InningNumber, 
                        @DeleteDate)";

            Connection.BeginTransaction();
            Connection.Execute(insertQuery, gameInning);
            Connection.Commit();
        }
コード例 #11
0
        public Guid SeedGameInning()
        {
            Guid gameInningId = Guid.NewGuid();
            Guid seedGameId   = SeedGame();

            GameInningDto dto = new GameInningDto()
            {
                GameInningId = gameInningId,
                GameId       = seedGameId,
                InningNumber = 1
            };

            GameInning.AddNew(dto);

            return(gameInningId);
        }
コード例 #12
0
        public GameInningDto LoadByCompositeKey(Guid gameId, int inningNumber)
        {
            GameInningDto gameInning = null;

            Connection.BeginTransaction();

            var result = Connection.Query <GameInningDto>(
                SELECT_QUERY + " WHERE GameId = @GameId " +
                "AND InningNumber = @InningNumber",
                new { GameId = gameId.ToString(), InningNumber = inningNumber });

            gameInning = result.FirstOrDefault();

            Connection.Commit();

            return(gameInning);
        }
コード例 #13
0
 public void Update(GameInningDto gameInning)
 {
     UpdateGameInning(gameInning);
 }
コード例 #14
0
 public void AddNew(GameInningDto gameInning)
 {
     InsertGameInning(gameInning);
 }
コード例 #15
0
        public void GameInningTeamBatterCurrentBatterTest()
        {
            //seed teams
            Guid teamOneId = SeedTeam();
            Guid teamTwoId = SeedTeamTwo();

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

            //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);


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

            GameInningTeamBatter.AddNew(gameInningTeamBatterDto);

            var currentBatter = GameInningTeamBatter.GetCurrentGameInningTeamBatter(gameId);

            Assert.IsNotNull(currentBatter);
            Assert.AreEqual(playerOneId, currentBatter.PlayerId);

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

            GameInningTeamBatter.AddNew(gameInningTeamBatter2Dto);

            currentBatter = GameInningTeamBatter.GetCurrentGameInningTeamBatter(gameId);
            Assert.IsNotNull(currentBatter);
            Assert.AreEqual(currentBatter.PlayerId, playerTwoId);

            //cleanup test data
            DeleteSeededTeam(teamOneId);
            DeleteSeededTeam(teamTwoId);
            DeleteSeededGame(gameId);
            DeleteSeededPlayer(playerOneId);
            DeleteSeededPlayer(playerTwoId);
            DeleteSeededPlayer(playerThreeId);
            DeleteSeededPlayer(playerFourId);
        }
コード例 #16
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);
        }