public void SimplePlayback()
 {
     var playback = new PlaybackStub();
     var underTest = new PodcastEpisode("1", "episode", "just some talking", string.Empty, "http://www.nowhere.com/episode1.mp3", "talking heads", default(PodcastSeries));
     underTest.SetPlaybackControl(playback);
     underTest.Play.Execute(null);
 }
 public void NullPlaybackControlThrowsException()
 {
     var playback = default(IPlayback);
     var underTest = new PodcastEpisode("1", "episode", "just some talking", string.Empty, "http://www.nowhere.com/episode1.mp3", "talking heads", default(PodcastSeries));
     underTest.SetPlaybackControl(playback);
     Assert.ThrowsException<NullReferenceException>(() => underTest.Play.Execute(null));
 }
        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 PlayPauseHandler(PodcastEpisode owner)
 {
     this.owner = owner;
 }
        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;
            }
        }