Example #1
0
        public void Test_TraktPost_UserCustomListItemsPostBuilder_AddShowAndSeasonsCollection()
        {
            ITraktShow show = new TraktShow
            {
                Ids = new TraktShowIds
                {
                    Trakt  = 1,
                    Slug   = "show-title",
                    Imdb   = "ttshowtitle",
                    Tmdb   = 1,
                    Tvdb   = 1,
                    TvRage = 1
                }
            };

            var seasons = new PostSeasons
            {
                1,
                { 2, new PostEpisodes {
                      1, 2
                  } }
            };

            ITraktUserCustomListItemsPost userCustomListItemsPost = TraktPost.NewUserCustomListItemsPost()
                                                                    .AddShowAndSeasonsCollection(show).WithSeasons(seasons)
                                                                    .Build();

            userCustomListItemsPost.Should().NotBeNull();
            userCustomListItemsPost.Shows.Should().NotBeNull().And.HaveCount(1);

            ITraktUserCustomListItemsPostShow postShow = userCustomListItemsPost.Shows.ToArray()[0];

            postShow.Ids.Should().NotBeNull();
            postShow.Ids.Trakt.Should().Be(1U);
            postShow.Ids.Slug.Should().Be("show-title");
            postShow.Ids.Imdb.Should().Be("ttshowtitle");
            postShow.Ids.Tmdb.Should().Be(1U);
            postShow.Ids.Tvdb.Should().Be(1U);
            postShow.Ids.TvRage.Should().Be(1U);
            postShow.Seasons.Should().NotBeNull().And.HaveCount(2);

            ITraktUserCustomListItemsPostShowSeason[] showSeasons = postShow.Seasons.ToArray();

            showSeasons[0].Number.Should().Be(1);
            showSeasons[0].Episodes.Should().BeNull();

            showSeasons[1].Number.Should().Be(2);
            showSeasons[1].Episodes.Should().NotBeNull().And.HaveCount(2);

            ITraktUserCustomListItemsPostShowEpisode[] showSeasonPeople = showSeasons[1].Episodes.ToArray();

            showSeasonPeople[0].Number.Should().Be(1);
            showSeasonPeople[1].Number.Should().Be(2);

            userCustomListItemsPost.Movies.Should().NotBeNull().And.BeEmpty();
            userCustomListItemsPost.People.Should().NotBeNull().And.BeEmpty();
        }
Example #2
0
        /// <summary>Adds a <see cref="TraktShow" />, which will be added to the collection post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="seasons">
        /// An <see cref="PostSeasons" /> instance, containing season and episode numbers.<para />
        /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the collection.
        /// </param>
        /// <returns>The current <see cref="TraktSyncCollectionPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero.
        /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero.
        /// </exception>
        public TraktSyncCollectionPostBuilder AddShow(TraktShow show, PostSeasons seasons)
        {
            ValidateShow(show);

            if (seasons == null)
            {
                throw new ArgumentNullException(nameof(seasons));
            }

            EnsureShowsListExists();

            var showSeasons = CreateShowSeasons(seasons);

            CreateOrSetShow(show, showSeasons);

            return(this);
        }
Example #3
0
        private IEnumerable <TraktSyncCollectionPostShowSeason> CreateShowSeasons(PostSeasons seasons)
        {
            var showSeasons = new List <TraktSyncCollectionPostShowSeason>();

            foreach (var season in seasons)
            {
                if (season.Number < 0)
                {
                    throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season));
                }

                var showSingleSeason = new TraktSyncCollectionPostShowSeason {
                    Number = season.Number
                };

                if (season.Episodes != null && season.Episodes.Count() > 0)
                {
                    var showEpisodes = new List <TraktSyncCollectionPostShowEpisode>();

                    foreach (var episode in season.Episodes)
                    {
                        if (episode < 0)
                        {
                            throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons));
                        }

                        showEpisodes.Add(new TraktSyncCollectionPostShowEpisode {
                            Number = episode
                        });
                    }

                    showSingleSeason.Episodes = showEpisodes;
                }

                showSeasons.Add(showSingleSeason);
            }

            return(showSeasons);
        }
Example #4
0
        /// <summary>Adds a <see cref="ITraktShow" />, which will be added to the watchlist post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="seasons">
        /// An <see cref="PostSeasons" /> instance, containing season and episode numbers.<para />
        /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the watchlist.
        /// </param>
        /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero.
        /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero.
        /// </exception>
        public TraktSyncWatchlistPostBuilder AddShow(ITraktShow show, PostSeasons seasons)
        {
            ValidateShow(show);
            EnsureShowsListExists();

            if (_watchlistPost.Shows == null)
            {
                _watchlistPost.Shows = new List <ITraktSyncWatchlistPostShow>();
            }

            List <ITraktSyncWatchlistPostShowSeason> showSeasons = null;

            if (seasons.Any())
            {
                showSeasons = new List <ITraktSyncWatchlistPostShowSeason>();

                foreach (PostSeason season in seasons)
                {
                    if (season.Number < 0)
                    {
                        throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season));
                    }

                    var showSingleSeason = new TraktSyncWatchlistPostShowSeason
                    {
                        Number = season.Number
                    };

                    if (season.Episodes?.Count() > 0)
                    {
                        var showEpisodes = new List <TraktSyncWatchlistPostShowEpisode>();

                        foreach (PostEpisode episode in season.Episodes)
                        {
                            if (episode.Number < 0)
                            {
                                throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons));
                            }

                            showEpisodes.Add(new TraktSyncWatchlistPostShowEpisode
                            {
                                Number = episode.Number
                            });
                        }

                        showSingleSeason.Episodes = showEpisodes;
                    }

                    showSeasons.Add(showSingleSeason);
                }
            }

            ITraktSyncWatchlistPostShow existingShow = _watchlistPost.Shows.FirstOrDefault(s => s.Ids == show.Ids);

            if (existingShow != null)
            {
                existingShow.Seasons = showSeasons;
            }
            else
            {
                var watchlistShow = new TraktSyncWatchlistPostShow
                {
                    Ids     = show.Ids,
                    Title   = show.Title,
                    Year    = show.Year,
                    Seasons = showSeasons
                };

                (_watchlistPost.Shows as List <ITraktSyncWatchlistPostShow>)?.Add(watchlistShow);
            }

            return(this);
        }
Example #5
0
        /// <summary>Adds a <see cref="ITraktShow" />, which will be added to the user custom list items post.</summary>
        /// <param name="show">The Trakt show, which will be added.</param>
        /// <param name="seasons">
        /// An <see cref="PostSeasons" /> instance, containing season and episode numbers.<para />
        /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the custom list.
        /// </param>
        /// <returns>The current <see cref="TraktUserCustomListItemsPostBuilder" /> instance.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown, if the given show is null.
        /// Thrown, if the given show ids are null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given show has no valid ids set.
        /// Thrown, if the given show has an year set, which has more or less than four digits.
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero.
        /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero.
        /// </exception>
        public TraktUserCustomListItemsPostBuilder AddShow(ITraktShow show, PostSeasons seasons)
        {
            ValidateShow(show);

            if (seasons == null)
            {
                throw new ArgumentNullException(nameof(seasons));
            }

            EnsureShowsListExists();

            var showSeasons = new List <ITraktUserCustomListItemsPostShowSeason>();

            foreach (PostSeason season in seasons)
            {
                if (season.Number < 0)
                {
                    throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season));
                }

                var showSingleSeason = new TraktUserCustomListItemsPostShowSeason
                {
                    Number = season.Number
                };

                if (season.Episodes?.Count() > 0)
                {
                    var showEpisodes = new List <ITraktUserCustomListItemsPostShowEpisode>();

                    foreach (PostEpisode episode in season.Episodes)
                    {
                        if (episode.Number < 0)
                        {
                            throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons));
                        }

                        showEpisodes.Add(new TraktUserCustomListItemsPostShowEpisode
                        {
                            Number = episode.Number
                        });
                    }

                    showSingleSeason.Episodes = showEpisodes;
                }

                showSeasons.Add(showSingleSeason);
            }

            ITraktUserCustomListItemsPostShow existingShow = _listItemsPost.Shows.FirstOrDefault(s => s.Ids == show.Ids);

            if (existingShow != null)
            {
                existingShow.Seasons = showSeasons;
            }
            else
            {
                var listItemsShow = new TraktUserCustomListItemsPostShow
                {
                    Ids     = show.Ids,
                    Seasons = showSeasons
                };

                (_listItemsPost.Shows as List <ITraktUserCustomListItemsPostShow>)?.Add(
                    new TraktUserCustomListItemsPostShow
                {
                    Ids     = show.Ids,
                    Seasons = showSeasons
                });
            }

            return(this);
        }
        private IEnumerable <ITraktSyncWatchlistPostShowSeason> CreateSyncWatchlistPostShowSeasons(PostSeasons seasons)
        {
            var syncWatchlistPostShowSeasons = new List <ITraktSyncWatchlistPostShowSeason>();

            foreach (PostSeason season in seasons)
            {
                var syncWatchlistPostShowSeason = new TraktSyncWatchlistPostShowSeason
                {
                    Number = season.Number
                };

                if (season.Episodes?.Count() > 0)
                {
                    var syncWatchlistPostShowEpisodes = new List <ITraktSyncWatchlistPostShowEpisode>();

                    foreach (PostEpisode episode in season.Episodes)
                    {
                        syncWatchlistPostShowEpisodes.Add(new TraktSyncWatchlistPostShowEpisode
                        {
                            Number = episode.Number
                        });
                    }

                    syncWatchlistPostShowSeason.Episodes = syncWatchlistPostShowEpisodes;
                }

                syncWatchlistPostShowSeasons.Add(syncWatchlistPostShowSeason);
            }

            return(syncWatchlistPostShowSeasons);
        }
Example #7
0
        public void Test_TraktPost_SyncWatchlistPostBuilder_AddShowAndSeasonsCollection()
        {
            ITraktShow show = new TraktShow
            {
                Title = "show title",
                Year  = 2020,
                Ids   = new TraktShowIds
                {
                    Trakt  = 1,
                    Slug   = "show-title",
                    Imdb   = "ttshowtitle",
                    Tmdb   = 1,
                    Tvdb   = 1,
                    TvRage = 1
                }
            };

            var seasons = new PostSeasons
            {
                1,
                { 2, new PostEpisodes {
                      1, 2
                  } }
            };

            ITraktSyncWatchlistPost syncWatchlistPost = TraktPost.NewSyncWatchlistPost()
                                                        .AddShowAndSeasonsCollection(show).WithSeasons(seasons)
                                                        .Build();

            syncWatchlistPost.Should().NotBeNull();
            syncWatchlistPost.Shows.Should().NotBeNull().And.HaveCount(1);

            ITraktSyncWatchlistPostShow postShow = syncWatchlistPost.Shows.ToArray()[0];

            postShow.Title = "show title";
            postShow.Year  = 2020;
            postShow.Ids.Should().NotBeNull();
            postShow.Ids.Trakt.Should().Be(1U);
            postShow.Ids.Slug.Should().Be("show-title");
            postShow.Ids.Imdb.Should().Be("ttshowtitle");
            postShow.Ids.Tmdb.Should().Be(1U);
            postShow.Ids.Tvdb.Should().Be(1U);
            postShow.Ids.TvRage.Should().Be(1U);
            postShow.Seasons.Should().NotBeNull().And.HaveCount(2);

            ITraktSyncWatchlistPostShowSeason[] showSeasons = postShow.Seasons.ToArray();

            showSeasons[0].Number.Should().Be(1);
            showSeasons[0].Episodes.Should().BeNull();

            showSeasons[1].Number.Should().Be(2);
            showSeasons[1].Episodes.Should().NotBeNull().And.HaveCount(2);

            ITraktSyncWatchlistPostShowEpisode[] showSeasonEpisodes = showSeasons[1].Episodes.ToArray();

            showSeasonEpisodes[0].Number.Should().Be(1);
            showSeasonEpisodes[1].Number.Should().Be(2);

            syncWatchlistPost.Movies.Should().NotBeNull().And.BeEmpty();
            syncWatchlistPost.Episodes.Should().NotBeNull().And.BeEmpty();
        }
        private ITraktSyncWatchlistPostShow CreateSyncWatchlistPostShowWithSeasonsCollection(ITraktShow show, PostSeasons seasons)
        {
            var syncWatchlistPostShow = CreateSyncWatchlistPostShow(show);

            if (seasons != null)
            {
                syncWatchlistPostShow.Seasons = CreateSyncWatchlistPostShowSeasons(seasons);
            }

            return(syncWatchlistPostShow);
        }
Example #9
0
        private IEnumerable <ITraktSyncCollectionPostShowSeason> CreateSyncCollectionPostShowSeasons(PostSeasons seasons)
        {
            var syncCollectionPostShowSeasons = new List <ITraktSyncCollectionPostShowSeason>();

            foreach (PostSeason season in seasons)
            {
                var syncCollectionPostShowSeason = new TraktSyncCollectionPostShowSeason
                {
                    Number = season.Number
                };

                if (season.Episodes?.Count() > 0)
                {
                    var syncCollectionPostShowEpisodes = new List <ITraktSyncCollectionPostShowEpisode>();

                    foreach (PostEpisode episode in season.Episodes)
                    {
                        syncCollectionPostShowEpisodes.Add(new TraktSyncCollectionPostShowEpisode
                        {
                            Number           = episode.Number,
                            MediaType        = episode.Metadata?.MediaType,
                            MediaResolution  = episode.Metadata?.MediaResolution,
                            Audio            = episode.Metadata?.Audio,
                            AudioChannels    = episode.Metadata?.AudioChannels,
                            ThreeDimensional = episode.Metadata?.ThreeDimensional,
                            HDR         = episode.Metadata?.HDR,
                            CollectedAt = episode.At
                        });
                    }

                    syncCollectionPostShowSeason.Episodes = syncCollectionPostShowEpisodes;
                }

                syncCollectionPostShowSeasons.Add(syncCollectionPostShowSeason);
            }

            return(syncCollectionPostShowSeasons);
        }
Example #10
0
        private ITraktSyncCollectionPostShow CreateSyncCollectionPostShowWithSeasonsCollection(ITraktShow show, ITraktMetadata metadata = null, DateTime?collectedAt = null, PostSeasons seasons = null)
        {
            var syncCollectionPostShow = CreateSyncCollectionPostShow(show, metadata, collectedAt);

            if (seasons != null)
            {
                syncCollectionPostShow.Seasons = CreateSyncCollectionPostShowSeasons(seasons);
            }

            return(syncCollectionPostShow);
        }
        private IEnumerable <ITraktUserCustomListItemsPostShowSeason> CreateUserCustomListItemsPostShowSeasons(PostSeasons seasons)
        {
            var userCustomListItemsPostShowSeasons = new List <ITraktUserCustomListItemsPostShowSeason>();

            foreach (PostSeason season in seasons)
            {
                var userCustomListItemsPostShowSeason = new TraktUserCustomListItemsPostShowSeason
                {
                    Number = season.Number
                };

                if (season.Episodes?.Count() > 0)
                {
                    var userCustomListItemsPostShowEpisodes = new List <ITraktUserCustomListItemsPostShowEpisode>();

                    foreach (PostEpisode episode in season.Episodes)
                    {
                        userCustomListItemsPostShowEpisodes.Add(new TraktUserCustomListItemsPostShowEpisode
                        {
                            Number = episode.Number
                        });
                    }

                    userCustomListItemsPostShowSeason.Episodes = userCustomListItemsPostShowEpisodes;
                }

                userCustomListItemsPostShowSeasons.Add(userCustomListItemsPostShowSeason);
            }

            return(userCustomListItemsPostShowSeasons);
        }
        private ITraktUserCustomListItemsPostShow CreateUserCustomListItemsPostShowWithSeasonsCollection(ITraktShow show, PostSeasons seasons)
        {
            var userCustomListItemsPostShow = CreateUserCustomListItemsPostShow(show);

            if (seasons != null)
            {
                userCustomListItemsPostShow.Seasons = CreateUserCustomListItemsPostShowSeasons(seasons);
            }

            return(userCustomListItemsPostShow);
        }