public void Test_TraktPost_SyncWatchlistPostBuilder_AddShowAndSeasons() { 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 } }; ITraktSyncWatchlistPost syncWatchlistPost = TraktPost.NewSyncWatchlistPost() .AddShowAndSeasons(show).WithSeasons(1, 2, 3) .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(3); ITraktSyncWatchlistPostShowSeason[] seasons = postShow.Seasons.ToArray(); seasons[0].Number.Should().Be(1); seasons[0].Episodes.Should().BeNull(); seasons[1].Number.Should().Be(2); seasons[1].Episodes.Should().BeNull(); seasons[2].Number.Should().Be(3); seasons[2].Episodes.Should().BeNull(); syncWatchlistPost.Movies.Should().NotBeNull().And.BeEmpty(); syncWatchlistPost.Episodes.Should().NotBeNull().And.BeEmpty(); }
/// <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); }