Esempio n. 1
0
        private void ValidateRankedInfo(string[] objects)
        {
            bool valid       = true;
            int  arrayLength = objects.Length;
            int  numberOfRankedGames;

            if (!int.TryParse(objects[arrayLength - 1], out numberOfRankedGames))
            {
                valid = false;
            }
            if (numberOfRankedGames > 10)
            {
                valid = false;
            }
            if (!RiotApiService.ValidReigon(objects[arrayLength - 2]))
            {
                valid = false;
            }

            if (!valid)
            {
                throw new ArgumentException("Arguments should be the following:\n1: Summoner Name\n" +
                                            "2: Reigon\n" +
                                            "3: Number of Ranked Games (10 max)");
            }
        }
Esempio n. 2
0
        public async Task FetchPlayerIdSucces()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName = "TestingPlayer";
                var regionName = "eune";
                var player     = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var mockMemoryCache   = new Mock <IMemoryCache>();
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(mockMemoryCache.Object, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);

                //Act

                var result = await riotApiService.FetchPlayerId(playerName, regionName);

                //Assert
                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{playerName}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);
                Assert.Equal(player.Id, result);
            }
        }
Esempio n. 3
0
        public async Task GetRankedInfoAsync(params string[] objects)
        {
            ValidateRankedInfo(objects);
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i <= objects.Length - 3; i++)
            {
                stringBuilder.Append(objects[i] + " ");
            }

            string summonerName = stringBuilder.ToString().Substring(0, stringBuilder.ToString().Length - 1);

            await ReplyAsync("Obtaining ranked stats for summoner :" + summonerName + " ...");

            var result = await RiotApiService.GetRankedHistoryAsync(summonerName, objects[objects.Length - 2], Int32.Parse(objects[objects.Length - 1]));

            var embed = new EmbedBuilder
            {
                Title        = "Ranked History for " + objects[0],
                Color        = Color.Green,
                ThumbnailUrl = DataDragonService.GetSummonerIconURL(result["IconID"]),
            };

            embed.WithAuthor(author);
            embed.AddField("Wins", result["Wins"], true);
            embed.AddField("Losses", result["Loss"], true);
            embed.AddField("Win rate", result["Winrate"], true);
            embed.AddField("Match History", result["Data"], false);

            embed.WithCurrentTimestamp();
            await ReplyAsync(embed : embed.Build());
        }
Esempio n. 4
0
        public async Task GetMasterySuccess()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName   = "TestingPlayer";
                var regionName   = "eune";
                var championName = "Test";
                var championId   = 10;
                var player       = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var championDTOs = new ChampionDTO[]
                {
                    new ChampionDTO
                    {
                        Name = "Test",
                        Id   = championId
                    }
                };
                var championMasteryDTO = new ChampionMasteryDTO
                {
                    ChampionLevel  = 1,
                    ChampionPoints = "2000"
                };
                var memoryCache       = new MemoryCache(new MemoryCacheOptions());
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(memoryCache, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);
                httpTest.RespondWithJson(championDTOs, 200);
                httpTest.RespondWithJson(championMasteryDTO, 200);

                //Act

                var result = await riotApiService.GetMastery(playerName, regionName, championName);

                //Assert
                httpTest.ShouldHaveCalled($"http://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/champion-mastery/v4/champion-masteries/by-summoner/{player.Id}/by-champion/{championId}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                Assert.Equal($"Champion level {championMasteryDTO.ChampionLevel} with {championName} ({championMasteryDTO.ChampionPoints ?? "0"} points)", result);
            }
        }
Esempio n. 5
0
        public async Task GetWinRatioSuccess()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName = "TestingPlayer";
                var regionName = "eune";
                var wins       = 10;
                var losses     = 10;
                var player     = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var LeagueEntryDTOs = new LeagueEntryDTO[]
                {
                    new LeagueEntryDTO
                    {
                        QueueType = "RANKED_SOLO_5x5",
                        Wins      = wins,
                        Losses    = losses
                    }
                };
                var mockMemoryCache   = new Mock <IMemoryCache>();
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(mockMemoryCache.Object, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);
                httpTest.RespondWithJson(LeagueEntryDTOs, 200);

                //Act

                var result = await riotApiService.GetWinRatio(playerName, regionName);

                //Assert
                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{playerName}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/league/v4/entries/by-summoner/{player.Id}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);

                var winRatio = 100 * wins / (wins + losses);
                Assert.Equal($"Solo Win Ratio: {winRatio}%\r\n", result);
            }
        }
Esempio n. 6
0
        public async Task GetLiveMatchDataAsync(params string[] objects)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i <= objects.Length - 2; i++)
            {
                stringBuilder.Append(objects[i] + " ");
            }
            string summonerName = stringBuilder.ToString().Substring(0, stringBuilder.ToString().Length - 1);
            string reigon       = objects[objects.Length - 1];

            if (RiotApiService.ValidReigon(reigon) == false)
            {
                throw new ArgumentException("Arguments should be the following:\n1: Summoner Name\n" +
                                            "2: Reigon\n");
            }
            await ReplyAsync("Obtaining summoner info for summoner : " + summonerName + " ...");

            CurrentGameInfo currentGameInfo = await RiotApiService.GetLiveMatchDataAsync(summonerName, reigon);

            var           blueSide          = currentGameInfo.Participants.Where(player => player.TeamId == 100);
            var           redSide           = currentGameInfo.Participants.Where(player => player.TeamId == 200);
            var           summonerIcon      = currentGameInfo.Participants.First(player => player.SummonerName == summonerName).ProfileIconId;
            StringBuilder blueStringBuilder = new StringBuilder();

            foreach (var participant in blueSide)
            {
                blueStringBuilder.AppendLine(participant.SummonerName + " : " + RiotApiService.MakeBold(((Champion)participant.ChampionId).Name()));
            }
            StringBuilder redStringBuilder = new StringBuilder();

            foreach (var participant in redSide)
            {
                redStringBuilder.AppendLine(participant.SummonerName + " : " + RiotApiService.MakeBold(((Champion)participant.ChampionId).Name()));
            }
            var embed = new EmbedBuilder
            {
                Title        = $"Live Match Data for {summonerName}",
                Color        = Color.Green,
                ThumbnailUrl = DataDragonService.GetMapURL(currentGameInfo.MapId.ToString()),
            };

            embed.AddField("Game Type", currentGameInfo.GameMode);
            embed.AddField("Blue Side", blueStringBuilder.ToString(), true);
            embed.AddField("Red Side", redStringBuilder.ToString(), true);
            embed.WithCurrentTimestamp();
            await ReplyAsync(embed : embed.Build());
        }
Esempio n. 7
0
        public async Task GetSummonerInfoAsync(params string[] objects)
        {
            if (RiotApiService.ValidReigon(objects[objects.Length - 1]) == false)
            {
                throw new ArgumentException("Arguments should be the following:\n1: Summoner Name\n" +
                                            "2: Reigon\n");
            }
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i <= objects.Length - 2; i++)
            {
                stringBuilder.Append(objects[i] + " ");
            }
            string summonerName = stringBuilder.ToString().Substring(0, stringBuilder.ToString().Length - 1);

            await ReplyAsync("Obtaining summoner info for summoner : " + summonerName + " ...");

            var result = await RiotApiService.GetSummonerInfoAsync(summonerName, objects[objects.Length - 1]);

            var embed = new EmbedBuilder();

            embed.WithAuthor(author);
            embed.Color = Color.Green;
            embed.Title = summonerName;
            embed.AddField("Level", result["Level"]);
            if (result.ContainsKey("RANKED_FLEX_SR"))
            {
                embed.AddField("Flex Rank", GetRankedLogo(result["RANKED_FLEX_SR"]) + " " + result["RANKED_FLEX_SR"], true);
                embed.AddField("Flex WR", result["RANKED_FLEX_SRWR"], true);
            }
            if (result.ContainsKey("RANKED_SOLO_5x5"))
            {
                embed.AddField("Solo Rank", GetRankedLogo(result["RANKED_SOLO_5x5"]) + " " + result["RANKED_SOLO_5x5"], true);
                embed.AddField("Solo WR", result["RANKED_SOLO_5x5WR"], true);
            }
            embed.AddField("Highest Champion Mastery",
                           result["ChampMastery"] + " " + result["ChampMasteryScore"] + " points");
            embed.ImageUrl     = DataDragonService.GetChampionImageURL(result["ChampMastery"]);
            embed.ThumbnailUrl = DataDragonService.GetSummonerIconURL(result["IconID"]);
            embed.WithCurrentTimestamp();

            await ReplyAsync(embed : embed.Build());
        }
Esempio n. 8
0
        public async Task FetchPlayerIdPlayerNotFound()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName        = "TestingPlayer";
                var regionName        = "eune";
                var player            = new SummonerDTO();
                var mockMemoryCache   = new Mock <IMemoryCache>();
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(mockMemoryCache.Object, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 404);

                //Act
                await Assert.ThrowsAsync <PlayerNotFoundException>(() => riotApiService.FetchPlayerId(playerName, regionName));

                //Assert
                httpTest.ShouldHaveCalled($"https://eun1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{playerName}")
                .WithQueryParams("api_key")
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }
Esempio n. 9
0
        public async Task GetMasteryNull()
        {
            using (var httpTest = new HttpTest())
            {
                //Arrange
                var playerName   = "TestingPlayer";
                var regionName   = "eune";
                var championName = "Unexisting Champion";
                var player       = new SummonerDTO
                {
                    Id = Guid.NewGuid().ToString()
                };
                var championDTOs = new ChampionDTO[]
                {
                    new ChampionDTO
                    {
                        Name = "Test"
                    }
                };
                var memoryCache       = new MemoryCache(new MemoryCacheOptions());
                var mockIConfigration = new Mock <IConfiguration>();
                mockIConfigration.Setup(c => c[Constants.RIOT_APIKEY]).Returns("RiotApiKey");
                var riotApiService = new RiotApiService(memoryCache, mockIConfigration.Object);
                httpTest.RespondWithJson(player, 200);
                httpTest.RespondWithJson(championDTOs, 200);

                //Act

                await Assert.ThrowsAsync <ChampionNotFoundException>(() => riotApiService.GetMastery(playerName, regionName, championName));

                //Assert
                httpTest.ShouldHaveCalled($"http://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json")
                .WithVerb(HttpMethod.Get)
                .Times(1);
            }
        }