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 void AssertThatFindByStatusIsCalled() { _matchDao.FindByStatus(_match.Status); _filterExpression = new ExpressionFilterDefinition <Match>(m => m.Status == _match.Status); _collection.Received().Find(_filterExpression); }
public async Task <dynamic> GetCurrentBetsAndScheduledMatches(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 now = DateTime.UtcNow; var betsByCompetition = betsByUser.FindAll(bet => bet.Match.Competition.Id == competitionId); var betsByMatchStatus = betsByCompetition.FindAll(bet => bet.Match.Status == Match.ScheduledStatus); var matchByStatus = await _matchDao.FindByStatus(Match.ScheduledStatus); var matchesByCompetition = matchByStatus.FindAll(m => m.Competition.Id == competitionId && now <= DateTimeOffset.Parse(m.UtcDate)); foreach (var bet in betsByMatchStatus) { var findMatch = matchesByCompetition.Find(m => m.Id == bet.Match.Id); if (findMatch != null) { matchesByCompetition.Remove(findMatch); } } foreach (var match in matchesByCompetition) { var awayTeamInformation = await _teamDao.FindTeam(match.AwayTeam.Id); if (awayTeamInformation != null) { match.AwayTeam = awayTeamInformation; } var homeTeamInformation = await _teamDao.FindTeam(match.HomeTeam.Id); if (homeTeamInformation != null) { match.HomeTeam = homeTeamInformation; } } dynamic betsAndMatches = new ExpandoObject(); betsAndMatches.Bets = betsByMatchStatus; betsAndMatches.Matches = matchesByCompetition; return(betsAndMatches); }