public async Task DeleteMatch_Cheсk() { IMatchListService matchListService = GetMatchListService(); await matchListService.CreateMatch("user"); var matchIds = await matchListService.GetMatches("user", 10, 0); var matchId = matchIds.SingleOrDefault().MatchId; await matchListService.DeleteMatch("user", matchId); var matches = await matchListService.GetMatches("user", 10, 0); matches.Should().BeNullOrEmpty(); }
public async Task GetMatches_Check_Empty() { IMatchListService matchListService = GetMatchListService(); await matchListService.CreateMatch("user"); var match = await matchListService.GetMatches("user2", 10, 0); match.Should().BeNullOrEmpty(); }
public async Task DeleteMatch_Cheсk_Not_This_User() { IMatchListService matchListService = GetMatchListService(); await matchListService.CreateMatch("user"); var matchIds = await matchListService.GetMatches("user", 10, 0); var matchId = matchIds.SingleOrDefault().MatchId; new Func <Task>(() => matchListService.DeleteMatch("user1", matchId)).ShouldThrow <KeyNotFoundException>(); }
public async Task GetMatchService_Cheсk_Not_This_User_and_Match() { IMatchListService matchListService = GetMatchListService(); await matchListService.CreateMatch("user"); var matchIds = await matchListService.GetMatches("user", 10, 0); var matchId = matchIds.SingleOrDefault().MatchId; new Func <Task>(() => matchListService.GetMatchService("otherUser", "otherId")) .ShouldThrow <KeyNotFoundException>(); }
public async Task GetMatchService_Cheсk() { IMatchListService matchListService = GetMatchListService(); await matchListService.CreateMatch("user"); var matchIds = await matchListService.GetMatches("user", 10, 0); var matchId = matchIds.SingleOrDefault().MatchId; var matchService = await matchListService.GetMatchService("user", matchId); matchService.Should().NotBeNull(); }
public async Task <IActionResult> Index(int count = 10, int skip = 0, IEnumerable <string> player = null, IEnumerable <MatchState> state = null, Sort sort = Sort.None) { //await _matchListService.RebuildMatchInfosAsync(); player = player ?? Enumerable.Empty <string>(); state = state ?? Enumerable.Empty <MatchState>(); var totalCount = await _matchListService.GetMatchCount(UserId, player, state); var(newCount, newSkip) = CorrectPagination(totalCount, count, skip); if (count != newCount || skip != newSkip) { return(RedirectToAction(nameof(Index), new { count = newCount, skip = newSkip })); } var matchInfoModels = await _matchListService.GetMatches(UserId, count, skip, player, state, sort); var containerForMatchModel = new ContainerForMatchModel { ListMatchModelView = matchInfoModels.Select(matchInfo => new MatchModelView { Id = matchInfo.MatchId, Players = matchInfo.FirstPlayer != null ? matchInfo.FirstPlayer + " - " + matchInfo.SecondPlayer : "None", Date = matchInfo.MatchStartedAt != DateTime.MinValue ? matchInfo.MatchStartedAt.ToString() : "None", Status = matchInfo.State.ToString(), Score = matchInfo.MatchScore }).ToList(), TotalCount = totalCount, Count = newCount, Skip = newSkip, FilterPayers = (await _matchListService.GetPlayers(UserId)).ToList(), SelectedPlayers = player, SelectedState = state, Sort = sort }; return(View(containerForMatchModel)); }
public async Task <IEnumerable <PlayerStatsModel> > GetPlayersStatsModelInner(string userId, int count, int skip, SortForPlayerStats sort, string player = null, string playerUserId = null) { var players = player == null ? null : Enumerable.Repeat(player, 1); var total = await _matchListService.GetMatchCount(userId, players); var mathes = await _matchListService.GetMatches(userId, total == 0? 1 : total, 0, players); var result = new Dictionary <string, PlayerStatsModel>(); foreach (var matchInfo in mathes) { var matchService = await _matchListService.GetMatchService(userId, matchInfo.MatchId); var matchState = await matchService.GetStateAsync(); if (matchState.State != MatchState.NotStarted) { var playersStats = await matchService.GetPlayersMatchStats(); if (((player == null || matchInfo.FirstPlayer == player) && playerUserId == null) || (playerUserId != null && matchState.FirstPlayerUserId == playerUserId)) { var firstPlayerCurrentStats = new PlayerStatsModel { Player = matchInfo.FirstPlayer, Matches = 1, Completed = matchInfo.State == MatchState.Completed ? 1 : 0, Won = matchInfo.Winner == Player.First ? 1 : 0, Lost = matchInfo.Winner == Player.Second ? 1 : 0, AggregatedMatchStats = playersStats.FirstPlayer }; if (matchInfo.FirstPlayer != null) { result[matchInfo.FirstPlayer] = result.TryGetValue(matchInfo.FirstPlayer, out var firstPlayerOldStats) ? firstPlayerOldStats + firstPlayerCurrentStats : firstPlayerCurrentStats; } } if (((player == null || matchInfo.SecondPlayer == player) && playerUserId == null) || (playerUserId != null && matchState.SecondPlayerUserId == playerUserId)) { var secondPlayerCurrentStats = new PlayerStatsModel { Player = matchInfo.SecondPlayer, Matches = 1, Completed = matchInfo.State == MatchState.Completed ? 1 : 0, Won = matchInfo.Winner == Player.Second ? 1 : 0, Lost = matchInfo.Winner == Player.First ? 1 : 0, AggregatedMatchStats = playersStats.SecondPlayer }; if (matchInfo.SecondPlayer != null) { result[matchInfo.SecondPlayer] = result.TryGetValue(matchInfo.SecondPlayer, out var secondPlayerOldStats) ? secondPlayerOldStats + secondPlayerCurrentStats : secondPlayerCurrentStats; } } } } return(result.Values.BySortForPlayerStats(sort).Skip(skip).Take(count)); }