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); } }
public async Task GetWinRatioNull() { using (var httpTest = new HttpTest()) { //Arrange var playerName = "TestingPlayer"; var regionName = "eune"; var player = new SummonerDTO { Id = Guid.NewGuid().ToString() }; var leagueEntryDTOs = new LeagueEntryDTO[0]; 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); Assert.Equal("Player got no division on any queue", result); } }