예제 #1
0
        public void GetEpisodesToDownload_All_OK()
        {
            // Arrange:
            var podCast = new PodCast(
                null,
                "x",
                new Uri("http://xx.dd"),
                "x",
                "x");

            this.PodCastRepository.SavePodCast(podCast);
            var episodes = new List <Episode>();

            episodes.Add(Episode.ConstructEpisode(
                             Guid.NewGuid().ToString(),
                             DateTime.Now,
                             "x",
                             "x",
                             new Uri("http://xxx.ddd"),
                             podCast,
                             true));
            this.EpisodeRepository.UpdateEpisodeList(
                podCast.Id.Value,
                episodes);

            // Act:
            this.EpisodeRepository.GetEpisodesToDownload();

            // Assert:
        }
예제 #2
0
        public void AddEpisodeToDownloadList_1_OK()
        {
            // Arrange:
            var podCast = new PodCast(
                null,
                "x",
                new Uri("http://ww.ee"),
                "x",
                "x");

            this.PodCastRepository.SavePodCast(podCast);
            var episode = Episode.ConstructEpisode(
                Guid.NewGuid().ToString(),
                DateTime.Now,
                "x",
                "x",
                new Uri("http://uu.qq"),
                podCast,
                false);
            var episodes = new List <Episode>();

            episodes.Add(episode);
            this.EpisodeRepository.UpdateEpisodeList(
                podCast.Id.Value,
                episodes);

            // Act:
            this.EpisodeRepository.AddEpisodeToDownloadList(
                podCast.Id.Value,
                episode.Id);

            // Assert:
        }
예제 #3
0
        /// <summary>
        /// Gets the episode.
        /// </summary>
        /// <param name="podCast">The pod cast.</param>
        /// <returns>The episode.</returns>
        private static Episode GetEpisode(PodCast podCast)
        {
            var one = Episode.ConstructEpisode(
                "x",
                DateTime.Now,
                "x",
                "x",
                new Uri("http://www.xxx.dk"),
                podCast,
                false);

            return(one);
        }
예제 #4
0
        /// <summary>
        /// Gets as model.
        /// </summary>
        /// <param name="episode">The episode.</param>
        /// <param name="podCasts">The pod casts.</param>
        /// <returns>The model episode.</returns>
        /// <exception cref="Uncas.PodCastPlayer.Repository.RepositoryException"></exception>
        public static Episode AsModel(
            this DBEpisode episode,
            IList <DBPodCast> podCasts)
        {
            Debug.Assert(
                podCasts != null,
                "Internal code assumes that there are pod casts!");
            Debug.Assert(
                podCasts.Count > 0,
                "Internal code assumes that there are pod casts!");
            if (podCasts == null ||
                episode.MediaUrl == null)
            {
                throw new RepositoryException(
                          InvalidDataText);
            }

            var podCast =
                podCasts.Where(
                    pc => pc.PodCastId == episode.RefPodCastId)
                .SingleOrDefault();

            if (podCast == null)
            {
                throw new RepositoryException(
                          InvalidDataText);
            }

            Uri mediaUrl = null;

            try
            {
                mediaUrl = new Uri(episode.MediaUrl);
            }
            catch (UriFormatException ex)
            {
                throw new RepositoryException(
                          InvalidDataText,
                          ex);
            }

            return(Episode.ConstructEpisode(
                       episode.EpisodeId,
                       episode.Date,
                       episode.Title,
                       episode.Description,
                       mediaUrl,
                       podCast.AsModel(),
                       true));
        }
예제 #5
0
 /// <summary>
 /// Gets the episode.
 /// </summary>
 /// <param name="id">The id of the episode.</param>
 /// <param name="podCast">The pod cast.</param>
 /// <param name="pendingDownload">if set to <c>true</c> [pending download].</param>
 /// <returns>The episode.</returns>
 private static Episode GetEpisode(
     string id,
     PodCast podCast,
     bool pendingDownload)
 {
     return(Episode.ConstructEpisode(
                id,
                DateTime.Now,
                id,
                id,
                new Uri("http://perseus.franklins.net/hanselminutes_0079.mp3"),
                podCast,
                pendingDownload));
 }
예제 #6
0
        public void Constructor_NullMediaUrl_Exception()
        {
            // Arrange:

            // Act:
            var episode = Episode.ConstructEpisode(
                Guid.NewGuid().ToString(),
                DateTime.Now,
                "x",
                "x",
                null,
                null,
                false);

            // Assert:
        }
예제 #7
0
        /// <summary>
        /// Downloads the episode list.
        /// </summary>
        /// <param name="podCast">The pod cast.</param>
        /// <returns>A list of episodes.</returns>
        public IList <Episode> DownloadEpisodeList(
            PodCast podCast)
        {
            var result = new List <Episode>();

            result.AddRange(podCast.Episodes);
            result.Add(Episode.ConstructEpisode(
                           Guid.NewGuid().ToString(),
                           DateTime.Now,
                           "x",
                           "y",
                           new Uri("http://www.xxx.ddd/asdasd.mp3"),
                           podCast,
                           false));
            return(result);
        }
예제 #8
0
        public void UpdateEpisodeList_1New_OK()
        {
            // Arrange:
            var podCast     = new PodCast(1, "x", new Uri("http://xx.dk"));
            var newEpisodes = new List <Episode>();

            newEpisodes.Add(Episode.ConstructEpisode(
                                Guid.NewGuid().ToString(),
                                DateTime.Now,
                                "x",
                                "x",
                                new Uri("http://sss.ddd"),
                                podCast,
                                false));

            // Arrange, act and assert:
            this.UpdateEpisodeList(newEpisodes);
        }
예제 #9
0
        public void FromEpisode_X_OK()
        {
            // Arrange:
            Episode episode =
                Episode.ConstructEpisode(
                    "x",
                    DateTime.Now,
                    "x",
                    "x",
                    new Uri("http://xxx.ddd"),
                    new PodCast(1, "x", null),
                    true);

            // Act:
            DownloadIndexViewModel.FromEpisode(episode);

            // Assert:
        }
예제 #10
0
        /// <summary>
        /// Reads the pod cast.
        /// </summary>
        /// <param name="podCast">The pod cast.</param>
        /// <returns>A list of episodes.</returns>
        /// <exception cref="Uncas.PodCastPlayer.Utility.UtilityException"></exception>
        private static IList <Episode> FetchEpisodeList(
            PodCast podCast)
        {
            var result = new List <Episode>();

            // Loads the pod cast:
            var feed = GetFeed(podCast.Url);

            foreach (var item in feed.Items)
            {
                // Gets enclosure info:
                var enclosure =
                    item.Links.Where(
                        l => l.RelationshipType == "enclosure")
                    .SingleOrDefault();
                if (enclosure == null)
                {
                    continue;
                }

                // Gets episode info:
                var episode =
                    Episode.ConstructEpisode(
                        item.Id,
                        item.PublishDate.Date,
                        item.Title.Text,
                        item.Summary.Text,
                        enclosure.Uri,
                        podCast,
                        false);

                episode.MediaInfo =
                    new EpisodeMediaInfo
                {
                    FileSizeInBytes = enclosure.Length
                };

                result.Add(episode);
            }

            return(result);
        }
예제 #11
0
        public void UpdateEpisode_1_OK()
        {
            // Arrange:
            var podCast = new PodCast(
                1,
                "x",
                new Uri("http://xx.ss"),
                "x",
                "x");
            var episode =
                Episode.ConstructEpisode(
                    Guid.NewGuid().ToString(),
                    DateTime.Now,
                    "x",
                    "x",
                    new Uri("http://xx.ss/sss.mp3"),
                    podCast,
                    false);

            // Act:
            this.EpisodeRepository.UpdateEpisode(episode);

            // Assert:
        }
예제 #12
0
        public void GetEpisodes_UnsortedSource_CheckSortedResult()
        {
            // Arrange:
            var podCastIndexViewModel =
                this.PodCastRepository.GetPodCasts()
                .FirstOrDefault();
            int     podCastId = 1;
            PodCast podCast   = null;

            if (podCastIndexViewModel == null)
            {
                podCast = new PodCast(
                    podCastId,
                    "x",
                    new Uri("http://www.xxx.ddd"),
                    "x",
                    "x");
                this.PodCastRepository.SavePodCast(podCast);
            }
            else
            {
                podCastId =
                    podCastIndexViewModel.Id.Value;
                podCast =
                    this.PodCastRepository.GetPodCast(
                        podCastId);
            }

            var episodes     = new List <Episode>();
            var episodeToday =
                Episode.ConstructEpisode(
                    Guid.NewGuid().ToString(),
                    DateTime.Now,
                    "x",
                    "x",
                    new Uri("http://www.xxxx.ddd"),
                    podCast,
                    false);
            var episodeOneDayAgo =
                Episode.ConstructEpisode(
                    Guid.NewGuid().ToString(),
                    DateTime.Now.AddDays(-1d),
                    "x",
                    "x",
                    new Uri("http://www.xxxx.ddd"),
                    podCast,
                    false);
            var episodeOneWeekAgo =
                Episode.ConstructEpisode(
                    Guid.NewGuid().ToString(),
                    DateTime.Now.AddDays(-7d),
                    "x",
                    "x",
                    new Uri("http://www.xxxx.ddd"),
                    podCast,
                    false);

            episodes.Add(episodeOneWeekAgo);
            episodes.Add(episodeToday);
            episodes.Add(episodeOneDayAgo);
            this.EpisodeRepository.UpdateEpisodeList(
                podCastId,
                episodes);

            // Act:
            var episodeList =
                this.EpisodeRepository.GetEpisodes(
                    podCastId).Episodes.ToList();

            // Assert:
            // Check that the newest episode is first, etc:
            for (int episodeIndex = 0;
                 episodeIndex <
                 episodeList.Count() - 1;
                 episodeIndex++)
            {
                var thisEpisode =
                    episodeList[episodeIndex];
                var nextEpisode =
                    episodeList[episodeIndex + 1];
                Assert.IsTrue(
                    nextEpisode.Date <=
                    thisEpisode.Date);
            }
        }