Example #1
0
        public async Task AssertThatCalculateMatchRatingCallsFindBetsByMatchAndUpdateMatches()
        {
            _betDao.FindBetsByMatch(_match).Returns(Task.FromResult(_bets));
            _matchManager.CalculateMatchRating(_match);
            await _betDao.Received().FindBetsByMatch(Arg.Any <Match>());

            _matchDao.Received().UpdateMatch(Arg.Any <int>(), Arg.Any <Match>());
        }
Example #2
0
 public void AssertThatAddPointToBetCallsRightUpdateFunctionsForWrongBets(Match match, List <Bet> wrongBets)
 {
     _betDao.FindBetsByMatch(match).Returns(Task.FromResult(wrongBets));
     _assignmentPointManager.AddPointToBet(match);
     foreach (var bet in wrongBets)
     {
         _betDao.Received().UpdateBetPointsWon(bet, Bet.WrongBet);
         _betDao.Received().UpdateBetStatus(bet, Bet.WrongStatus);
     }
 }
        public async void CalculateMatchRating(Match match)
        {
            var bets = await _betDao.FindBetsByMatch(match);

            var homeTeamCount = bets.FindAll(bet => bet.AwayTeamScore < bet.HomeTeamScore).Count;
            var awayTeamCount = bets.FindAll(bet => bet.AwayTeamScore > bet.HomeTeamScore).Count;
            var drawCount     = bets.FindAll(bet => bet.AwayTeamScore == bet.HomeTeamScore).Count;


            match.DrawRating     = drawCount == 0d ? 0d : 1d / (Convert.ToDouble(drawCount) / Convert.ToDouble(bets.Count));
            match.HomeTeamRating = homeTeamCount == 0d
                ? 0d
                : 1d / (Convert.ToDouble(homeTeamCount) / Convert.ToDouble(bets.Count));
            match.AwayTeamRating = awayTeamCount == 0d
                ? 0d
                : 1d / (Convert.ToDouble(awayTeamCount) / Convert.ToDouble(bets.Count));

            _matchDao.UpdateMatch(match.Id, match);
        }
        public async void AddPointToBet(Match match)
        {
            var bets = await _betDao.FindBetsByMatch(match);

            foreach (var bet in bets)
            {
                var betTeamHightScore = GetTeamNameWithTheBestHightScore(bet);
                var multiply          = bet.Multiply;
                if (multiply == 0)
                {
                    multiply = 1;
                }

                if (match.Score.FullTime.HomeTeam == bet.HomeTeamScore &&
                    match.Score.FullTime.AwayTeam == bet.AwayTeamScore)
                {
                    switch (betTeamHightScore)
                    {
                    case "AWAY":
                        _betDao.UpdateBetPointsWon(bet,
                                                   Bet.PerfectBet * match.AwayTeamRating * multiply);
                        _betDao.UpdateBetStatus(bet, Bet.PerfectStatus);
                        continue;

                    case "HOME":
                        _betDao.UpdateBetPointsWon(bet,
                                                   Bet.PerfectBet * match.HomeTeamRating * multiply);
                        _betDao.UpdateBetStatus(bet, Bet.PerfectStatus);
                        continue;

                    case "DRAW":
                        _betDao.UpdateBetPointsWon(bet,
                                                   Bet.PerfectBet * match.DrawRating * multiply);
                        _betDao.UpdateBetStatus(bet, Bet.PerfectStatus);
                        continue;
                    }
                }

                switch (betTeamHightScore)
                {
                case "HOME" when match.Score.Winner == "HOME_TEAM":
                    _betDao.UpdateBetPointsWon(bet,
                                               Bet.OkBet * match.HomeTeamRating * multiply);
                    _betDao.UpdateBetStatus(bet, Bet.OkStatus);
                    continue;

                case "AWAY" when match.Score.Winner == "AWAY_TEAM":
                    _betDao.UpdateBetPointsWon(bet,
                                               Bet.OkBet * match.AwayTeamRating * multiply);
                    _betDao.UpdateBetStatus(bet, Bet.OkStatus);
                    continue;

                case "DRAW" when match.Score.Winner == "DRAW":
                    _betDao.UpdateBetPointsWon(bet, Bet.OkBet * match.DrawRating * multiply);
                    _betDao.UpdateBetStatus(bet, Bet.OkStatus);
                    continue;

                default:
                    _betDao.UpdateBetPointsWon(bet, Bet.WrongBet);
                    _betDao.UpdateBetStatus(bet, Bet.WrongStatus);
                    break;
                }
            }
        }
Example #5
0
 public void AssertThatFindBetsByMatchIsCalled()
 {
     _betDao.FindBetsByMatch(_match);
     _filterExpression = new ExpressionFilterDefinition <Bet>(b => b.Match.Id == _match.Id);
     _collection.Received().Find(_filterExpression);
 }