Пример #1
0
        public GameInfo Create([FromBody] PlayerInfo playerInfo)
        {
            string name       = string.Empty;
            int    maxPlayers = 0;
            int    rounds     = 0;
            string gameId;

            lock (createLockObject)
            {
                ++gameIdSequence;
                gameId = gameIdSequence.ToString();
            }

            foreach (KeyValuePair <string, string> parameter in Request.GetQueryNameValuePairs())
            {
                switch (parameter.Key)
                {
                case "name":
                    name = parameter.Value;
                    break;

                case "maxPlayers":
                    maxPlayers = int.Parse(parameter.Value);
                    break;

                case "rounds":
                    rounds = int.Parse(parameter.Value);
                    break;

                default:
                    break;
                }
            }

            GameInfo createdGameContext = new GameInfo(rounds)
            {
                Id = gameId, MaxPlayers = maxPlayers, Name = name
            };
            int playerIndex = -1;

            createdGameContext.AddPlayer(playerInfo, ref playerIndex);
            gamesRepository.AddGame(createdGameContext);
            return(createdGameContext);
        }
Пример #2
0
 public ActionResult Index(Games game)
 {
     using (var db = new SimonOMarcusEntities())
     {
         var repos = new GamesRepository();
         repos.AddGame(game.GameId, game.HomeScore, game.AwayScore, game.HomeTeam, game.AwayTeam);
         ViewBag.Mess = "You have registered a game!";
     }
     return(View(game));
 }
Пример #3
0
        public void AddGetGameTest()
        {
            GamesRepository repository = new GamesRepository(MainTest.ConnectionString);
            string          name       = MainTest.GetRandomName(10);

            repository.AddGame(new Game(name));
            _gamesList.Add(name);

            Assert.AreEqual(name, repository.GetGame(name).Name);
        }
Пример #4
0
        public void GetScoresTest()
        {
            PlayersRepository playersRepository = new PlayersRepository(ConnectionString);
            GamesRepository   gamesRepository   = new GamesRepository(ConnectionString);
            ScoresRepository  scoresRepository  = new ScoresRepository(ConnectionString);

            string playerName = GetRandomName(10);
            string gameName   = GetRandomName(10);

            playersRepository.AddPlayer(new Player(playerName));
            _playersList.Add(playerName);

            gamesRepository.AddGame(new Game(gameName));
            _gamesList.Add(gameName);

            Guid scoreId1 = Guid.NewGuid(), scoreId2 = Guid.NewGuid();

            _scoresList.Add(scoreId1);
            _scoresList.Add(scoreId2);

            Score score = new Score(scoreId1, playerName, gameName, scores: 5);

            scoresRepository.AddScore(score);
            score = new Score(scoreId2, playerName, gameName, scores: 15);
            scoresRepository.AddScore(score);

            List <Score> scores = scoresRepository.GetScores(new Game(gameName), new Player(playerName)).ToList();

            if (scores.Find(x => x.Id == scoreId1) == null)
            {
                Assert.Fail($"Expected score id is {scoreId1}");
            }
            if (scores.Find(x => x.Id == scoreId2) == null)
            {
                Assert.Fail($"Expected score id is {scoreId1}");
            }
        }
Пример #5
0
        public void AddGetScoreTest()
        {
            PlayersRepository playersRepository = new PlayersRepository(ConnectionString);
            GamesRepository   gamesRepository   = new GamesRepository(ConnectionString);
            ScoresRepository  scoresRepository  = new ScoresRepository(ConnectionString);

            string playerName = GetRandomName(10);
            string gameName   = GetRandomName(10);

            playersRepository.AddPlayer(new Player(playerName));
            _playersList.Add(playerName);

            gamesRepository.AddGame(new Game(gameName));
            _gamesList.Add(gameName);

            Guid scoreId = Guid.NewGuid();

            _scoresList.Add(scoreId);
            Score score = new Score(scoreId, playerName, gameName, scores: 5);

            scoresRepository.AddScore(score);

            Assert.AreEqual(scoreId, scoresRepository.GetScore(scoreId).Id);
        }