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); } }
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); } }