public async Task TestSlowDownload() { int executeChanged = 0; var downloader = new EpisodeDownloaderStub(); var task = new Task(() => { }); downloader.SetReturnValue(task); var underTest = new PodcastSeries("1", "testCollection", string.Empty, "A test collection", downloader); underTest.DownloadHander.CanExecuteChanged += (_, __) => executeChanged++; PodcastEpisode episode = new PodcastEpisode("2", "title", "subtitle", string.Empty, "http://nowhere.com/episode1.mp3", "This is a podcast", underTest); underTest.Items.Add(episode); underTest.SelectedEpisodes.Add(episode); underTest.DownloadHander.Execute(null); Assert.AreEqual(1, executeChanged); Assert.AreEqual(1, underTest.SelectedEpisodes.Count); task.Start(); // want to await the ownded task. // check the result await underTest.ActiveDownload; Assert.AreEqual(2, executeChanged); Assert.AreEqual(0, underTest.SelectedEpisodes.Count); }
public async Task TestErrorDownload() { int executeChanged = 0; var downloader = new EpisodeDownloaderStub(); var task = new Task(() => { throw new InvalidOperationException("Well, that failed"); }); downloader.SetReturnValue(task); var underTest = new PodcastSeries("1", "testCollection", string.Empty, "A test collection", downloader); underTest.DownloadHander.CanExecuteChanged += (_, __) => executeChanged++; PodcastEpisode episode = new PodcastEpisode("2", "title", "subtitle", string.Empty, "http://nowhere.com/episode1.mp3", "This is a podcast", underTest); underTest.Items.Add(episode); underTest.SelectedEpisodes.Add(episode); underTest.DownloadHander.Execute(null); Assert.AreEqual(1, executeChanged); Assert.AreEqual(1, underTest.SelectedEpisodes.Count); task.Start(); // want to await the ownded task. // check the result try { await underTest.ActiveDownload; Assert.Fail("Exception not generated"); } catch (InvalidOperationException) { return; } }