Beispiel #1
0
        private static void DoCommand(char c)
        {
            switch (char.ToLowerInvariant(c))
            {
            case 'f': BeginFetch(); break;

            case 'l': splatTagController.LoadDatabase(); break;

            case 'p':
            {
                Console.WriteLine("Player name?");
                string input = Console.ReadLine() ?? "";
                foreach (Player p in splatTagController.MatchPlayer(input))
                {
                    Console.WriteLine($"{(p.Country != null ? ":flag_" + p.Country + ": " : "")}{(p.Top500 ? "👑 " : "")}{p.Name}, Plays for: {splatTagController.GetTeamById(p.CurrentTeam)}");
                }
                break;
            }

            case 't':
            {
                Console.WriteLine();
                Console.WriteLine("Team name?");
                string input = Console.ReadLine() ?? "";
                foreach (var t in splatTagController.MatchTeam(input))
                {
                    Console.WriteLine(t);
                    Console.WriteLine("Players: " + string.Join(", ", splatTagController.GetPlayersForTeam(t).Select(tuple => tuple.Item1.Name + " " + (tuple.Item2 ? "(Most recent)" : "(Ex)"))));
                    Console.WriteLine("-----");
                }
                break;
            }
            }
        }
Beispiel #2
0
        public void MatchTeamByRegex_InvalidRegex()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Team t1 = CreateTeam("Inkology");

            t1.AddClanTag("¡g", Builtins.ManualSource, TagOption.Front);

            Team t2 = CreateTeam("Inkfected");

            t2.AddClanTag("τイ", Builtins.ManualSource, TagOption.Front);

            database.expectedTeams = new List <Team> {
                t1, t2
            };

            controller.LoadDatabase();
            Team[] matched = controller.MatchTeam("[", new MatchOptions {
                IgnoreCase = true, QueryIsRegex = true
            });
            Assert.IsNotNull(matched);
            Assert.AreEqual(0, matched.Length);
        }
Beispiel #3
0
        public void LoadDatabaseTest()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();
            Assert.IsTrue(database.loadCalled);

            database.loadCalled = false;
            Team exampleTeam = new Team("Example Team", Builtins.ManualSource);

            exampleTeam.AddClanTag("e.g", Builtins.ManualSource, TagOption.Front);
            exampleTeam.AddDivision(new Division(1, DivType.DSB), Builtins.ManualSource);
            var TEAM_ID = exampleTeam.Id;

            database.expectedTeams = new List <Team> {
                exampleTeam
            };
            var PLAYER_NAME = "Example Name";

            database.expectedPlayers = new List <Player>
            {
                new Player(PLAYER_NAME, new Guid[] { TEAM_ID }, Builtins.ManualSource)
            };
            var PLAYER_ID = database.expectedPlayers[0].Id;

            controller.LoadDatabase();
            Assert.IsTrue(database.loadCalled);

            // Also check the player and team is now in the controller
            var players = controller.MatchPlayer(PLAYER_ID.ToString(), new MatchOptions {
                FilterOptions = FilterOptions.SlappId
            });

            Assert.IsNotNull(players.FirstOrDefault());
            var player = players[0];

            Assert.IsTrue(player.Name.Value == PLAYER_NAME);

            var teams = controller.MatchTeam(TEAM_ID.ToString(), new MatchOptions {
                FilterOptions = FilterOptions.SlappId
            });

            Assert.IsNotNull(teams.FirstOrDefault());
            var team = teams[0];

            Assert.IsTrue(team.CurrentDiv.Value == 1);
            Assert.IsTrue(team.CurrentDiv.DivType == DivType.DSB);

            // Verify getting the players for that team returns our player
            var playersForExampleTeam = controller.GetPlayersForTeam(exampleTeam);

            Assert.IsNotNull(playersForExampleTeam);
            Assert.IsTrue(playersForExampleTeam.Count == 1);
            Assert.IsTrue(playersForExampleTeam[0].player.Equals(player));
        }
Beispiel #4
0
        public void MatchPlayerByNameTest()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Player p1 = CreatePlayer("Player 17"); // Purposefully mixed case

            database.expectedPlayers = new List <Player> {
                p1
            };

            controller.LoadDatabase();
            Player[] matched = controller.MatchPlayer("player"); // Purposefully mixed case
            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Length == 1);
        }
Beispiel #5
0
        public void MatchPlayerByTagTest_NearMatched()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Player p1 = CreatePlayer("BΛÐ SΛVΛGΞ");

            database.expectedPlayers = new List <Player> {
                p1
            };

            controller.LoadDatabase();
            Player[] matched = controller.MatchPlayer("bad savage");
            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Length == 1);
        }
Beispiel #6
0
        private void DataBaseButton_Click(object sender, RoutedEventArgs e)
        {
            if (sourcesImporter == null)
            {
                return;
            }

            DatabaseEditor databaseEditor = new DatabaseEditor(splatTagController, sourcesImporter.Sources);
            bool?          result         = databaseEditor.ShowDialog();

            if (result == true)
            {
                // Editor accepted, save the sources list.
                sourcesImporter.SaveSources(databaseEditor.DatabaseSources);

                // And load the new database.
                splatTagController.LoadDatabase();
            }
        }
Beispiel #7
0
        public void MatchTeamByNameTest()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Team t = CreateTeam("Team 17");                             // Purposefully mixed case

            t.AddClanTag("WO", Builtins.ManualSource, TagOption.Front); // Purposefully upper-case
            database.expectedTeams = new List <Team> {
                t
            };

            controller.LoadDatabase();
            Team[] matched = controller.MatchTeam("team"); // Purposefully mixed case
            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Length == 1);
        }
Beispiel #8
0
        public void MatchTeamByTagTest_NearMatched()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Team t = CreateTeam("Inkology");

            t.AddClanTag("¡g", Builtins.ManualSource, TagOption.Front);
            database.expectedTeams = new List <Team> {
                t
            };

            controller.LoadDatabase();
            Team[] matched = controller.MatchTeam("ig"); // Note i != ¡
            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Length == 1);
        }
Beispiel #9
0
        public void MatchPlayersAmbiguous()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Player p1 = CreatePlayer("Player 17");
            Player p2 = CreatePlayer("Player 18");

            database.expectedPlayers = new List <Player> {
                p1, p2
            };

            controller.LoadDatabase();
            Player[] matched = controller.MatchPlayer("lay");
            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Length == 2);
        }
Beispiel #10
0
        public void MatchPlayerByTagTest_ExactMatched()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Player p1 = CreatePlayer("BΛÐ SΛVΛGΞ");

            database.expectedPlayers = new List <Player> {
                p1
            };

            controller.LoadDatabase();
            Player[] matched = controller.MatchPlayer("BΛÐ SΛVΛGΞ", new MatchOptions {
                IgnoreCase = false, NearCharacterRecognition = false
            });
            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Length == 1);
        }
Beispiel #11
0
        public void MatchPlayerByRegex_InvalidRegex()
        {
            UnitTestDatabase   database   = new UnitTestDatabase();
            SplatTagController controller = new SplatTagController(database);

            controller.Initialise();

            Player p1 = CreatePlayer("¡g Slate");
            Player p2 = CreatePlayer("Slate*NBF");

            database.expectedPlayers = new List <Player> {
                p1, p2
            };

            controller.LoadDatabase();
            Player[] matched = controller.MatchPlayer("[", new MatchOptions {
                IgnoreCase = true, QueryIsRegex = true
            });
            Assert.IsNotNull(matched);
            Assert.AreEqual(0, matched.Length);
        }