/// <summary> /// Returns all matches for a player /// </summary> /// <param name="player"> player </param> /// <returns> all matches for a player </returns> public List <MatchType> GetMatchesForPlayer(PlayerType player) { List <MatchType> matches = new List <MatchType>(); foreach (MatchType t in backend.MatchList) { if (t is TeamMatch) { TeamMatch matchTeam = (TeamMatch)t; foreach (TeamType tt in matchTeam.Teams) { if (tt.Members.Contains(player)) { if (!matches.Contains(t)) { matches.Add(t); } } } } else if (t is SoloMatch) { SoloMatch matchSolo = (SoloMatch)t; if (matchSolo.Players.Contains(player)) { if (!matches.Contains(t)) { matches.Add(t); } } } } return(matches); }
/// <summary> /// Adds or updates a SoloMatch /// </summary> /// <param name="match"> SoloMatch </param> public void AddOrUpdateSoloMatch(SoloMatch match) { if (backend.MatchList.Contains(match)) { backend.MatchList.Remove(match); } backend.MatchList.Add(match); backend.SubmitmatchListChanges(); UpdateScores(); UpdateRankings(); }
public void TestIfDataPersistedThroughDifferentLogicImplementations() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List <PlayerType>() { player1, player2 }, Scores = new List <int>() { 1, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); var matchesForPlayer1 = playerLogic.GetMatchesForPlayer(player1); Assert.IsTrue( ((matchesForPlayer1.Count == 1) && (matchesForPlayer1.Contains(match1))), " - Logic implementations do not persist to same DAL implementation."); }
public ActionResult Create([Bind(Include = "MatchID,Winner,Loser")] SoloMatch soloMatch) { if (ModelState.IsValid) { db.SoloMatches.Add(soloMatch); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MatchID = new SelectList(db.Matches, "MatchID", "MatchID", soloMatch.MatchID); ViewBag.Winner = new SelectList(db.Players, "PlayerID", "Handle", soloMatch.Winner); ViewBag.MatchID = new SelectList(db.SoloMatches, "MatchID", "MatchID", soloMatch.MatchID); ViewBag.MatchID = new SelectList(db.SoloMatches, "MatchID", "MatchID", soloMatch.MatchID); ViewBag.MatchID = new SelectList(db.SoloMatches, "MatchID", "MatchID", soloMatch.MatchID); ViewBag.MatchID = new SelectList(db.SoloMatches, "MatchID", "MatchID", soloMatch.MatchID); return(View(soloMatch)); }
public void TestSoloMatchType() { PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; var soloMatch1 = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; PlayerType player3 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player4 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; var soloMatch2 = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = soloMatch1.dateTime, Players = new List<PlayerType>() { player3, player4 }, Scores = new List<int>() { 1, 2 } }; Assert.AreEqual(soloMatch1, soloMatch2, "SoloMatch Equals does not return true for cloned matches"); Assert.IsTrue(soloMatch1 == soloMatch2, "SoloMatch '==' does not return true for cloned matches"); player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; soloMatch2 = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame2", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Tournament, dateTime = DateTime.Now, Players = new List<PlayerType>() { player3, player4 }, Scores = new List<int>() { 3,4 } }; Assert.AreNotEqual(soloMatch1, soloMatch2, "SoloMatch Equals returns true for different solomatches"); Assert.IsTrue(soloMatch1 != soloMatch2, "SoloMatch '!=' does not return true for different solomatches"); }
// GET: SoloMatches/Delete/5 public ActionResult Delete(int?id) { if (Session["LoggedIn"] == null) { return(RedirectToAction("Index", "Home", new { area = "" })); } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SoloMatch soloMatch = db.SoloMatches.Find(id); if (soloMatch == null) { return(HttpNotFound()); } return(View(soloMatch)); }
public List <PlayerType> GetPlayersForgame(GameType game) { List <PlayerType> players = new List <PlayerType>(); foreach (MatchType match in backend.MatchList) { if (match is SoloMatch) { SoloMatch soloM = (SoloMatch)match; if (match.GameID == game) { foreach (PlayerType p in soloM.Players) { if (!players.Contains(p)) { players.Add(p); } } } } else if (match is TeamMatch) { TeamMatch teamM = (TeamMatch)match; if (match.GameID == game) { foreach (TeamType t in teamM.Teams) { foreach (PlayerType p in t.Members) { if (!players.Contains(p)) { players.Add(p); } } } } } } return(players); }
/// <summary> /// Returns filtered matches for a player /// </summary> /// <param name="game"> game </param> /// <param name="player"> player </param> /// <returns> filtered matches for a player </returns> public List <MatchType> GetGameMatchesForPlayer(GameType game, PlayerType player) { List <MatchType> matches = new List <MatchType>(); foreach (MatchType m in backend.MatchList) { if (m is SoloMatch) { SoloMatch solo = (SoloMatch)m; if (solo.Players.Contains(player) && solo.GameID == game) { // protect against duplicates if (!matches.Contains(m)) { matches.Add(m); } } } else if (m is TeamMatch) { TeamMatch teamMatch = (TeamMatch)m; foreach (TeamType t in teamMatch.Teams) { if (t.Members.Contains(player) && teamMatch.GameID == game) { // protect against duplicates if (!matches.Contains(m)) { matches.Add(m); } } } } else { throw new System.InvalidOperationException("Invalid Match in MatchList!"); } } return(matches); }
static void AddSoloMatch() { IPlayerManipulations playerLogic = new PlayerLogic(); IGameManipulations gameLogic = new GameLogic(); IMatchManipulations matchLogic = new MatchLogic(); IRankingSource rankingLogic = new RankingLogic(); // add match between 2 players List <PlayerType> players = playerLogic.GetPlayers(); List <GameType> games = gameLogic.GetGames(); Console.WriteLine("-> adding match (Solo)..."); Console.WriteLine("\t\t#Method AddOrUpdateSoloMatch()"); matchLogic.AddOrUpdateSoloMatch(new SoloMatch(new List <PlayerType> { players[0], players[2] }, new List <int> { 2500, 2300 }, MatchCategories.Competition, games[0])); // print match Console.WriteLine("\t\t#Method GetMatches()"); Console.WriteLine("\t\t#Method SoloMatch.ToString()"); Console.WriteLine("------- First Match -------"); SoloMatch solo = (SoloMatch)matchLogic.GetMatches(games[0], ParticipantTypes.Solo, MatchCategories.Competition)[0]; Console.WriteLine(solo.ToString()); Console.WriteLine("------- @@@@@ -------\n\n"); // print ranking Console.WriteLine("\t\t#Method GetGameRankingsAll()"); Console.WriteLine("------- Ranking Game -------"); foreach (PlayerGameRankingType g in rankingLogic.GetGameRankingsAll(games[0], ParticipantTypes.All)) { Console.WriteLine(g.ToString()); } Console.WriteLine("------- @@@@@ -------\n\n"); // wait for user Wait(); }
public void testRanking() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var teamLogic = (ITeamManipulations)getInterfaceImplementation(typeof(ITeamManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); var rankingLogic = (IRankingSource)getInterfaceImplementation(typeof(IRankingSource)); var players = new PlayerType[20]; for (int i = 0; i < players.Length; i++) { players[i] = new PlayerType() { Name = $"test{i}", Mail = $"test{i}", Tag = $"test{i}" }; playerLogic.AddOrUpdatePlayer(players[i]); } var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); for (int i = 0; i < 5; i++) { var scores = new List<int>(); for (int j = 0; j < players.Length; j++) { scores.Add(j + 1); } var match = new SoloMatch() { GameID = game1, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = players.ToList(), Scores = scores }; matchLogic.AddOrUpdateSoloMatch(match); } var rankings = rankingLogic.GetGameRankingsAll(game1, ParticipantTypes.All); Assert.IsTrue(rankings.Count == players.Length, $" - getGameRankingsAll, expected count = {players.Length}, was: {rankings.Count}"); var rank = rankings.Where(r => r.Player == players[0]).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Ranking == Ranks.Novice, $" - getGameRankingsAll, \"Novice\" expected, was \"{rank.Ranking}\""); rank = rankings.Where(r => r.Player == players[5]).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Ranking == Ranks.Competent, $" - getGameRankingsAll, \"Competent\" expected, was \"{rank.Ranking}\""); rank = rankings.Where(r => r.Player == players[14]).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Ranking == Ranks.Advanced, $" - getGameRankingsAll, \"Advanced\" expected, was \"{rank.Ranking}\""); rank = rankings.Where(r => r.Player == players[19]).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Ranking == Ranks.Elite, $" - getGameRankingsAll, \"Elite\" expected, was \"{rank.Ranking}\""); }
public void AddOrUpdateSoloMatch(SoloMatch match) { throw new NotImplementedException(); }
/// <summary> /// Updates all ranking scores /// </summary> private void UpdateScores() { backend.RankingList.Clear(); backend.SubmitRankingListChanges(); // update points foreach (MatchType match in backend.MatchList) { if (match is SoloMatch) { SoloMatch soloMatch = (SoloMatch)match; if (soloMatch.Players.Count < 1) { continue; } int maxPoints = soloMatch.Players.Count + 1; List <int> uniquePoints = GenerateUniqueOrdered(soloMatch.Scores); for (int i = 0; i < uniquePoints.Count; i++) { if (i >= (uniquePoints.Count - 1)) { maxPoints = 0; // no point for player for (int j = 0; j < soloMatch.Players.Count; j++) { if (uniquePoints[i] == soloMatch.Scores[j]) { AddPoints(soloMatch.GameID, soloMatch.Players[j], soloMatch.Category, maxPoints); } } } else if (i == 0) { // max points for (int j = 0; j < soloMatch.Players.Count; j++) { if (uniquePoints[i] == soloMatch.Scores[j]) { AddPoints(soloMatch.GameID, soloMatch.Players[j], soloMatch.Category, maxPoints); } } maxPoints -= 2; } else { for (int j = 0; j < soloMatch.Players.Count; j++) { if (uniquePoints[i] == soloMatch.Scores[j]) { AddPoints(soloMatch.GameID, soloMatch.Players[j], soloMatch.Category, maxPoints); } } maxPoints--; } } } else if (match is TeamMatch) { TeamMatch teamMatch = (TeamMatch)match; if (teamMatch.Teams.Count < 1) { continue; } int maxPoints = teamMatch.Teams.Count + 1; List <int> uniquePoints = GenerateUniqueOrdered(teamMatch.Scores); for (int i = 0; i < uniquePoints.Count; i++) { if (i >= (uniquePoints.Count - 1)) { maxPoints = 0; // no point for player for (int j = 0; j < teamMatch.Teams.Count; j++) { if (uniquePoints[i] == teamMatch.Scores[j]) { foreach (PlayerType player in teamMatch.Teams[j].Members) { AddPoints(teamMatch.GameID, player, teamMatch.Category, maxPoints); } } } } else if (i == 0) { // max points for (int j = 0; j < teamMatch.Teams.Count; j++) { if (uniquePoints[i] == teamMatch.Scores[j]) { foreach (PlayerType player in teamMatch.Teams[j].Members) { AddPoints(teamMatch.GameID, player, teamMatch.Category, maxPoints); } } } maxPoints -= 2; } else { for (int j = 0; j < teamMatch.Teams.Count; j++) { if (uniquePoints[i] == teamMatch.Scores[j]) { foreach (PlayerType player in teamMatch.Teams[j].Members) { AddPoints(teamMatch.GameID, player, teamMatch.Category, maxPoints); } } } maxPoints--; } } } } }
private void UpdateTree() { IRankingSource rankingLogic = new RankingLogic(); IGameManipulations gameLogic = new GameLogic(); ITeamManipulations teamLogic = new TeamLogic(); IPlayerManipulations playerLogic = new PlayerLogic(); IMatchManipulations matchLogic = new MatchLogic(); List <GameType> games = gameLogic.GetGames(); List <TeamType> teams = teamLogic.GetTeams(); List <PlayerType> players = playerLogic.GetPlayers(); // ranking tree treeRankings.BeginUpdate(); treeRankings.Nodes.Clear(); for (int i = 0; i < games.Count; i++) { List <PlayerGameRankingType> r = rankingLogic.GetGameRankingsAll(games[i], ParticipantTypes.All); treeRankings.Nodes.Add(games[i].Name); for (int j = 0; j < r.Count; j++) { treeRankings.Nodes[i].Nodes.Add("Player: " + r[j].Player.Name); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Mail: " + r[j].Player.Mail); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Tag: " + r[j].Player.Tag); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Points: " + r[j].Points); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Ranking: " + r[j].Ranking); } } treeRankings.EndUpdate(); // games tree treeGames.BeginUpdate(); treeGames.Nodes.Clear(); for (int i = 0; i < games.Count; i++) { treeGames.Nodes.Add(games[i].Name); treeGames.Nodes[i].Nodes.Add("Participant type: " + games[i].ParticipantType.ToString()); } treeGames.EndUpdate(); // teams tree treeTeams.BeginUpdate(); treeTeams.Nodes.Clear(); for (int i = 0; i < teams.Count; i++) { treeTeams.Nodes.Add(teams[i].Name); for (int j = 0; j < teams[i].Members.Count; j++) { treeTeams.Nodes[i].Nodes.Add($"Player: {teams[i].Members[j].Name} - {teams[i].Members[j].Tag} - {teams[i].Members[j].Mail}"); } } treeTeams.EndUpdate(); // players tree treePlayers.BeginUpdate(); treePlayers.Nodes.Clear(); for (int i = 0; i < players.Count; i++) { treePlayers.Nodes.Add(players[i].Name); treePlayers.Nodes[i].Nodes.Add("Tag: " + players[i].Tag); treePlayers.Nodes[i].Nodes.Add("Mail: " + players[i].Mail); } treePlayers.EndUpdate(); // matches tree treeMatches.BeginUpdate(); treeMatches.Nodes.Clear(); for (int i = 0; i < games.Count; i++) { List <MatchType> matches = matchLogic.GetMatchesAll(games[i]); treeMatches.Nodes.Add($"Matches for: {games[i].Name}"); for (int j = 0; j < matches.Count; j++) { if (matches[j] is SoloMatch) { SoloMatch s = (SoloMatch)matches[j]; treeMatches.Nodes[i].Nodes.Add(s.dateTime.ToString()); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Name: {s.GameID.Name}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Type: {s.GameID.ParticipantType.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Category: {s.Category.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add("Players & scores"); for (int k = 0; k < s.Players.Count; k++) { treeMatches.Nodes[i].Nodes[j].Nodes[3].Nodes.Add($"Player: {s.Players[k].Name} : {s.Scores[k]}"); } } else if (matches[j] is TeamMatch) { TeamMatch t = (TeamMatch)matches[j]; treeMatches.Nodes[i].Nodes.Add(t.dateTime.ToString()); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Name: {t.GameID.Name}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Type: {t.GameID.ParticipantType.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Category: {t.Category.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add("Teams & scores"); for (int k = 0; k < t.Teams.Count; k++) { treeMatches.Nodes[i].Nodes[j].Nodes[3].Nodes.Add($"Team: {t.Teams[k].Name} : {t.Scores[k]}"); } } } } treeMatches.EndUpdate(); }
public void TestMatchSerialisation() { var DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess)); ClearAllData(DAL); Assert.IsNotNull(DAL.MatchList, "DAL property \"RankingList\" is null after calling \"ClearAllData\""); Assert.IsTrue(DAL.MatchList.Count == 0, "DAL property \"RankingList\" is not empty after calling \"ClearAllData\""); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; var soloMatch = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; DAL.MatchList.Add(soloMatch); var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var teamMatch = new TeamMatch() { GameID = new GameType() { Name = "testTeamGame", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Training, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 3, 4 } }; DAL.MatchList.Add(teamMatch); Assert.IsTrue(DAL.MatchList.Count == 2, "Count for DAL property \"MatchList\" != 2 after adding two matches."); DAL.SubmitmatchListChanges(); // destroy DAL & force reload from files... DAL = null; DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess)); Assert.IsNotNull(DAL.MatchList, "DAL property \"MatchList\" is null after creating a new instance of the DAL."); Assert.IsTrue(DAL.MatchList.Count == 2, "Added matches were not persisted."); bool soloMatchFound = false; bool teamMatchFound = false; for (int i = 0; i < 2; i++) { if (DAL.MatchList[i] is SoloMatch) { soloMatchFound = true; var match = DAL.MatchList[i] as SoloMatch; Assert.AreEqual(match.GameID,soloMatch.GameID, $"SoloMatch.GameID not OK after serialisation. Expected: {soloMatch.GameID}, was: {match.GameID}"); Assert.AreEqual(match.Category, soloMatch.Category, $"SoloMatch.Category not OK after serialisation. Expected: {soloMatch.Category}, was: {match.Category}"); Assert.AreEqual(match.dateTime, soloMatch.dateTime, $"SoloMatch.dateTime not OK after serialisation. Expected: {soloMatch.dateTime}, was: {match.dateTime}"); Assert.AreEqual(match.Players[0], soloMatch.Players[0], $"SoloMatch.Players[0] not OK after serialisation. Expected: {soloMatch.Players[0]}, was: {match.Players[0]}"); Assert.AreEqual(match.Scores[1], soloMatch.Scores[1], $"SoloMatch.Scores[1] not OK after serialisation. Expected: {soloMatch.Scores[1]}, was: {match.Scores[1]}"); } else if (DAL.MatchList[i] is TeamMatch) { teamMatchFound = true; var match = DAL.MatchList[i] as TeamMatch; Assert.AreEqual(match.GameID, teamMatch.GameID, $"TeamMatch.GameID not OK after serialisation. Expected: {teamMatch.GameID}, was: {match.GameID}"); Assert.AreEqual(match.Category, teamMatch.Category, $"TeamMatch.Category not OK after serialisation. Expected: {teamMatch.Category}, was: {match.Category}"); Assert.AreEqual(match.dateTime, teamMatch.dateTime, $"TeamMatch.dateTime not OK after serialisation. Expected: {teamMatch.dateTime}, was: {match.dateTime}"); Assert.AreEqual(match.Teams[0].Name, teamMatch.Teams[0].Name, $"TeamMatch.Teams[0] not OK after serialisation. Expected: {teamMatch.Teams[0]}, was: {match.Teams[0]}"); Assert.AreEqual(match.Scores[1], teamMatch.Scores[1], $"TeamMatch.Scores[1] not OK after serialisation. Expected: {teamMatch.Scores[1]}, was: {match.Scores[1]}"); } } Assert.IsTrue(soloMatchFound, "SoloMatch not persisted"); Assert.IsTrue(teamMatchFound, "TeamMatch not persisted"); }
public void testSoloTournamentGamePoints() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var teamLogic = (ITeamManipulations)getInterfaceImplementation(typeof(ITeamManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); var rankingLogic = (IRankingSource)getInterfaceImplementation(typeof(IRankingSource)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; PlayerType player5 = new PlayerType() { Name = "test5", Mail = "test5", Tag = "test5" }; PlayerType player6 = new PlayerType() { Name = "test6", Mail = "test6", Tag = "test6" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); playerLogic.AddOrUpdatePlayer(player3); playerLogic.AddOrUpdatePlayer(player4); playerLogic.AddOrUpdatePlayer(player5); playerLogic.AddOrUpdatePlayer(player6); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Tournament, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2, player3 }, Scores = new List<int>() { 1, 3, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); var rankings = rankingLogic.GetGameRankingsAll(game1, ParticipantTypes.All); Assert.IsTrue(rankings.Count == 3, $" - getGameRankingsAll, expected count = {3}, was: {rankings.Count}"); var rank = rankings.Where(r => r.Player == player1).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Points == 0, $" - getGameRankingsAll, points: expected 0, was {rank.Points}"); Assert.IsTrue(rank.Ranking == Ranks.Unranked, $" - getGameRankingsAll, \"unranked\" expected, as \"{rank.Ranking}\""); rank = rankings.Where(r => r.Player == player2).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Points == 12, $" - getGameRankingsAll,points: expected 12, was {rank.Points}"); Assert.IsTrue(rank.Ranking == Ranks.Unranked, $" - getGameRankingsAll, \"unranked\" expected, as \"{rank.Ranking}\""); rank = rankings.Where(r => r.Player == player3).FirstOrDefault(); Assert.IsNotNull(rank, $" - getGameRankingsAll does not return correct players in rankings"); Assert.IsTrue(rank.Points == 6, $" - getGameRankingsAll, points: expected 6, was {rank.Points}"); Assert.IsTrue(rank.Ranking == Ranks.Unranked, $" - getGameRankingsAll, \"unranked\" expected, as \"{rank.Ranking}\""); }
public void TestGetMatches() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; PlayerType player5 = new PlayerType() { Name = "test5", Mail = "test5", Tag = "test5" }; PlayerType player6 = new PlayerType() { Name = "test6", Mail = "test6", Tag = "test6" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); playerLogic.AddOrUpdatePlayer(player3); playerLogic.AddOrUpdatePlayer(player4); playerLogic.AddOrUpdatePlayer(player5); playerLogic.AddOrUpdatePlayer(player6); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.Solo }; var game2 = new GameType() { Name = "game2", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); gameLogic.AddOrUpdateGame(game2); var team1 = new TeamType() { Name = "team1", Members = new List<PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List<PlayerType>() { player3, player4 } }; var team3 = new TeamType() { Name = "team3", Members = new List<PlayerType>() { player5, player6 } }; var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; var match2 = new SoloMatch() { GameID = game2, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player3 }, Scores = new List<int>() { 1, 2 } }; var match3 = new TeamMatch() { GameID = game2, Category = MatchCategories.Training, dateTime = DateTime.Now, Teams = new List<TeamType>() { team1, team2 }, Scores = new List<int>() { 1, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); matchLogic.AddOrUpdateSoloMatch(match2); matchLogic.AddOrUpdateTeamMatch(match3); var matches = matchLogic.GetMatches(game2, ParticipantTypes.All, MatchCategories.Training); Assert.IsTrue( ((matches.Count == 2) && (matches.Contains(match2)) && (matches.Contains(match3))), " - MatchManipulator \"GetMatches\" Not OK"); matches = matchLogic.GetMatches(game2, ParticipantTypes.Solo, MatchCategories.Training); Assert.IsTrue( ((matches.Count == 1) && (matches.Contains(match2))), " - MatchManipulator \"GetMatches\" Not OK"); matches = matchLogic.GetMatches(game2, ParticipantTypes.Team, MatchCategories.Training); Assert.IsTrue( ((matches.Count == 1) && (matches.Contains(match3))), " - MatchManipulator \"GetMatches\" Not OK"); matches = matchLogic.GetMatches(game2, ParticipantTypes.All, MatchCategories.Competition); Assert.IsTrue((matches.Count == 0), " - MatchManipulator \"GetMatches\" Not OK"); }
public void TestIfDataPersistedThroughDifferentLogicImplementations() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; gameLogic.AddOrUpdateGame(game1); var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); var matchesForPlayer1 = playerLogic.GetMatchesForPlayer(player1); Assert.IsTrue( ((matchesForPlayer1.Count == 1) && (matchesForPlayer1.Contains(match1))), " - Logic implementations do not persist to same DAL implementation."); }
public void TestMatchSerialisation() { var DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess)); ClearAllData(DAL); Assert.IsNotNull(DAL.MatchList, "DAL property \"RankingList\" is null after calling \"ClearAllData\""); Assert.IsTrue(DAL.MatchList.Count == 0, "DAL property \"RankingList\" is not empty after calling \"ClearAllData\""); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; var soloMatch = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List <PlayerType>() { player1, player2 }, Scores = new List <int>() { 1, 2 } }; DAL.MatchList.Add(soloMatch); var team1 = new TeamType() { Name = "team1", Members = new List <PlayerType>() { player1, player2 } }; var team2 = new TeamType() { Name = "team2", Members = new List <PlayerType>() { player3, player4 } }; var teamMatch = new TeamMatch() { GameID = new GameType() { Name = "testTeamGame", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Training, dateTime = DateTime.Now, Teams = new List <TeamType>() { team1, team2 }, Scores = new List <int>() { 3, 4 } }; DAL.MatchList.Add(teamMatch); Assert.IsTrue(DAL.MatchList.Count == 2, "Count for DAL property \"MatchList\" != 2 after adding two matches."); DAL.SubmitmatchListChanges(); // destroy DAL & force reload from files... DAL = null; DAL = (IGameRankingDataAccess)getInterfaceImplementation(typeof(IGameRankingDataAccess)); Assert.IsNotNull(DAL.MatchList, "DAL property \"MatchList\" is null after creating a new instance of the DAL."); Assert.IsTrue(DAL.MatchList.Count == 2, "Added matches were not persisted."); bool soloMatchFound = false; bool teamMatchFound = false; for (int i = 0; i < 2; i++) { if (DAL.MatchList[i] is SoloMatch) { soloMatchFound = true; var match = DAL.MatchList[i] as SoloMatch; Assert.AreEqual(match.GameID, soloMatch.GameID, $"SoloMatch.GameID not OK after serialisation. Expected: {soloMatch.GameID}, was: {match.GameID}"); Assert.AreEqual(match.Category, soloMatch.Category, $"SoloMatch.Category not OK after serialisation. Expected: {soloMatch.Category}, was: {match.Category}"); Assert.AreEqual(match.dateTime, soloMatch.dateTime, $"SoloMatch.dateTime not OK after serialisation. Expected: {soloMatch.dateTime}, was: {match.dateTime}"); Assert.AreEqual(match.Players[0], soloMatch.Players[0], $"SoloMatch.Players[0] not OK after serialisation. Expected: {soloMatch.Players[0]}, was: {match.Players[0]}"); Assert.AreEqual(match.Scores[1], soloMatch.Scores[1], $"SoloMatch.Scores[1] not OK after serialisation. Expected: {soloMatch.Scores[1]}, was: {match.Scores[1]}"); } else if (DAL.MatchList[i] is TeamMatch) { teamMatchFound = true; var match = DAL.MatchList[i] as TeamMatch; Assert.AreEqual(match.GameID, teamMatch.GameID, $"TeamMatch.GameID not OK after serialisation. Expected: {teamMatch.GameID}, was: {match.GameID}"); Assert.AreEqual(match.Category, teamMatch.Category, $"TeamMatch.Category not OK after serialisation. Expected: {teamMatch.Category}, was: {match.Category}"); Assert.AreEqual(match.dateTime, teamMatch.dateTime, $"TeamMatch.dateTime not OK after serialisation. Expected: {teamMatch.dateTime}, was: {match.dateTime}"); Assert.AreEqual(match.Teams[0].Name, teamMatch.Teams[0].Name, $"TeamMatch.Teams[0] not OK after serialisation. Expected: {teamMatch.Teams[0]}, was: {match.Teams[0]}"); Assert.AreEqual(match.Scores[1], teamMatch.Scores[1], $"TeamMatch.Scores[1] not OK after serialisation. Expected: {teamMatch.Scores[1]}, was: {match.Scores[1]}"); } } Assert.IsTrue(soloMatchFound, "SoloMatch not persisted"); Assert.IsTrue(teamMatchFound, "TeamMatch not persisted"); }
public void TestGetGameMatchesForPlayer() { ClearAllData(); var playerLogic = (IPlayerManipulations)getInterfaceImplementation(typeof(IPlayerManipulations)); var gameLogic = (IGameManipulations)getInterfaceImplementation(typeof(IGameManipulations)); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); Assert.IsNotNull(playerLogic.GetPlayers(), " - PlayerManipulator.GetPlayers is null after ClearAllData"); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; playerLogic.AddOrUpdatePlayer(player1); playerLogic.AddOrUpdatePlayer(player2); playerLogic.AddOrUpdatePlayer(player3); playerLogic.AddOrUpdatePlayer(player4); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; var game2 = new GameType() { Name = "game2", ParticipantType = ParticipantTypes.Solo }; gameLogic.AddOrUpdateGame(game1); gameLogic.AddOrUpdateGame(game2); var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; var match2 = new SoloMatch() { GameID = game2, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player3 }, Scores = new List<int>() { 1, 2 } }; var match3 = new SoloMatch() { GameID = game2, Category = MatchCategories.Training, dateTime = DateTime.Now, Players = new List<PlayerType>() { player2, player3 }, Scores = new List<int>() { 1, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); matchLogic.AddOrUpdateSoloMatch(match2); matchLogic.AddOrUpdateSoloMatch(match3); var matchesForPlayer1 = playerLogic.GetGameMatchesForPlayer(game1, player1); Assert.IsTrue( ((matchesForPlayer1.Count == 1) && (matchesForPlayer1.Contains(match1))), " - PlayerManipulator \"GetGameMatchesForPlayer\" Not OK"); }
public void TestSimpleSoloMatchManipulations() { ClearAllData(); var matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); var game1 = new GameType() { Name = "game1", ParticipantType = ParticipantTypes.All }; Assert.IsNotNull(matchLogic.GetMatchesAll(game1), " - MatchManipulator.GetMatchesAll is null after ClearAllData"); Assert.IsNotNull(matchLogic.GetMatches(game1, ParticipantTypes.All, MatchCategories.Training), " - MatchManipulator.GetMatches is null after ClearAllData"); PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; PlayerType player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; PlayerType player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; var match1 = new SoloMatch() { GameID = game1, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List<PlayerType>() { player1, player2 }, Scores = new List<int>() { 1, 2 } }; matchLogic.AddOrUpdateSoloMatch(match1); matchLogic = null; matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); Assert.IsTrue(matchLogic.GetMatchesAll(game1).Contains(match1), " - MatchManipulator does not persist new SoloMatch"); var match = matchLogic.GetMatchesAll(game1).First() as SoloMatch; match.Scores = new List<int>() { 2, 3 }; matchLogic.AddOrUpdateSoloMatch(match); matchLogic = null; matchLogic = (IMatchManipulations)getInterfaceImplementation(typeof(IMatchManipulations)); Assert.IsTrue((((matchLogic.GetMatchesAll(game1).First() as SoloMatch).Scores.Contains(2)) && ((matchLogic.GetMatchesAll(game1).First() as SoloMatch).Scores.Contains(2))), " - MatchManipulator does not persist SoloMatch changes"); }
public void AddOrUpdateSoloMatch(SoloMatch match) { grda.MatchList.Add(match); grda.SubmitmatchListChanges(); }
public void TestSoloMatchType() { PlayerType player1 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player2 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; var soloMatch1 = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = DateTime.Now, Players = new List <PlayerType>() { player1, player2 }, Scores = new List <int>() { 1, 2 } }; PlayerType player3 = new PlayerType() { Name = "test1", Mail = "test1", Tag = "test1" }; PlayerType player4 = new PlayerType() { Name = "test2", Mail = "test2", Tag = "test2" }; var soloMatch2 = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame", ParticipantType = ParticipantTypes.Solo }, Category = MatchCategories.Competition, dateTime = soloMatch1.dateTime, Players = new List <PlayerType>() { player3, player4 }, Scores = new List <int>() { 1, 2 } }; Assert.AreEqual(soloMatch1, soloMatch2, "SoloMatch Equals does not return true for cloned matches"); Assert.IsTrue(soloMatch1 == soloMatch2, "SoloMatch '==' does not return true for cloned matches"); player3 = new PlayerType() { Name = "test3", Mail = "test3", Tag = "test3" }; player4 = new PlayerType() { Name = "test4", Mail = "test4", Tag = "test4" }; soloMatch2 = new SoloMatch() { GameID = new GameType() { Name = "testSoloGame2", ParticipantType = ParticipantTypes.Team }, Category = MatchCategories.Tournament, dateTime = DateTime.Now, Players = new List <PlayerType>() { player3, player4 }, Scores = new List <int>() { 3, 4 } }; Assert.AreNotEqual(soloMatch1, soloMatch2, "SoloMatch Equals returns true for different solomatches"); Assert.IsTrue(soloMatch1 != soloMatch2, "SoloMatch '!=' does not return true for different solomatches"); }