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