Exemple #1
0
        public async Task Test_CollectionShowSeasonArrayJsonWriter_WriteArray_JsonWriter_SingleObject()
        {
            IEnumerable <ITraktCollectionShowSeason> traktCollectionShowSeasons = new List <ITraktCollectionShowSeason>
            {
                new TraktCollectionShowSeason
                {
                    Number   = 1,
                    Episodes = new List <ITraktCollectionShowEpisode>
                    {
                        new TraktCollectionShowEpisode
                        {
                            Number      = 1,
                            CollectedAt = COLLECTED_AT,
                            Metadata    = new TraktMetadata
                            {
                                MediaType        = TraktMediaType.Digital,
                                MediaResolution  = TraktMediaResolution.HD_720p,
                                Audio            = TraktMediaAudio.AAC,
                                AudioChannels    = TraktMediaAudioChannel.Channels_5_1,
                                ThreeDimensional = true
                            }
                        },
                        new TraktCollectionShowEpisode
                        {
                            Number      = 1,
                            CollectedAt = COLLECTED_AT,
                            Metadata    = new TraktMetadata
                            {
                                MediaType        = TraktMediaType.Digital,
                                MediaResolution  = TraktMediaResolution.HD_720p,
                                Audio            = TraktMediaAudio.AAC,
                                AudioChannels    = TraktMediaAudioChannel.Channels_5_1,
                                ThreeDimensional = true
                            }
                        }
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktCollectionShowSeason>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktCollectionShowSeasons);

                    stringWriter.ToString().Should().Be(@"[{""number"":1,""episodes"":[{""number"":1," +
                                                        $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""metadata"":{""media_type"":""digital""," +
                                                        @"""resolution"":""hd_720p"",""audio"":""aac""," +
                                                        @"""audio_channels"":""5.1"",""3d"":true}}," +
                                                        @"{""number"":1," +
                                                        $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""metadata"":{""media_type"":""digital""," +
                                                        @"""resolution"":""hd_720p"",""audio"":""aac""," +
                                                        @"""audio_channels"":""5.1"",""3d"":true}}]}]");
                }
        }
        public async Task Test_EpisodeCollectionProgressArrayJsonWriter_WriteArray_Array_Empty()
        {
            IEnumerable <ITraktEpisodeCollectionProgress> traktEpisodeCollectionProgresss = new List <TraktEpisodeCollectionProgress>();

            var    traktJsonWriter = new ArrayJsonWriter <ITraktEpisodeCollectionProgress>();
            string json            = await traktJsonWriter.WriteArrayAsync(traktEpisodeCollectionProgresss);

            json.Should().Be("[]");
        }
Exemple #3
0
        public async Task Test_HistoryItemArrayJsonWriter_Episode_WriteArray_JsonWriter_SingleObject()
        {
            IEnumerable <ITraktHistoryItem> traktHistoryItems = new List <ITraktHistoryItem>
            {
                new TraktHistoryItem
                {
                    Id        = 1982347UL,
                    WatchedAt = WATCHED_AT,
                    Action    = TraktHistoryActionType.Checkin,
                    Type      = TraktSyncItemType.Episode,
                    Episode   = new TraktEpisode
                    {
                        SeasonNumber = 1,
                        Number       = 1,
                        Title        = "Winter Is Coming",
                        Ids          = new TraktEpisodeIds
                        {
                            Trakt  = 73640U,
                            Tvdb   = 3254641U,
                            Imdb   = "tt1480055",
                            Tmdb   = 63056U,
                            TvRage = 1065008299U
                        }
                    },
                    Show = new TraktShow
                    {
                        Title = "Game of Thrones",
                        Year  = 2011,
                        Ids   = new TraktShowIds
                        {
                            Trakt  = 1390U,
                            Slug   = "game-of-thrones",
                            Tvdb   = 121361U,
                            Imdb   = "tt0944947",
                            Tmdb   = 1399U,
                            TvRage = 24493U
                        }
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktHistoryItem>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktHistoryItems);

                    stringWriter.ToString().Should().Be(@"[{""id"":1982347," +
                                                        $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""action"":""checkin"",""type"":""episode""," +
                                                        @"""show"":{""title"":""Game of Thrones"",""year"":2011," +
                                                        @"""ids"":{""trakt"":1390,""slug"":""game-of-thrones"",""tvdb"":121361," +
                                                        @"""imdb"":""tt0944947"",""tmdb"":1399,""tvrage"":24493}}," +
                                                        @"""episode"":{""season"":1,""number"":1,""title"":""Winter Is Coming""," +
                                                        @"""ids"":{""trakt"":73640,""tvdb"":3254641,""imdb"":""tt1480055"",""tmdb"":63056,""tvrage"":1065008299}}}]");
                }
        }
Exemple #4
0
        public async Task Test_HistoryItemArrayJsonWriter_Season_WriteArray_Array_Complete()
        {
            IEnumerable <ITraktHistoryItem> traktHistoryItems = new List <ITraktHistoryItem>
            {
                new TraktHistoryItem
                {
                    Id        = 1982347UL,
                    WatchedAt = WATCHED_AT,
                    Action    = TraktHistoryActionType.Checkin,
                    Type      = TraktSyncItemType.Season,
                    Season    = new TraktSeason
                    {
                        Number = 1,
                        Ids    = new TraktSeasonIds
                        {
                            Trakt  = 61430U,
                            Tvdb   = 279121U,
                            Tmdb   = 60523U,
                            TvRage = 36939U
                        }
                    }
                },
                new TraktHistoryItem
                {
                    Id        = 1982347UL,
                    WatchedAt = WATCHED_AT,
                    Action    = TraktHistoryActionType.Checkin,
                    Type      = TraktSyncItemType.Season,
                    Season    = new TraktSeason
                    {
                        Number = 1,
                        Ids    = new TraktSeasonIds
                        {
                            Trakt  = 61430U,
                            Tvdb   = 279121U,
                            Tmdb   = 60523U,
                            TvRage = 36939U
                        }
                    }
                }
            };

            var    traktJsonWriter = new ArrayJsonWriter <ITraktHistoryItem>();
            string json            = await traktJsonWriter.WriteArrayAsync(traktHistoryItems);

            json.Should().Be(@"[{""id"":1982347," +
                             $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                             @"""action"":""checkin"",""type"":""season""," +
                             @"""season"":{""number"":1," +
                             @"""ids"":{""trakt"":61430,""tvdb"":279121,""tmdb"":60523,""tvrage"":36939}}}," +
                             @"{""id"":1982347," +
                             $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                             @"""action"":""checkin"",""type"":""season""," +
                             @"""season"":{""number"":1," +
                             @"""ids"":{""trakt"":61430,""tvdb"":279121,""tmdb"":60523,""tvrage"":36939}}}]");
        }
Exemple #5
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktSyncRatingsPostShow obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.RatedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_SHOW_PROPERTY_NAME_RATED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.RatedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Rating.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_SHOW_PROPERTY_NAME_RATING, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Rating, cancellationToken).ConfigureAwait(false);
            }

            if (!string.IsNullOrEmpty(obj.Title))
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_SHOW_PROPERTY_NAME_TITLE, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Title, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Year.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_SHOW_PROPERTY_NAME_YEAR, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Year, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Ids != null)
            {
                var showIdsObjectJsonWriter = new ShowIdsObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_SHOW_PROPERTY_NAME_IDS, cancellationToken).ConfigureAwait(false);

                await showIdsObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Ids, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Seasons != null)
            {
                var syncRatingsPostShowSeasonArrayJsonWriter = new ArrayJsonWriter <ITraktSyncRatingsPostShowSeason>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SYNC_RATINGS_POST_SHOW_PROPERTY_NAME_SEASONS, cancellationToken).ConfigureAwait(false);

                await syncRatingsPostShowSeasonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Seasons, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public async Task Test_RecommendationArrayJsonWriter_WriteArray_StringWriter_Empty()
        {
            IEnumerable <ITraktRecommendation> traktRecommendations = new List <TraktRecommendation>();

            using var stringWriter = new StringWriter();

            var    traktJsonWriter = new ArrayJsonWriter <ITraktRecommendation>();
            string json            = await traktJsonWriter.WriteArrayAsync(stringWriter, traktRecommendations);

            json.Should().Be("[]");
        }
Exemple #7
0
        public async Task Test_RatingArrayJsonWriter_WriteArray_StringWriter_Empty()
        {
            IEnumerable<ITraktRating> traktRating = new List<TraktRating>();

            using (var stringWriter = new StringWriter())
            {
                var traktJsonWriter = new ArrayJsonWriter<ITraktRating>();
                string json = await traktJsonWriter.WriteArrayAsync(stringWriter, traktRating);
                json.Should().Be("[]");
            }
        }
        public static Task <string> SerializeCollectionAsync <TObjectType>(IEnumerable <TObjectType> objects, CancellationToken cancellationToken = default)
        {
            if (objects == null)
            {
                throw new ArgumentNullException(nameof(objects), "objects must not be null");
            }

            IArrayJsonWriter <TObjectType> arrayJsonWriter = new ArrayJsonWriter <TObjectType>();

            return(arrayJsonWriter.WriteArrayAsync(objects, cancellationToken));
        }
Exemple #9
0
        public async Task Test_RatingArrayJsonWriter_WriteArray_JsonWriter_Complete()
        {
            IEnumerable <ITraktRating> traktRating = new List <ITraktRating>
            {
                new TraktRating
                {
                    Rating       = 7.4561f,
                    Votes        = 2453,
                    Distribution = new Dictionary <string, int>
                    {
                        ["1"]  = 1,
                        ["2"]  = 2,
                        ["3"]  = 3,
                        ["4"]  = 4,
                        ["5"]  = 5,
                        ["6"]  = 6,
                        ["7"]  = 7,
                        ["8"]  = 8,
                        ["9"]  = 9,
                        ["10"] = 10
                    }
                },
                new TraktRating
                {
                    Rating       = 7.4561f,
                    Votes        = 2453,
                    Distribution = new Dictionary <string, int>
                    {
                        ["1"]  = 1,
                        ["2"]  = 2,
                        ["3"]  = 3,
                        ["4"]  = 4,
                        ["5"]  = 5,
                        ["6"]  = 6,
                        ["7"]  = 7,
                        ["8"]  = 8,
                        ["9"]  = 9,
                        ["10"] = 10
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktRating>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktRating);

                    stringWriter.ToString().Should().Be(@"[{""rating"":7.4561,""votes"":2453," +
                                                        @"""distribution"":{""1"":1,""2"":2,""3"":3,""4"":4,""5"":5,""6"":6,""7"":7,""8"":8,""9"":9,""10"":10}}," +
                                                        @"{""rating"":7.4561,""votes"":2453," +
                                                        @"""distribution"":{""1"":1,""2"":2,""3"":3,""4"":4,""5"":5,""6"":6,""7"":7,""8"":8,""9"":9,""10"":10}}]");
                }
        }
Exemple #10
0
        public async Task Test_CollectionShowEpisodeArrayJsonWriter_WriteArray_StringWriter_Empty()
        {
            IEnumerable <ITraktCollectionShowEpisode> traktCollectionShowEpisodes = new List <TraktCollectionShowEpisode>();

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new ArrayJsonWriter <ITraktCollectionShowEpisode>();
                string json            = await traktJsonWriter.WriteArrayAsync(stringWriter, traktCollectionShowEpisodes);

                json.Should().Be("[]");
            }
        }
        public async Task Test_EpisodeWatchedProgressArrayJsonWriter_WriteArray_StringWriter_Empty()
        {
            IEnumerable <ITraktEpisodeWatchedProgress> traktEpisodeWatchedProgresss = new List <TraktEpisodeWatchedProgress>();

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new ArrayJsonWriter <ITraktEpisodeWatchedProgress>();
                string json            = await traktJsonWriter.WriteArrayAsync(stringWriter, traktEpisodeWatchedProgresss);

                json.Should().Be("[]");
            }
        }
        public async Task Test_UserCustomListsReorderPostResponseArrayJsonWriter_WriteArray_StringWriter_Empty()
        {
            IEnumerable <ITraktUserCustomListsReorderPostResponse> traktUserCustomListsReorderPostResponses = new List <TraktUserCustomListsReorderPostResponse>();

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new ArrayJsonWriter <ITraktUserCustomListsReorderPostResponse>();
                string json            = await traktJsonWriter.WriteArrayAsync(stringWriter, traktUserCustomListsReorderPostResponses);

                json.Should().Be("[]");
            }
        }
Exemple #13
0
        public async Task Test_CommentLikeArrayJsonWriter_WriteArray_JsonWriter_Complete()
        {
            IEnumerable <ITraktCommentLike> traktCommentLikes = new List <ITraktCommentLike>
            {
                new TraktCommentLike
                {
                    LikedAt = LIKED_AT,
                    User    = new TraktUser
                    {
                        Username  = "******",
                        IsPrivate = false,
                        Name      = "Sean Rudford",
                        IsVIP     = true,
                        IsVIP_EP  = true,
                        Ids       = new TraktUserIds
                        {
                            Slug = "sean"
                        }
                    }
                },
                new TraktCommentLike
                {
                    LikedAt = LIKED_AT,
                    User    = new TraktUser
                    {
                        Username  = "******",
                        IsPrivate = false,
                        Name      = "Sean Rudford",
                        IsVIP     = true,
                        IsVIP_EP  = true,
                        Ids       = new TraktUserIds
                        {
                            Slug = "sean"
                        }
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktCommentLike>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktCommentLikes);

                    stringWriter.ToString().Should().Be($"[{{\"liked_at\":\"{LIKED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""user"":{""username"":""sean"",""private"":false,""ids"":{""slug"":""sean""}," +
                                                        @"""name"":""Sean Rudford"",""vip"":true,""vip_ep"":true}}," +
                                                        $"{{\"liked_at\":\"{LIKED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""user"":{""username"":""sean"",""private"":false,""ids"":{""slug"":""sean""}," +
                                                        @"""name"":""Sean Rudford"",""vip"":true,""vip_ep"":true}}]");
                }
        }
        public async Task Test_GenreArrayJsonWriter_WriteArray_JsonWriter_Empty()
        {
            IEnumerable <ITraktGenre> traktGenres = new List <TraktGenre>();

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktGenre>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktGenres);

                    stringWriter.ToString().Should().Be("[]");
                }
        }
Exemple #15
0
        public async Task Test_UserCustomListsReorderPostArrayJsonWriter_WriteArray_JsonWriter_Empty()
        {
            IEnumerable <ITraktUserCustomListsReorderPost> traktUserCustomListsReorderPosts = new List <TraktUserCustomListsReorderPost>();

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktUserCustomListsReorderPost>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktUserCustomListsReorderPosts);

                    stringWriter.ToString().Should().Be("[]");
                }
        }
Exemple #16
0
        public async Task Test_EpisodeCollectionProgressArrayJsonWriter_WriteArray_JsonWriter_Empty()
        {
            IEnumerable <ITraktEpisodeCollectionProgress> traktEpisodeCollectionProgresss = new List <TraktEpisodeCollectionProgress>();

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktEpisodeCollectionProgress>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktEpisodeCollectionProgresss);

                    stringWriter.ToString().Should().Be("[]");
                }
        }
Exemple #17
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktWatchedShow obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Plays.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_PLAYS, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.Plays, cancellationToken).ConfigureAwait(false);
            }

            if (obj.LastWatchedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_LAST_WATCHED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.LastWatchedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.LastUpdatedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_LAST_UPDATED_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.LastUpdatedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.ResetAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_RESET_AT, cancellationToken).ConfigureAwait(false);

                await jsonWriter.WriteValueAsync(obj.ResetAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false);
            }

            if (obj.Show != null)
            {
                var showObjectJsonWriter = new ShowObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHOW, cancellationToken).ConfigureAwait(false);

                await showObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Show, cancellationToken).ConfigureAwait(false);
            }

            if (obj.WatchedSeasons != null)
            {
                var watchedShowSeasonArrayJsonWriter = new ArrayJsonWriter <ITraktWatchedShowSeason>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SEASONS, cancellationToken).ConfigureAwait(false);

                await watchedShowSeasonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.WatchedSeasons, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserCustomListItemsPostResponseNotFoundGroup obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Movies != null)
            {
                var notFoundMovieArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundMovie>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_CUSTOM_LIST_ITEMS_POST_RESPONSE_NOT_FOUND_GROUP_PROPERTY_NAME_MOVIES, cancellationToken).ConfigureAwait(false);

                await notFoundMovieArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Movies, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Shows != null)
            {
                var notFoundShowArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundShow>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_CUSTOM_LIST_ITEMS_POST_RESPONSE_NOT_FOUND_GROUP_PROPERTY_NAME_SHOWS, cancellationToken).ConfigureAwait(false);

                await notFoundShowArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Shows, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Seasons != null)
            {
                var notFoundSeasonArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundSeason>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_CUSTOM_LIST_ITEMS_POST_RESPONSE_NOT_FOUND_GROUP_PROPERTY_NAME_SEASONS, cancellationToken).ConfigureAwait(false);

                await notFoundSeasonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Seasons, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episodes != null)
            {
                var notFoundEpisodeArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundEpisode>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_CUSTOM_LIST_ITEMS_POST_RESPONSE_NOT_FOUND_GROUP_PROPERTY_NAME_EPISODES, cancellationToken).ConfigureAwait(false);

                await notFoundEpisodeArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Episodes, cancellationToken).ConfigureAwait(false);
            }

            if (obj.People != null)
            {
                var notFoundPersonArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundPerson>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_CUSTOM_LIST_ITEMS_POST_RESPONSE_NOT_FOUND_GROUP_PROPERTY_NAME_PEOPLE, cancellationToken).ConfigureAwait(false);

                await notFoundPersonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.People, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #19
0
        public async Task Test_NetworkArrayJsonWriter_WriteArray_Array_SingleObject()
        {
            IEnumerable<ITraktNetwork> traktNetworks = new List<ITraktNetwork>
            {
                new TraktNetwork
                {
                    Network = "network 1"
                }
            };

            var traktJsonWriter = new ArrayJsonWriter<ITraktNetwork>();
            string json = await traktJsonWriter.WriteArrayAsync(traktNetworks);
            json.Should().Be(@"[{""network"":""network 1""}]");
        }
Exemple #20
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktCertifications obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.US != null)
            {
                var certificationArrayJsonWriter = new ArrayJsonWriter <ITraktCertification>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_US, cancellationToken).ConfigureAwait(false);

                await certificationArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.US, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #21
0
        public async Task Test_GenreArrayJsonWriter_WriteArray_Array_SingleObject()
        {
            IEnumerable <ITraktGenre> traktGenres = new List <ITraktGenre>
            {
                new TraktGenre
                {
                    Name = "genre name 1",
                    Slug = "genre slug 1"
                }
            };

            var    traktJsonWriter = new ArrayJsonWriter <ITraktGenre>();
            string json            = await traktJsonWriter.WriteArrayAsync(traktGenres);

            json.Should().Be(@"[{""name"":""genre name 1"",""slug"":""genre slug 1""}]");
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserCustomListItemsPostResponseNotFoundGroup obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Movies != null)
            {
                var notFoundMovieArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundMovie>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_MOVIES, cancellationToken).ConfigureAwait(false);

                await notFoundMovieArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Movies, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Shows != null)
            {
                var notFoundShowArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundShow>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SHOWS, cancellationToken).ConfigureAwait(false);

                await notFoundShowArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Shows, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Seasons != null)
            {
                var notFoundSeasonArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundSeason>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SEASONS, cancellationToken).ConfigureAwait(false);

                await notFoundSeasonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Seasons, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episodes != null)
            {
                var notFoundEpisodeArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundEpisode>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_EPISODES, cancellationToken).ConfigureAwait(false);

                await notFoundEpisodeArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.Episodes, cancellationToken).ConfigureAwait(false);
            }

            if (obj.People != null)
            {
                var notFoundPersonArrayJsonWriter = new ArrayJsonWriter <ITraktPostResponseNotFoundPerson>();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_PEOPLE, cancellationToken).ConfigureAwait(false);

                await notFoundPersonArrayJsonWriter.WriteArrayAsync(jsonWriter, obj.People, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemple #23
0
        public async Task Test_CastMemberArrayJsonWriter_WriteArray_JsonWriter_Complete()
        {
            IEnumerable <ITraktCastMember> traktCastMembers = new List <ITraktCastMember>
            {
                new TraktCastMember
                {
                    Characters = new List <string>
                    {
                        "Character 1"
                    },
                    Person = new TraktPerson
                    {
                        Name = "Person 1",
                        Ids  = new TraktPersonIds
                        {
                            Slug = "person-1"
                        }
                    }
                },
                new TraktCastMember
                {
                    Characters = new List <string>
                    {
                        "Character 2"
                    },
                    Person = new TraktPerson
                    {
                        Name = "Person 2",
                        Ids  = new TraktPersonIds
                        {
                            Slug = "person-2"
                        }
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktCastMember>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktCastMembers);

                    stringWriter.ToString().Should().Be(@"[{""characters"":[""Character 1""],""person"":{""name"":""Person 1"",""ids"":{""trakt"":0,""slug"":""person-1""}}}," +
                                                        @"{""characters"":[""Character 2""],""person"":{""name"":""Person 2"",""ids"":{""trakt"":0,""slug"":""person-2""}}}]");
                }
        }
        public async Task Test_CertificationArrayJsonWriter_WriteArray_Array_SingleObject()
        {
            IEnumerable <ITraktCertification> traktCertifications = new List <ITraktCertification>
            {
                new TraktCertification
                {
                    Name        = "certification name 1",
                    Slug        = "certification slug 1",
                    Description = "certification description 1"
                }
            };

            var    traktJsonWriter = new ArrayJsonWriter <ITraktCertification>();
            string json            = await traktJsonWriter.WriteArrayAsync(traktCertifications);

            json.Should().Be(@"[{""name"":""certification name 1"",""slug"":""certification slug 1"",""description"":""certification description 1""}]");
        }
Exemple #25
0
        public async Task Test_CommentArrayJsonWriter_WriteArray_JsonWriter_SingleObject()
        {
            IEnumerable <ITraktComment> traktComments = new List <ITraktComment>
            {
                new TraktComment
                {
                    Id         = 76957U,
                    ParentId   = 1234U,
                    CreatedAt  = CREATED_UPDATED_AT,
                    UpdatedAt  = CREATED_UPDATED_AT,
                    Comment    = "I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse.",
                    Spoiler    = true,
                    Review     = true,
                    Replies    = 1,
                    Likes      = 2,
                    UserRating = 7.3f,
                    User       = new TraktUser
                    {
                        Username  = "******",
                        IsPrivate = false,
                        Name      = "Sean Rudford",
                        IsVIP     = true,
                        IsVIP_EP  = true,
                        Ids       = new TraktUserIds
                        {
                            Slug = "sean"
                        }
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktComment>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktComments);

                    stringWriter.ToString().Should().Be(@"[{""id"":76957,""parent_id"":1234," +
                                                        $"\"created_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        $"\"updated_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""comment"":""I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse.""," +
                                                        @"""spoiler"":true,""review"":true,""replies"":1,""likes"":2,""user_rating"":7.3," +
                                                        @"""user"":{""username"":""sean"",""private"":false,""ids"":{""slug"":""sean""}," +
                                                        @"""name"":""Sean Rudford"",""vip"":true,""vip_ep"":true}}]");
                }
        }
Exemple #26
0
        public async Task Test_EpisodeWatchedProgressArrayJsonWriter_WriteArray_Array_SingleObject()
        {
            IEnumerable <ITraktEpisodeWatchedProgress> traktEpisodeWatchedProgresss = new List <ITraktEpisodeWatchedProgress>
            {
                new TraktEpisodeWatchedProgress
                {
                    Number        = 1,
                    Completed     = true,
                    LastWatchedAt = LAST_WATCHED_AT
                }
            };

            var    traktJsonWriter = new ArrayJsonWriter <ITraktEpisodeWatchedProgress>();
            string json            = await traktJsonWriter.WriteArrayAsync(traktEpisodeWatchedProgresss);

            json.Should().Be($"[{{\"number\":1,\"completed\":true,\"last_watched_at\":\"{LAST_WATCHED_AT.ToTraktLongDateTimeString()}\"}}]");
        }
Exemple #27
0
        public async Task Test_EpisodeTranslationArrayJsonWriter_WriteArray_Array_SingleObject()
        {
            IEnumerable <ITraktEpisodeTranslation> traktEpisodeTranslations = new List <ITraktEpisodeTranslation>
            {
                new TraktEpisodeTranslation
                {
                    Title        = "title 1",
                    Overview     = "overview 1",
                    LanguageCode = "language code 1"
                }
            };

            var    traktJsonWriter = new ArrayJsonWriter <ITraktEpisodeTranslation>();
            string json            = await traktJsonWriter.WriteArrayAsync(traktEpisodeTranslations);

            json.Should().Be(@"[{""title"":""title 1"",""overview"":""overview 1"",""language"":""language code 1""}]");
        }
        public async Task Test_ImageArrayJsonWriter_WriteArray_StringWriter_SingleObject()
        {
            IEnumerable <ITraktImage> traktImage = new List <ITraktImage>
            {
                new TraktImage
                {
                    Full = "fullPath 1"
                }
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new ArrayJsonWriter <ITraktImage>();
                string json            = await traktJsonWriter.WriteArrayAsync(stringWriter, traktImage);

                json.Should().Be(@"[{""full"":""fullPath 1""}]");
            }
        }
        public async Task Test_NetworkArrayJsonWriter_WriteArray_StringWriter_SingleObject()
        {
            IEnumerable <ITraktNetwork> traktNetworks = new List <ITraktNetwork>
            {
                new TraktNetwork
                {
                    Name = "network 1"
                }
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new ArrayJsonWriter <ITraktNetwork>();
                string json            = await traktJsonWriter.WriteArrayAsync(stringWriter, traktNetworks);

                json.Should().Be(@"[{""name"":""network 1""}]");
            }
        }
Exemple #30
0
        public async Task Test_DeviceArrayJsonWriter_WriteArray_JsonWriter_Complete()
        {
            IEnumerable <ITraktDevice> traktDevices = new List <ITraktDevice>
            {
                new TraktDevice
                {
                    DeviceCode        = "mockDeviceCode1",
                    UserCode          = "mockUserCode1",
                    VerificationUrl   = "mockUrl1",
                    ExpiresInSeconds  = 7200,
                    IntervalInSeconds = 600
                },
                new TraktDevice
                {
                    DeviceCode        = "mockDeviceCode2",
                    UserCode          = "mockUserCode2",
                    VerificationUrl   = "mockUrl2",
                    ExpiresInSeconds  = 7200,
                    IntervalInSeconds = 600
                },
                new TraktDevice
                {
                    DeviceCode        = "mockDeviceCode3",
                    UserCode          = "mockUserCode3",
                    VerificationUrl   = "mockUrl3",
                    ExpiresInSeconds  = 7200,
                    IntervalInSeconds = 600
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new ArrayJsonWriter <ITraktDevice>();
                    await traktJsonWriter.WriteArrayAsync(jsonWriter, traktDevices);

                    stringWriter.ToString().Should().Be(@"[{""device_code"":""mockDeviceCode1"",""user_code"":""mockUserCode1""," +
                                                        @"""verification_url"":""mockUrl1"",""expires_in"":7200,""interval"":600}," +
                                                        @"{""device_code"":""mockDeviceCode2"",""user_code"":""mockUserCode2""," +
                                                        @"""verification_url"":""mockUrl2"",""expires_in"":7200,""interval"":600}," +
                                                        @"{""device_code"":""mockDeviceCode3"",""user_code"":""mockUserCode3""," +
                                                        @"""verification_url"":""mockUrl3"",""expires_in"":7200,""interval"":600}]");
                }
        }