public void FinalisePlayersTest() { var team1 = Guid.NewGuid(); var team2 = Guid.NewGuid(); // p1 Player p1 = new Player("p1_username", new[] { team1 }, new Source("p1")); p1.AddBattlefyInformation("user", "user", "p_persis_id", Builtins.ManualSource); p1.AddBattlefyInformation("p1_slug", "z", "p_persis_id", Builtins.ManualSource); p1.AddDiscordId("p_discord_id", Builtins.ManualSource); var id1 = p1.Id; // p2 -> p1 (persistent id match) Player p2 = new Player("p2_person", new[] { team1 }, new Source("p2")); p2.AddBattlefyInformation("unrelated", "unrelated", "p_persis_id", Builtins.ManualSource); p2.AddBattlefyInformation("p2_slug", "x", "p_persis_id", Builtins.ManualSource); // p3 Player p3 = new Player("player_ign_team", new[] { team1 }, new Source("p3")); var id3 = p3.Id; // p4 -> p3 (name and team matches) Player p4 = new Player("player_ign_team", new[] { team1 }, new Source("p4")); // p5 -> p1 (slug match) Player p5 = new Player("p5_name", new[] { team2 }, new Source("p5")); p5.AddBattlefyInformation("another", "another", "p_persis_id", Builtins.ManualSource); p5.AddBattlefyInformation("p5_slug", "y", "p_persis_id", Builtins.ManualSource); // p6 -> p1 (discord id) Player p6 = new Player("p6_username", new[] { team2 }, new Source("p6")); p6.AddDiscordId("p_discord_id", Builtins.ManualSource); var players = new List <Player>() { p1, p2, p3, p4, p5, p6 }; // Perform the merge DumpSourceable("Players before merge:", players); Merger.FinalisePlayers(players); DumpSourceable("Players after merge:", players); // Transform into a dictionary... var dict = players.ToDictionary(p => p.Id, p => p); // ...now check the dictionary. Assert.AreEqual(2, dict.Count, $"Expected 2 players remaining - the others should be merged, actually:\n {string.Join("\n", dict.Keys.Select(k => k.ToString() + " (" + dict[k] + ")"))}"); Assert.IsTrue(dict.ContainsKey(id1), "Expected id1."); var expectedP1BattlefyNames = new[] { "user", "unrelated", "another", "x", "y", "z" }; var expectedP1IGNs = new[] { "p1_username", "p2_person", "p5_name", "p6_username" }; Assert.AreEqual(expectedP1BattlefyNames.Length, Matcher.NamesMatchCount(dict[id1].Battlefy.Usernames, Name.FromStrings(expectedP1BattlefyNames, Builtins.ManualSource)), $"Expected usernames to be merged, actually: {string.Join("\n", dict[id1].Battlefy.Usernames)}"); Assert.AreEqual(expectedP1IGNs.Length, Matcher.NamesMatchCount(dict[id1].NamesInformation.GetItemsUnordered(), Name.FromStrings(expectedP1IGNs, Builtins.ManualSource)), "Expected names to be merged."); Assert.IsTrue(dict[id1].TeamInformation.Contains(team1) && dict[id1].TeamInformation.Contains(team2), "Expected teams to be merged. Teams: [" + string.Join(", ", dict[id1].TeamInformation.GetAllTeamsUnordered()) + "]"); Assert.IsTrue(dict.ContainsKey(id3), "Expected id3."); Assert.AreEqual(1, Matcher.NamesMatchCount(dict[id3].NamesInformation.GetItemsUnordered(), Name.FromStrings(new[] { "player_ign_team" }, Builtins.ManualSource)), "Expected names to be merged."); Assert.AreEqual(team1, dict[id3].CurrentTeam, "Expected current team (p4 -> p3). p3 Teams: [" + string.Join(", ", dict[id3].TeamInformation.GetAllTeamsUnordered()) + "]"); Assert.AreEqual(1, dict[id3].TeamInformation.Count, "Expected current team to be merged. p3 Teams: [" + string.Join(", ", dict[id3].TeamInformation.GetAllTeamsUnordered()) + "]"); }