Esempio n. 1
0
        private async Task <string> CreateRoundAsync()
        {
            var(_, games) = await m_gameService.SearchAsync(new Pagination(), new SimpleFilter <Game>());

            var game  = games.First();
            var round = new Round {
                Id = Guid.NewGuid(), GameId = game.Id
            };
            await m_roundService.AddAsync(round);

            var rand          = new Random();
            var categoryValue = listOfCategories.ElementAt(rand.Next(0, listOfCategories.Count)).Key;
            var category      = new Category {
                Id = Guid.NewGuid(), RoundId = round.Id, Value = categoryValue
            };
            await m_categoryService.AddAsync(category);

            foreach (KeyValuePair <string, List <string> > entry in listOfCategories)
            {
                if (entry.Key.Equals(categoryValue))
                {
                    foreach (string value in entry.Value)
                    {
                        await m_correctResponsesService.AddAsync(new CorrectResponses { Id = Guid.NewGuid(), CategoryId = category.Id, Values = value });
                    }
                }
            }

            return(categoryValue);
        }
Esempio n. 2
0
        public async Task <ActionResult <bool> > Post([FromBody] List <RoundDto> rounds)
        {
            try
            {
                await service.AddAsync(rounds);

                return(Ok(true));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> PostAsync([FromBody] RoundInputModel model)
        {
            if (ModelState.IsValid)
            {
                var round = new Round(model.Description, model.Date, model.RankingId);
                await _roundService.AddAsync(round);

                if (ValidOperation())
                {
                    return(Created(GetRouteById(round.Id), new { id = round.Id }));
                }

                return(ResponseInvalid());
            }

            NotifyModelStateError();

            return(ResponseInvalid());
        }
Esempio n. 4
0
        public async Task AddAsyncTest()
        {
            var round = new Round
            {
                Name   = "First",
                Topics = new List <Topic>
                {
                    new Topic
                    {
                        Name      = "C#",
                        Questions = new List <Question>
                        {
                            new Question
                            {
                                Text  = "g",
                                Price = 100
                            }
                        }
                    },
                    new Topic
                    {
                        Name      = "Java",
                        Questions = new List <Question>
                        {
                            new Question
                            {
                                Text  = "g",
                                Price = 200
                            }
                        }
                    }
                }
            };

            var flag = await _roundService.AddAsync(round);

            await _roundService.RemoveAsync(round.Id);

            Assert.IsTrue(flag);
        }
Esempio n. 5
0
        public async void CreateGames()
        {
            Random r           = new Random();
            var    numberGames = 0;

            Console.WriteLine("Creating 100 games");
            Console.WriteLine();
            Console.WriteLine();
            while (numberGames < 1)
            {
                numberGames++;

                Console.WriteLine($"Start the {numberGames} game ...");
                Console.WriteLine();

                await CreatePlayer(1);
                await CreatePlayer(2);

                Game game;
                try
                {
                    game = await _gameService.AddAsync(new Game
                    {
                        EndGame = false,
                        PlayerGameWinnerName = ""
                    });


                    Console.WriteLine($"Game {game.Id} Created Succefully");
                    Console.WriteLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex}");
                    continue;
                }


                var numberRound = 1;
                var player1     = await _playerService.GetPlayerByNumber(1);

                var player2 = await _playerService.GetPlayerByNumber(2);

                while (true)
                {
                    Console.WriteLine($"Round {numberRound}");
                    numberRound++;
                    Round round;
                    try
                    {
                        var player1Move = (Move)r.Next(1, 4);
                        round = await _roundService.AddAsync(new Round
                        {
                            Player1Move = player1Move,
                            GameId      = game.Id
                        });

                        Console.WriteLine($"{player1.PlayerName} played {player1Move}");
                        Console.WriteLine();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error with Player 1 move: {ex}");
                        break;
                    }

                    try
                    {
                        Console.WriteLine(round.Id);
                        var player2Move = (Move)r.Next(1, 4);

                        var rnd = await _roundService.SingleOrDefaultAsync(round.Id);

                        if (rnd != null)
                        {
                            game = await _roundService.CompleteRound(rnd, player2Move);
                        }

                        Console.WriteLine($"{player2.PlayerName} played {player2Move}");
                        Console.WriteLine();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error with Player 2 move: {ex}");
                        break;
                    }

                    if (game.EndGame)
                    {
                        Console.WriteLine($"Game {numberGames} winner is {game.PlayerGameWinnerName}");
                        Console.WriteLine();
                        break;
                    }
                }
            }
            Console.WriteLine("Statics for players");
            foreach (var name in PlayerNames)
            {
                try
                {
                    var result = await _gameService.Statistics(name);

                    Console.WriteLine($"{name} won {result.Count} games");
                    Console.WriteLine();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error: {ex}");
                    continue;
                }
            }
            Console.WriteLine("Test Finish");
        }