private static async Task GetLyrics(Artist model, Uri baseAddress, IBLService _blService, List <string> singles, List <Song> songs) { using (var httpClient = new HttpClient { BaseAddress = baseAddress, Timeout = TimeSpan.FromSeconds(20) }) { foreach (var single in singles) { //if statement is to avoid duplicates if (songs.Where(x => x.Name == single).Count() == 0) { try { HttpResponseMessage response = await httpClient.GetAsync(model.ArtistName + "/" + single); if (response.IsSuccessStatusCode) { int noWordsinSong; string responseData = await response.Content.ReadAsStringAsync(); noWordsinSong = _blService.CountWords(responseData); Song song = new Song(); song.Name = single; song.WordCount = noWordsinSong; songs.Add(song); } } catch (Exception) { } } } } }
public void CountWords_Test() { //Arrange string text = "hello my name is test"; int expected = 5; int actual; IBLService bLService = BLServiceFactory.GetBLServiceObj(); //Act actual = bLService.CountWords(text); //Assert Assert.AreEqual(expected, actual); }