private static IEnumerable <IImporter> PathToIImporter(string input) { // Remove preceding and seceding quotes from path. input = input.TrimStart('"').TrimEnd('"'); if (string.IsNullOrWhiteSpace(input)) { throw new ArgumentException("Input path cannot be null or whitespace.", nameof(input)); } // Correct paths if (!Path.IsPathRooted(input)) { input = Path.GetFullPath(input); } if (Directory.Exists(input) && input.Contains(Path.DirectorySeparatorChar + "statink")) { foreach (var file in Directory.EnumerateFiles(input)) { if (StatInkReader.AcceptsInput(file)) { yield return(new StatInkReader(file)); } } } else if (!File.Exists(input)) { Console.WriteLine($"Input does not exist on disk. Remote is not currently supported ({input})."); } else if (TwitterReader.AcceptsInput(input)) { yield return(new TwitterReader(input)); } else if (SendouReader.AcceptsInput(input)) { yield return(new SendouReader(input)); } else if (TSVReader.AcceptsInput(input)) { yield return(new TSVReader(input)); } else if (LUTIJsonReader.AcceptsInput(input)) { yield return(new LUTIJsonReader(input)); } else if (BattlefyJsonReader.AcceptsInput(input)) { yield return(new BattlefyJsonReader(input)); } else { throw new NotImplementedException("File extension not recognised or supported."); } }
public void TestSendouImporter_New() { string filePath = Path.GetTempFileName() + ".Sendou.json"; const string JSON = @"[ { ""id"": 8001, ""username"": ""Player1"", ""discriminator"": ""3122"", ""discordAvatar"": ""1c4720e249fd1f425839fc06b23b38bb"", ""discordId"": ""342369454719631361"", ""profile"": null }, { ""id"": 8002, ""username"": ""AnotherPlayer"", ""discriminator"": ""6667"", ""discordAvatar"": ""1895e5ca0ebb705ee92add96808f1f0e"", ""discordId"": ""98746624112599040"", ""profile"": { ""twitterName"": ""ATwitter"" } } ]"; try { File.WriteAllText(filePath, JSON); SendouReader reader = new SendouReader(filePath); Source s = reader.Load(); var loadedTeams = s.Teams; var loadedPlayers = s.Players; Assert.AreEqual(0, loadedTeams.Length); Assert.AreEqual(2, loadedPlayers.Length); Assert.IsTrue(loadedPlayers.Any(p => p.Name.Value == "Player1")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Ids.FirstOrDefault()?.Value == "342369454719631361")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Usernames.FirstOrDefault()?.Value == "Player1#3122")); Assert.IsTrue(loadedPlayers.Any(p => p.Name.Value == "AnotherPlayer")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Ids.FirstOrDefault()?.Value == "98746624112599040")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Usernames.FirstOrDefault()?.Value == "AnotherPlayer#6667")); Assert.IsTrue(loadedPlayers.Any(p => p.TwitterProfiles.FirstOrDefault()?.Value == "ATwitter")); } finally { File.Delete(filePath); } }
public void TestSendouImporter_Old() { string filePath = Path.GetTempFileName() + ".Sendou.json"; const string JSON = @"{ ""users"": [ { ""username"": ""!Username!"", ""id"": ""5cff40aefeacd363157b3962"", ""twitch_name"": ""Twitch_Name"", ""twitter_name"": ""Twitter_Name"", ""country"": ""us"", ""weapons"": [ ""Kensa Dynamo Roller"", ""Gold Dynamo Roller"", ""Nautilus 79"", ""Custom Explosher"", ""Tenta Camo Brella"" ], ""top500"": false, ""discord"": { ""discordId"": ""85179121671364608"", ""username"": ""!A_DISCORD_USERNAME!"", ""avatar"": ""3a6d339e5395a07ffee9fd5cd079782d"", ""discriminator"": ""2227"", ""public_flags"": 0 } }, { ""username"": ""AnotherPlayer"", ""id"": ""5f36d677a6558f2e8fadfdd8"", ""twitch_name"": null, ""twitter_name"": ""AnotherPlayerTwitter"", ""country"": ""fr"", ""weapons"": [ ""Splatterscope"", ""Splat Charger"", ""Splat Brella"", ""Sorella Brella"" ], ""top500"": true, ""discord"": { ""discordId"": ""346383172986208256"", ""username"": ""!AnotherPlayerDiscord"", ""avatar"": ""482c0dde65d22f31d405efeec6b12b57"", ""discriminator"": ""1783"", ""public_flags"": 0 } } ] }"; try { File.WriteAllText(filePath, JSON); SendouReader reader = new SendouReader(filePath); Source s = reader.Load(); var loadedTeams = s.Teams; var loadedPlayers = s.Players; Assert.AreEqual(0, loadedTeams.Length); Assert.AreEqual(2, loadedPlayers.Length); Assert.IsTrue(loadedPlayers.Any(p => p.Name.Value == "!Username!")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Ids.FirstOrDefault()?.Value == "85179121671364608")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Usernames.FirstOrDefault()?.Value == "!A_DISCORD_USERNAME!#2227")); Assert.IsTrue(loadedPlayers.Any(p => p.TwitterProfiles.FirstOrDefault()?.Value == "Twitter_Name")); Assert.IsTrue(loadedPlayers.Any(p => p.TwitchProfiles.FirstOrDefault()?.Value == "Twitch_Name")); Assert.IsTrue(loadedPlayers.Any(p => p.Name.Value == "AnotherPlayer")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Ids.FirstOrDefault()?.Value == "346383172986208256")); Assert.IsTrue(loadedPlayers.Any(p => p.Discord.Usernames.FirstOrDefault()?.Value == "!AnotherPlayerDiscord#1783")); Assert.IsTrue(loadedPlayers.Any(p => p.TwitterProfiles.FirstOrDefault()?.Value == "AnotherPlayerTwitter")); Assert.IsTrue(loadedPlayers.Count(p => p.Top500) == 1); } finally { File.Delete(filePath); } }