public void Parse_Banners_76156_Test() { var bannerCollectionRaw = SampleDataHelper.GetText(SampleDataHelper.SampleData.SeriesFull76156Banners); var banners = _bannerParseService.Parse(bannerCollectionRaw); Assert.NotNull(banners); Assert.Equal(140, banners.Count); Assert.Equal((uint)23585, banners.First().Id); Assert.Equal((byte)226, (banners.First() as FanartBanner).Colors.First().G); }
/// <summary> /// Parse complete series from an compressed stream with a given language and return null if stream or xml is not valid /// </summary> /// <param name="fullSeriesCompressedStream">Complete series zip compressed stream</param> /// <param name="language">Series language</param> /// <returns>Return the parsed complete series or null if stream or xml is not valid</returns> public async Task <Series> ParseFull(System.IO.Stream fullSeriesCompressedStream, Language language) { if (fullSeriesCompressedStream == null) { throw new ArgumentNullException(nameof(fullSeriesCompressedStream)); } string seriesRaw; string actorsRaw; string bannersRaw; using (var archive = new ZipArchive(fullSeriesCompressedStream, ZipArchiveMode.Read)) { // Throw ParseException if series metadata cannot be retrieved from the compressed file. seriesRaw = archive.GetEntry(language.ToShort() + ".xml").ReadToEnd(); if (seriesRaw == null) { throw new ParseException("Compressed file does not have a series metadata file."); } actorsRaw = archive.GetEntry("actors.xml").ReadToEnd(); bannersRaw = archive.GetEntry("banners.xml").ReadToEnd(); } // Create parse tasks if string not null var seriesTask = Task.Run(() => Parse(seriesRaw)); var actorsTask = actorsRaw != null? Task.Run(() => _actorParseService.Parse(actorsRaw)) : null; var bannersTask = bannersRaw != null? Task.Run(() => _bannerParseService.Parse(bannersRaw)) : null; // Create tasks list to await it var tasks = new List <Task> { seriesTask }; if (actorsTask != null) { tasks.Add(actorsTask); } if (bannersTask != null) { tasks.Add(bannersTask); } await Task.WhenAll(tasks); var series = seriesTask.Result; if (actorsTask != null) { series.Actors = actorsTask.Result; } if (bannersTask != null) { series.Banners = bannersTask.Result; } return(series); }