public void GetTVSeasonById_ValidSeasonId_ReturnsShow() { // Arrange iTunesSearchManager search = new iTunesSearchManager(); long seasonId = 327827178; // Act var items = search.GetTVSeasonById(seasonId).Result; // Assert Assert.IsTrue(items.Seasons.Any()); Assert.AreEqual("Modern Family", items.Seasons.First().ShowName); }
/// <summary> /// Gets the large artwork url for a given show /// </summary> /// <param name="seasonId"></param> /// <returns></returns> private async Task <string> GetLargeArtworkForSeasonId(long seasonId) { string retval = string.Empty; // If we don't have it in cache, get it in cache if (!seasonArtworkCache.ContainsKey(seasonId)) { TVSeasonListResult result = await iTunes.GetTVSeasonById(seasonId); // If we got results back... if (result.Seasons.Any()) { // Make sure the artwork cache directory exists: if (!Directory.Exists(artworkCachePath)) { Directory.CreateDirectory(artworkCachePath); } // Get information about the artwork var showInfo = result.Seasons.First(); Uri uri = new Uri(showInfo.ArtworkUrlLarge); string artworkExtension = Path.GetExtension(uri.LocalPath); // Get our target filename and save the artwork to the cache directory: string savedArtworkPath = Path.Combine(artworkCachePath, string.Format("{0}_S{1}{2}", showInfo.ShowName, showInfo.SeasonNumber, artworkExtension) ); // If the file doesn't seem to exist on disk, go fetch it: if (!File.Exists(savedArtworkPath)) { WebClient web = new WebClient(); web.DownloadFile(showInfo.ArtworkUrlLarge, savedArtworkPath); } // Store the item in the cache: seasonArtworkCache.AddOrUpdate(seasonId, savedArtworkPath, (key, oldValue) => savedArtworkPath); } } // Return it from cache: try { retval = seasonArtworkCache[seasonId]; } catch (Exception) { } return(retval); }
public void GetTVSeasonById_ValidSeasonId_ReturnsCorrectLargeArtwork() { // Arrange iTunesSearchManager search = new iTunesSearchManager(); long seasonId = 316075588; string expectedShowName = "Gilmore Girls"; string expectedLargeArtworkUrl = "http://is1.mzstatic.com/image/thumb/Music71/v4/82/28/39/8228392e-f1f9-3b64-6c0f-14ba1f958a92/source/600x600bb.jpg"; // Act var items = search.GetTVSeasonById(seasonId).Result; // Assert Assert.IsTrue(items.Seasons.Any()); Assert.AreEqual(expectedShowName, items.Seasons.First().ShowName); Assert.AreEqual(expectedLargeArtworkUrl, items.Seasons.First().ArtworkUrlLarge); }
public void GetTVSeasonById_ValidSeasonId_ReturnsCorrectLargeArtwork() { // Arrange iTunesSearchManager search = new iTunesSearchManager(); long seasonId = 316075588; string expectedShowName = "Gilmore Girls"; string expectedLargeArtworkUrl = "http://is3.mzstatic.com/image/thumb/Music71/v4/8f/5c/1d/8f5c1d3d-c025-de7d-099e-6f55764e0d21/source/600x600bb.jpg"; // Act var items = search.GetTVSeasonById(seasonId).Result; // Assert Assert.IsTrue(items.Seasons.Any()); Assert.AreEqual(expectedShowName, items.Seasons.First().ShowName); Assert.AreEqual(expectedLargeArtworkUrl, items.Seasons.First().ArtworkUrlLarge); }