Ejemplo n.º 1
0
        public void SumbitHandTest()
        {
            var gameProvider = new GameProvider();

            gameProvider.GetNextAvailableGame(ObjectMother.TeamTestData.Team1Id);
            var gameId = gameProvider.GetNextAvailableGame(ObjectMother.TeamTestData.Team2Id);

            var roundProvider = new RoundProvider();

            roundProvider.SumbitHand(Hand.Rock, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team2Id, gameId);

            var roundAdapter = new RoundAdapter();

            var finalRoundResult = roundAdapter.GetCompletedRoundByGameId(gameId);

            if (finalRoundResult.Count() != 1)
            {
                Assert.Fail("Error linking round.");
            }

            foreach (var round in finalRoundResult)
            {
                Assert.AreEqual(round.Result, RoundResult.Team2Won);
            }
        }
Ejemplo n.º 2
0
        // GET: Dashboard
        /// <summary>
        /// Indexes this instance.
        /// </summary>
        /// <returns>ActionResult.</returns>
        public ActionResult Index()
        {
            var gameProvider = new GameProvider();

            var roundsProvider = new RoundProvider();
            var games          = gameProvider.GetAllGamesForDashboardGames(12).ToList();

            List <GameResult> gameResults = new List <GameResult>();

            foreach (var game in games)
            {
                var gameRounds = roundsProvider.GetCompletedRoundByGameId(game.Id).ToList();

                gameResults.Add(new GameResult()
                {
                    Game           = game,
                    Rounds         = gameRounds,
                    LastRound      = gameRounds.OrderByDescending(x => x.SequenceNumber).FirstOrDefault(),
                    Team1WinsCount = gameRounds.Where(x => x.Result == Contracts.Common.RoundResult.Team1Won).ToList().Count,
                    Team2WinsCount = gameRounds.Where(x => x.Result == Contracts.Common.RoundResult.Team2Won).ToList().Count,
                    DrawsCount     = gameRounds.Where(x => x.Result == Contracts.Common.RoundResult.Draw).ToList().Count
                });
            }
            gameResults.Sort();
            ViewBag.Data = gameResults;

            return(View());
        }
Ejemplo n.º 3
0
        public ResponseItem <bool> PlayHand(Guid gameId, Guid teamId, Hand hand)
        {
            var roundProvider = new RoundProvider();
            var outcome       = roundProvider.SumbitHand(hand, teamId, gameId);

            return(new ResponseItem <bool>(ResultCodeEnum.Success)
            {
                Data = outcome.Result
            });
        }
Ejemplo n.º 4
0
        public ResponseList <Contracts.Api.Round> Get(Guid?gameId = null)
        {
            if (gameId == null)
            {
                throw new BadRequestException();
            }

            var provider = new RoundProvider();
            var rounds   = provider.GetCompletedRoundByGameId(gameId.Value);

            return(new ResponseList <Contracts.Api.Round>()
            {
                Data = rounds.Map()
            });
        }
Ejemplo n.º 5
0
        public void FullGameTest()
        {
            var gameProvider  = new GameProvider();
            var roundProvider = new RoundProvider();

            gameProvider.GetNextAvailableGame(ObjectMother.TeamTestData.Team1Id);
            var gameId = gameProvider.GetNextAvailableGame(ObjectMother.TeamTestData.Team2Id);

            // Round 1 - 0 1
            roundProvider.SumbitHand(Hand.Rock, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 2 Draw
            roundProvider.SumbitHand(Hand.Rock, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Rock, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 3 - 0 2
            roundProvider.SumbitHand(Hand.Spock, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 4 - 1 2
            roundProvider.SumbitHand(Hand.Lizard, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Spock, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 5 Draw
            roundProvider.SumbitHand(Hand.Lizard, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Lizard, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 6 Draw
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 7 - 2 2
            roundProvider.SumbitHand(Hand.Scissor, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team2Id, gameId);

            // Round 7 - 2 3
            roundProvider.SumbitHand(Hand.Rock, ObjectMother.TeamTestData.Team1Id, gameId);
            roundProvider.SumbitHand(Hand.Paper, ObjectMother.TeamTestData.Team2Id, gameId);
        }
Ejemplo n.º 6
0
        static void Main()
        {
            var round = RoundProvider.LoadFromFile();

            new RoundProvider(round).SaveToFile();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the completed round by game identifier.
        /// </summary>
        /// <param name="gameId">The game identifier.</param>
        /// <returns>List of Rounds.</returns>
        public IEnumerable <Round> GetCompletedRoundByGameId(Guid gameId)
        {
            var provider = new RoundProvider();

            return(provider.GetCompletedRoundByGameId(gameId));
        }