public void ViewModelTest() { // arrange var pavlovServers = PavlovServerServiceTests.InitializePavlovServer(_sshServerSerivce, _pavlovServerService); var pavlovServerInfo = PavlovServerInfoServiceTest.CreatePavlovServerInfo(_pavlovServerInfoService, pavlovServers.First().Id); var pavlovServerPlayer = PavlovServerPlayerServiceTest.CreatePavlovServerPlayer(_pavlovServerPlayerService, pavlovServers.First().Id); // act var result = _publicViewListsService.PavlovServerPlayerListPublicViewModel(pavlovServerInfo, new[] { pavlovServerPlayer }); var result2 = _publicViewListsService.GetPavlovServerPlayerListPublicViewModel(pavlovServers.First().Id, false) .GetAwaiter().GetResult(); // assert result.ServerInfo.ServerName.Should().Be("test"); result2.PlayerList.Should().NotBeNull(); result.PlayerList.Should().NotBeNull(); result.Should().NotBeNull(); result2.Should().NotBeNull(); }
public async Task <IActionResult> EditMatchResult(int id) { var user = await _userservice.getUserFromCp(HttpContext.User); var servers = await _matchService.FindAllMatchesWhereTheUserHasRights(HttpContext.User, user); if (!servers.Select(x => x.Id).Contains(id)) { return(Forbid()); } var match = await _matchService.FindOne(id); if (match == null) { return(BadRequest("No match like that exists!")); } if (!match.isFinished()) { return(BadRequest("Match is not finished jet!")); } if (match.EndInfo == null) { return(BadRequest("Match has no endInfo")); } var map = await _mapsService.FindOne(match.MapId.Replace("UGC", "")); if (map == null) { return(BadRequest("Match has no map set")); } var result = _publicViewListsService.PavlovServerPlayerListPublicViewModel(new PavlovServerInfo { MapLabel = match.MapId, MapPictureLink = map.ImageUrl, GameMode = match.EndInfo.GameMode, ServerName = match.EndInfo.ServerName, RoundState = match.EndInfo.RoundState, PlayerCount = match.EndInfo.PlayerCount, Teams = match.EndInfo.Teams, Team0Score = match.EndInfo.Team0Score, Team1Score = match.EndInfo.Team1Score, ServerId = match.PavlovServer.Id }, match.PlayerResults); result.MatchId = match.Id; return(View("EditResult", result)); }
// GET public async Task <IActionResult> PlayersFromMatches([FromQuery] int[] matchIds, [FromQuery] string backgroundColorHex, [FromQuery] string fontColorHex) { var result = new List <PavlovServerPlayerListPublicViewModel>(); foreach (var matchId in matchIds) { var match = await _matchService.FindOne(matchId); if (match == null) { continue; } if (!match.hasStats()) { continue; } var map = await _mapsService.FindOne(match.MapId.Replace("UGC", "")); if (map == null) { continue; } result.Add(_publicViewListsService.PavlovServerPlayerListPublicViewModel(new PavlovServerInfo { MapLabel = match.MapId, MapPictureLink = map.ImageUrl, GameMode = match.EndInfo.GameMode, ServerName = match.EndInfo.ServerName, RoundState = match.EndInfo.RoundState, PlayerCount = match.EndInfo.PlayerCount, Teams = match.EndInfo.Teams, Team0Score = match.EndInfo.Team0Score, Team1Score = match.EndInfo.Team1Score, ServerId = match.PavlovServer.Id }, match.PlayerResults)); } ViewBag.background = backgroundColorHex; ViewBag.textColor = fontColorHex; return(PartialView("PlayersFromServers", result)); }