public async Task <string> GetPlayerNameForId(int playerId) { if (_cache.ContainsKey(playerId)) { return(_cache[playerId]); } string url = _urlConfigurationProvider.GetNflPlayerEndpoint(playerId); string titleTag = await _htmlParserProvider.getInnerTextForFirstXPathMatch(url, XPATH_FOR_PLAYER_NAME); string playerName = _espnHtmlTrimService.TrimNameFromTitleTag(titleTag); _cache[playerId] = playerName; return(playerName); }
public async Task Should_GetPlayerNameForId_ForStandardInput() { //arrange int playerId = 55555; string url = "http://www.espn.com/nfl/player/_/id/55555"; string xPath = "//head/title"; IHtmlParserProvider htmlParserProvider = A.Fake <IHtmlParserProvider>(); A.CallTo(() => htmlParserProvider.getInnerTextForFirstXPathMatch(url, xPath)).Returns("Emmanuel Sanders Stats, News, Bio | ESPN"); IEspnHtmlTrimService espnHtmlTrimService = A.Fake <IEspnHtmlTrimService>(); A.CallTo(() => espnHtmlTrimService.TrimNameFromTitleTag("Emmanuel Sanders Stats, News, Bio | ESPN")).Returns("Emmanuel Sanders"); IUrlConfigurationProvider urlConfigurationProvider = A.Fake <IUrlConfigurationProvider>(); A.CallTo(() => urlConfigurationProvider.GetNflPlayerEndpoint(playerId)).Returns(url); NflPlayerService nflPlayerService = new NflPlayerService(htmlParserProvider, espnHtmlTrimService, urlConfigurationProvider); //act string playerName = await nflPlayerService.GetPlayerNameForId(55555); //assert playerName.Should().BeEquivalentTo("Emmanuel Sanders"); }