public async Task Test_TraktSyncModule_AddCollectionItems_ArgumentExceptions()
        {
            string postJson = await TestUtility.SerializeObject(AddCollectionItemsPost);

            postJson.Should().NotBeNullOrEmpty();

            TraktClient client = TestUtility.GetOAuthMockClient(ADD_COLLECTION_ITEMS_URI, postJson, COLLECTION_POST_RESPONSE_JSON);

            Func <Task <TraktResponse <ITraktSyncCollectionPostResponse> > > act = () => client.Sync.AddCollectionItemsAsync(null);

            act.Should().Throw <ArgumentNullException>();

            act = () => client.Sync.AddCollectionItemsAsync(new TraktSyncCollectionPost());
            act.Should().Throw <ArgumentException>();

            ITraktSyncCollectionPost collectionPost = new TraktSyncCollectionPost
            {
                Movies   = new List <ITraktSyncCollectionPostMovie>(),
                Shows    = new List <ITraktSyncCollectionPostShow>(),
                Episodes = new List <ITraktSyncCollectionPostEpisode>()
            };

            act = () => client.Sync.AddCollectionItemsAsync(collectionPost);
            act.Should().Throw <ArgumentException>();
        }
        public void TestTraktSyncCollectionPostDefaultConstructor()
        {
            var collectionPost = new TraktSyncCollectionPost();

            collectionPost.Movies.Should().BeNull();
            collectionPost.Shows.Should().BeNull();
            collectionPost.Episodes.Should().BeNull();
        }
        public ITraktSyncCollectionPost Build()
        {
            ITraktSyncCollectionPost syncCollectionPost = new TraktSyncCollectionPost();

            AddMovies(syncCollectionPost);
            AddShows(syncCollectionPost);
            AddEpisodes(syncCollectionPost);
            return(syncCollectionPost);
        }
        public override async Task <ITraktSyncCollectionPost> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktSyncCollectionPost)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktSyncCollectionPost traktSyncCollectionPost = new TraktSyncCollectionPost();
                var syncCollectionPostMovieArrayJsonReader       = new SyncCollectionPostMovieArrayJsonReader();
                var syncCollectionPostShowArrayJsonReader        = new SyncCollectionPostShowArrayJsonReader();
                var syncCollectionPostEpisodeArrayJsonReader     = new SyncCollectionPostEpisodeArrayJsonReader();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.SYNC_COLLECTION_POST_PROPERTY_NAME_MOVIES:
                        traktSyncCollectionPost.Movies = await syncCollectionPostMovieArrayJsonReader.ReadArrayAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.SYNC_COLLECTION_POST_PROPERTY_NAME_SHOWS:
                        traktSyncCollectionPost.Shows = await syncCollectionPostShowArrayJsonReader.ReadArrayAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.SYNC_COLLECTION_POST_PROPERTY_NAME_EPISODES:
                        traktSyncCollectionPost.Episodes = await syncCollectionPostEpisodeArrayJsonReader.ReadArrayAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktSyncCollectionPost);
            }

            return(await Task.FromResult(default(ITraktSyncCollectionPost)));
        }
Beispiel #5
0
        private void ValidateCollectionPost(TraktSyncCollectionPost collectionPost)
        {
            if (collectionPost == null)
            {
                throw new ArgumentNullException(nameof(collectionPost), "collection post must not be null");
            }

            var movies   = collectionPost.Movies;
            var shows    = collectionPost.Shows;
            var episodes = collectionPost.Episodes;

            var bHasNoMovies   = movies == null || !movies.Any();
            var bHasNoShows    = shows == null || !shows.Any();
            var bHasNoEpisodes = episodes == null || !episodes.Any();

            if (bHasNoMovies && bHasNoShows && bHasNoEpisodes)
            {
                throw new ArgumentException("no collection items set");
            }
        }
Beispiel #6
0
        public async Task <TraktSyncCollectionRemovePostResponse> RemoveCollectionItemsAsync([NotNull] TraktSyncCollectionPost collectionRemovePost)
        {
            ValidateCollectionPost(collectionRemovePost);

            return(await QueryAsync(new TraktSyncCollectionRemoveRequest(Client) { RequestBody = collectionRemovePost }));
        }
        public void TestTraktSyncCollectionPostWriteJsonWithoutMetadata()
        {
            var collectionPost = new TraktSyncCollectionPost
            {
                Movies = new List <TraktSyncCollectionPostMovie>()
                {
                    new TraktSyncCollectionPostMovie
                    {
                        CollectedAt = DateTime.Parse("2014-09-01T09:10:11.000Z").ToUniversalTime(),
                        Title       = "Batman Begins",
                        Year        = 2005,
                        Ids         = new TraktMovieIds
                        {
                            Trakt = 1,
                            Slug  = "batman-begins-2005",
                            Imdb  = "tt0372784",
                            Tmdb  = 272
                        }
                    },
                    new TraktSyncCollectionPostMovie
                    {
                        Ids = new TraktMovieIds
                        {
                            Imdb = "tt0000111"
                        }
                    }
                },
                Shows = new List <TraktSyncCollectionPostShow>()
                {
                    new TraktSyncCollectionPostShow
                    {
                        Title = "Breaking Bad",
                        Year  = 2008,
                        Ids   = new TraktShowIds
                        {
                            Trakt  = 1,
                            Slug   = "breaking-bad",
                            Tvdb   = 81189,
                            Imdb   = "tt0903747",
                            Tmdb   = 1396,
                            TvRage = 18164
                        }
                    },
                    new TraktSyncCollectionPostShow
                    {
                        Title = "The Walking Dead",
                        Year  = 2010,
                        Ids   = new TraktShowIds
                        {
                            Trakt  = 2,
                            Slug   = "the-walking-dead",
                            Tvdb   = 153021,
                            Imdb   = "tt1520211",
                            Tmdb   = 1402,
                            TvRage = 25056
                        },
                        Seasons = new List <TraktSyncCollectionPostShowSeason>()
                        {
                            new TraktSyncCollectionPostShowSeason
                            {
                                Number = 3
                            }
                        }
                    },
                    new TraktSyncCollectionPostShow
                    {
                        Title = "Mad Men",
                        Year  = 2007,
                        Ids   = new TraktShowIds
                        {
                            Trakt  = 4,
                            Slug   = "mad-men",
                            Tvdb   = 80337,
                            Imdb   = "tt0804503",
                            Tmdb   = 1104,
                            TvRage = 16356
                        },
                        Seasons = new List <TraktSyncCollectionPostShowSeason>()
                        {
                            new TraktSyncCollectionPostShowSeason
                            {
                                Number   = 1,
                                Episodes = new List <TraktSyncCollectionPostShowEpisode>()
                                {
                                    new TraktSyncCollectionPostShowEpisode
                                    {
                                        Number = 1
                                    },
                                    new TraktSyncCollectionPostShowEpisode
                                    {
                                        Number = 2
                                    }
                                }
                            }
                        }
                    }
                },
                Episodes = new List <TraktSyncCollectionPostEpisode>()
                {
                    new TraktSyncCollectionPostEpisode
                    {
                        Ids = new TraktEpisodeIds
                        {
                            Trakt  = 1061,
                            Tvdb   = 1555111,
                            Imdb   = "tt007404",
                            Tmdb   = 422183,
                            TvRage = 12345
                        }
                    }
                }
            };

            var strJson = JsonConvert.SerializeObject(collectionPost);

            strJson.Should().NotBeNullOrEmpty();

            var collectionPostFromJson = JsonConvert.DeserializeObject <TraktSyncCollectionPost>(strJson);

            collectionPostFromJson.Should().NotBeNull();

            collectionPostFromJson.Movies.Should().NotBeNull().And.HaveCount(2);
            collectionPostFromJson.Shows.Should().NotBeNull().And.HaveCount(3);
            collectionPostFromJson.Episodes.Should().NotBeNull().And.HaveCount(1);

            var movies = collectionPostFromJson.Movies.ToArray();

            movies[0].CollectedAt.Should().Be(DateTime.Parse("2014-09-01T09:10:11.000Z").ToUniversalTime());
            movies[0].Title.Should().Be("Batman Begins");
            movies[0].Year.Should().Be(2005);
            movies[0].Ids.Should().NotBeNull();
            movies[0].Ids.Trakt.Should().Be(1U);
            movies[0].Ids.Slug.Should().Be("batman-begins-2005");
            movies[0].Ids.Imdb.Should().Be("tt0372784");
            movies[0].Ids.Tmdb.Should().Be(272U);
            movies[0].Metadata.Should().BeNull();

            movies[1].CollectedAt.Should().NotHaveValue();
            movies[1].Title.Should().BeNullOrEmpty();
            movies[1].Year.Should().NotHaveValue();
            movies[1].Ids.Should().NotBeNull();
            movies[1].Ids.Trakt.Should().Be(0U);
            movies[1].Ids.Slug.Should().BeNullOrEmpty();
            movies[1].Ids.Imdb.Should().Be("tt0000111");
            movies[1].Ids.Tmdb.Should().BeNull();
            movies[1].Metadata.Should().BeNull();

            var shows = collectionPostFromJson.Shows.ToArray();

            shows[0].CollectedAt.Should().NotHaveValue();
            shows[0].Title.Should().Be("Breaking Bad");
            shows[0].Year.Should().Be(2008);
            shows[0].Ids.Should().NotBeNull();
            shows[0].Ids.Trakt.Should().Be(1U);
            shows[0].Ids.Slug.Should().Be("breaking-bad");
            shows[0].Ids.Tvdb.Should().Be(81189U);
            shows[0].Ids.Imdb.Should().Be("tt0903747");
            shows[0].Ids.Tmdb.Should().Be(1396U);
            shows[0].Ids.TvRage.Should().Be(18164U);
            shows[0].Seasons.Should().BeNull();

            shows[1].CollectedAt.Should().NotHaveValue();
            shows[1].Title.Should().Be("The Walking Dead");
            shows[1].Year.Should().Be(2010);
            shows[1].Ids.Should().NotBeNull();
            shows[1].Ids.Trakt.Should().Be(2U);
            shows[1].Ids.Slug.Should().Be("the-walking-dead");
            shows[1].Ids.Tvdb.Should().Be(153021U);
            shows[1].Ids.Imdb.Should().Be("tt1520211");
            shows[1].Ids.Tmdb.Should().Be(1402U);
            shows[1].Ids.TvRage.Should().Be(25056U);
            shows[1].Seasons.Should().NotBeNull().And.HaveCount(1);

            var show2Seasons = shows[1].Seasons.ToArray();

            show2Seasons[0].Number.Should().Be(3);
            show2Seasons[0].Episodes.Should().BeNull();

            shows[2].CollectedAt.Should().NotHaveValue();
            shows[2].Title.Should().Be("Mad Men");
            shows[2].Year.Should().Be(2007);
            shows[2].Ids.Should().NotBeNull();
            shows[2].Ids.Trakt.Should().Be(4U);
            shows[2].Ids.Slug.Should().Be("mad-men");
            shows[2].Ids.Tvdb.Should().Be(80337U);
            shows[2].Ids.Imdb.Should().Be("tt0804503");
            shows[2].Ids.Tmdb.Should().Be(1104U);
            shows[2].Ids.TvRage.Should().Be(16356U);
            shows[2].Seasons.Should().NotBeNull().And.HaveCount(1);

            var show3Seasons = shows[2].Seasons.ToArray();

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

            var show3Season1Episodes = show3Seasons[0].Episodes.ToArray();

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

            var episodes = collectionPostFromJson.Episodes.ToArray();

            episodes[0].CollectedAt.Should().NotHaveValue();
            episodes[0].Metadata.Should().BeNull();
            episodes[0].Ids.Should().NotBeNull();
            episodes[0].Ids.Trakt.Should().Be(1061U);
            episodes[0].Ids.Tvdb.Should().Be(1555111U);
            episodes[0].Ids.Imdb.Should().Be("tt007404");
            episodes[0].Ids.Tmdb.Should().Be(422183U);
            episodes[0].Ids.TvRage.Should().Be(12345U);
        }