Ejemplo n.º 1
0
        public async Task <List <Bet> > GetFinishBets(User user, int competitionId)
        {
            var betsByUser = await _betDao.FindBetsByUser(user);

            foreach (var bet in betsByUser)
            {
                var matchInformation = await _matchDao.FindMatch(bet.Match.Id);

                bet.Match = matchInformation;
                var awayTeamInformation = await _teamDao.FindTeam(bet.Match.AwayTeam.Id);

                if (awayTeamInformation != null)
                {
                    bet.Match.AwayTeam = awayTeamInformation;
                }
                var homeTeamInformation = await _teamDao.FindTeam(bet.Match.HomeTeam.Id);

                if (homeTeamInformation != null)
                {
                    bet.Match.HomeTeam = homeTeamInformation;
                }
            }

            var betsByCompetition = betsByUser.FindAll(bet => bet.Match.Competition.Id == competitionId);
            var betsByMatchStatus = betsByCompetition.FindAll(bet => bet.Match.Status == Match.FinishedStatus);

            return(betsByMatchStatus);
        }
Ejemplo n.º 2
0
        AssertThatGetCurrentBetsAndScheduledMatchesCallsFindBetsByUseAndReturnsOnlyScheduledBetsAndMatch()
        {
            _betDao.FindBetsByUser(Arg.Any <User>()).Returns(Task.FromResult(_betsByUser));
            _teamDao.FindTeam(Arg.Any <int>()).Returns(Task.FromResult(_team));
            _matchDao.FindMatch(Arg.Any <int>()).Returns(Task.FromResult(_matchScheduled));
            _matchDao.FindByStatus(Match.ScheduledStatus).Returns(Task.FromResult(_matchesScheduled));

            var currentBetsAndMatch = await _betManager.GetCurrentBetsAndScheduledMatches(_user, 2001);

            await _betDao.Received().FindBetsByUser(Arg.Any <User>());

            await _teamDao.Received().FindTeam(Arg.Any <int>());

            await _matchDao.Received().FindMatch(Arg.Any <int>());

            await _matchDao.Received().FindByStatus(Arg.Any <string>());

            var bets    = currentBetsAndMatch.Bets as List <Bet>;
            var matches = currentBetsAndMatch.Matches as List <Match>;

            Assert.IsNotEmpty(bets, "bets empty");
            Assert.IsTrue(bets.All(b => b.Match.Status == Match.ScheduledStatus));
            Assert.IsTrue(bets.All(b => b.Match.Competition.Id == 2001));

            Assert.IsNotEmpty(matches, "matches empty");
            Assert.IsTrue(matches.All(m => m.Status == Match.ScheduledStatus));
            Assert.IsTrue(matches.All(m => m.Competition.Id == 2001));
        }
        public async Task GetAllMatchForAWeek()
        {
            try
            {
                Console.WriteLine("     ----- Begin Fetch matches ----- ");
                var dateFrom = DateTime.Now.AddDays(-2);
                var dateTo   = DateTime.Now.AddDays(7);

                var response = await _http.GetAsync("matches?dateFrom=" + dateFrom.ToString("yyyy-MM-dd") + "&dateTo=" +
                                                    dateTo.ToString("yyyy-MM-dd"));

                var responseContent = await response.Content.ReadAsStringAsync();

                var json      = JObject.Parse(responseContent);
                var jsonMatch = json["matches"];
                var matches   = JsonConvert.DeserializeObject <List <Match> >(JsonConvert.SerializeObject(jsonMatch));

                foreach (var match in matches)
                {
                    var findMatch = _matchDao.FindMatch(match.Id).Result;
                    if (findMatch == null)
                    {
                        match.HomeTeamRating = 0;
                        match.AwayTeamRating = 0;
                        match.DrawRating     = 0;
                        Console.WriteLine("Add match " + match.Id);
                        _matchDao.AddMatch(match);
                    }
                    else
                    {
                        Console.WriteLine("Update match " + match.Id);
                        match.AwayTeamRating = findMatch.AwayTeamRating;
                        match.HomeTeamRating = findMatch.HomeTeamRating;
                        match.DrawRating     = findMatch.DrawRating;
                        _matchDao.UpdateMatch(findMatch.Id, match);
                        if (findMatch.Status == Match.ScheduledStatus && match.Status == Match.FinishedStatus)
                        {
                            _assignmentPointManager.AddPointToBet(match);
                        }
                    }
                }

                Console.WriteLine("     ----- End Fetch matches ----- ");
            }
            catch (Exception e)
            {
                SingletonManager.Instance.EmailManager.SendWebMasterEmail(e);
                throw;
            }
        }
Ejemplo n.º 4
0
 public void AssertThatFindMatchIsCalled()
 {
     _matchDao.FindMatch(1);
     _filterExpression = new ExpressionFilterDefinition <Match>(match => match.Id == _match.Id);
     _collection.Received().Find(_filterExpression);
 }