private void PerformTest(IAudioDownloadOutputSample sample) { const string DownloadDirectory = "fakepath"; MockForAudioDownloadTest processMock = this.CreateProcessFactory(sample, DownloadDirectory); YoutubeDl downloader = new YoutubeDl(processMock); Dictionary <double, bool> ExpectedPercentsToBeReported = new Dictionary <double, bool>(sample.ExpectedPercents.Distinct().Select(x => new KeyValuePair <double, bool>(x, false))); Dictionary <DownloadState, bool> ExpectedStatusesToBeReported = new Dictionary <DownloadState, bool>(sample.ExpectedDownloadStatuses.Distinct().Select(x => new KeyValuePair <DownloadState, bool>(x, false))); using (IDownload progress = downloader.PrepareDownload(new Uri(sample.MediaUri), MediaFormat.MP3Audio, DownloadDirectory)) { RunDownload(processMock, ExpectedPercentsToBeReported, ExpectedStatusesToBeReported, progress); } foreach (var item in ExpectedStatusesToBeReported) { Assert.IsTrue(item.Value, $"Expected download status {item.Key} was not reported by event {nameof(IDownload.DownloadStatusChanged)}."); } foreach (var item in ExpectedPercentsToBeReported) { Assert.IsTrue(item.Value, $"Expected download percentage {item.Key} was not reported by event {nameof(IDownload.PercentageChanged)}."); } }
private MockForAudioDownloadTest CreateProcessFactory(IAudioDownloadOutputSample sample, string downloadPath) { if (sample is ISuccessfulAudioOutputSample successfulSample) { return(new MockForAudioDownloadTest(successfulSample.GetStdOut(), 0, downloadPath)); } else if (sample is IFailedAudioOutputSample failedSample) { return(new MockForAudioDownloadTest(failedSample.Output, failedSample.ExitCode, downloadPath)); } throw new NotSupportedException($"{sample.GetType().FullName} is not supported."); }