Exemplo n.º 1
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktRatingsItem obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.RatedAt.HasValue)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.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.PROPERTY_NAME_RATING, cancellationToken).ConfigureAwait(false);

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_TYPE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, 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.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episode != null)
            {
                var episodeObjectJsonWriter = new EpisodeObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_EPISODE, cancellationToken).ConfigureAwait(false);

                await episodeObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Episode, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 2
0
        public void Test_SeasonObjectJsonWriter_WriteObject_Object_Exceptions()
        {
            var traktJsonWriter          = new SeasonObjectJsonWriter();
            Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(ITraktSeason));

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
 public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var          traktJsonWriter = new SeasonObjectJsonWriter();
     ITraktSeason traktSeason     = new TraktSeason();
     Func <Task>  action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktSeason);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktCommentItem obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_ITEM_PROPERTY_NAME_TYPE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_ITEM_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

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

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

            if (obj.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_ITEM_PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episode != null)
            {
                var episodeObjectJsonWriter = new EpisodeObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_ITEM_PROPERTY_NAME_EPISODE, cancellationToken).ConfigureAwait(false);

                await episodeObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Episode, cancellationToken).ConfigureAwait(false);
            }

            if (obj.List != null)
            {
                var listObjectJsonWriter = new ListObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_ITEM_PROPERTY_NAME_LIST, cancellationToken).ConfigureAwait(false);

                await listObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.List, cancellationToken).ConfigureAwait(false);
            }

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

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

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

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COLLECTION_MOVIE_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COLLECTION_MOVIE_PROPERTY_NAME_METADATA, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

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

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

            if (obj.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COLLECTION_MOVIE_PROPERTY_NAME_METADATA, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episode != null)
            {
                var episodeObjectJsonWriter = new EpisodeObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.COLLECTION_MOVIE_PROPERTY_NAME_METADATA, cancellationToken).ConfigureAwait(false);

                await episodeObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Episode, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        protected override async Task WriteCommentObjectAsync(JsonTextWriter jsonWriter, ITraktSeasonCommentPost obj, CancellationToken cancellationToken = default)
        {
            if (obj.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.SEASON_COMMENT_POST_PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }
        }
Exemplo n.º 7
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Rating_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Rating = 8.7654f
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""rating"":8.7654}");
        }
Exemplo n.º 8
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Votes_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Votes = 9765
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""votes"":9765}");
        }
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_UpdatedAt_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                UpdatedAt = UPDATED_AT
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be($"{{\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"}}");
        }
Exemplo n.º 10
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Network_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Network = "Season 1 Network"
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""network"":""Season 1 Network""}");
        }
Exemplo n.º 11
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Title_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Title = "Season 1"
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""title"":""Season 1""}");
        }
Exemplo n.º 12
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Overview_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Overview = "Season 1 Overview"
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""overview"":""Season 1 Overview""}");
        }
Exemplo n.º 13
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_FirstAired_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                FirstAired = FIRST_AIRED
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be($"{{\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"}}");
        }
Exemplo n.º 14
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_TotalEpisodesCount_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                TotalEpisodesCount = 24
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""episode_count"":24}");
        }
Exemplo n.º 15
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_AiredEpisodesCount_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                AiredEpisodesCount = 12
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""aired_episodes"":12}");
        }
Exemplo n.º 16
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Number_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Number = 1
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""number"":1}");
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserHiddenItem obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

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

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

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_HIDDEN_ITEM_PROPERTY_NAME_TYPE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_HIDDEN_ITEM_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

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

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

            if (obj.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_HIDDEN_ITEM_PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 18
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_AiredEpisodesCount_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                AiredEpisodesCount = 12
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be(@"{""aired_episodes"":12}");
                }
        }
Exemplo n.º 19
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Title_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Title = "Season 1"
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be(@"{""title"":""Season 1""}");
                }
        }
Exemplo n.º 20
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Number_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Number = 1
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be(@"{""number"":1}");
                }
        }
Exemplo n.º 21
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_FirstAired_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                FirstAired = FIRST_AIRED
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be($"{{\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"}}");
                }
        }
Exemplo n.º 22
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_UpdatedAt_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                UpdatedAt = UPDATED_AT
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be($"{{\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"}}");
                }
        }
Exemplo n.º 23
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Rating_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Rating = 8.7654f
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be(@"{""rating"":8.7654}");
                }
        }
Exemplo n.º 24
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Ids_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Ids = new TraktSeasonIds
                {
                    Trakt  = 123,
                    Tvdb   = 456,
                    Tmdb   = 789,
                    TvRage = 101
                }
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""ids"":{""trakt"":123,""tvdb"":456,""tmdb"":789,""tvrage"":101}}");
        }
Exemplo n.º 25
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Ids_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Ids = new TraktSeasonIds
                {
                    Trakt  = 123,
                    Tvdb   = 456,
                    Tmdb   = 789,
                    TvRage = 101
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be(@"{""ids"":{""trakt"":123,""tvdb"":456,""tmdb"":789,""tvrage"":101}}");
                }
        }
Exemplo n.º 26
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktHistoryItem obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

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

            await jsonWriter.WritePropertyNameAsync(JsonProperties.HISTORY_ITEM_PROPERTY_NAME_ID, cancellationToken).ConfigureAwait(false);

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

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

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

            if (obj.Action != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.HISTORY_ITEM_PROPERTY_NAME_ACTION, cancellationToken).ConfigureAwait(false);

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.HISTORY_ITEM_PROPERTY_NAME_TYPE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.HISTORY_ITEM_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

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

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

            if (obj.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.HISTORY_ITEM_PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episode != null)
            {
                var episodeObjectJsonWriter = new EpisodeObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.HISTORY_ITEM_PROPERTY_NAME_EPISODE, cancellationToken).ConfigureAwait(false);

                await episodeObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Episode, cancellationToken).ConfigureAwait(false);
            }

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

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

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

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

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

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.LIST_ITEM_PROPERTY_NAME_TYPE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.LIST_ITEM_PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, cancellationToken).ConfigureAwait(false);
            }

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

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

            if (obj.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.LIST_ITEM_PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episode != null)
            {
                var episodeObjectJsonWriter = new EpisodeObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.LIST_ITEM_PROPERTY_NAME_EPISODE, cancellationToken).ConfigureAwait(false);

                await episodeObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Episode, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Person != null)
            {
                var personObjectJsonWriter = new PersonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.LIST_ITEM_PROPERTY_NAME_PERSON, cancellationToken).ConfigureAwait(false);

                await personObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Person, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserComment obj, CancellationToken cancellationToken = default)
        {
            CheckJsonTextWriter(jsonWriter);
            await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false);

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_TYPE, cancellationToken).ConfigureAwait(false);

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

            if (obj.Comment != null)
            {
                var commentObjectJsonWriter = new CommentObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_COMMENT, cancellationToken).ConfigureAwait(false);

                await commentObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Comment, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Movie != null)
            {
                var movieObjectJsonWriter = new MovieObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_MOVIE, cancellationToken).ConfigureAwait(false);

                await movieObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Movie, 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.Season != null)
            {
                var seasonObjectJsonWriter = new SeasonObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_SEASON, cancellationToken).ConfigureAwait(false);

                await seasonObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Season, cancellationToken).ConfigureAwait(false);
            }

            if (obj.Episode != null)
            {
                var episodeObjectJsonWriter = new EpisodeObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_EPISODE, cancellationToken).ConfigureAwait(false);

                await episodeObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.Episode, cancellationToken).ConfigureAwait(false);
            }

            if (obj.List != null)
            {
                var listObjectJsonWriter = new ListObjectJsonWriter();
                await jsonWriter.WritePropertyNameAsync(JsonProperties.PROPERTY_NAME_LIST, cancellationToken).ConfigureAwait(false);

                await listObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.List, cancellationToken).ConfigureAwait(false);
            }

            await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 29
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Episodes_Property()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Episodes = new List <ITraktEpisode>
                {
                    new TraktEpisode
                    {
                        SeasonNumber = 1,
                        Number       = 1,
                        Title        = "title 1",
                        Ids          = new TraktEpisodeIds
                        {
                            Trakt  = 123456,
                            Tvdb   = 234567,
                            Imdb   = "345678",
                            Tmdb   = 456789,
                            TvRage = 567890
                        },
                        NumberAbsolute = 1,
                        Overview       = "overview 1",
                        Runtime        = 60,
                        Rating         = 8.45672f,
                        Votes          = 8925,
                        FirstAired     = FIRST_AIRED,
                        UpdatedAt      = UPDATED_AT,
                        AvailableTranslationLanguageCodes = new List <string>
                        {
                            "en",
                            "de"
                        },
                        Translations = new List <TraktEpisodeTranslation>
                        {
                            new TraktEpisodeTranslation
                            {
                                Title        = "german title 1",
                                Overview     = "german overview 1",
                                LanguageCode = "de"
                            },
                            new TraktEpisodeTranslation
                            {
                                Title        = "english title 1",
                                Overview     = "english overview 1",
                                LanguageCode = "en"
                            }
                        }
                    },
                    new TraktEpisode
                    {
                        SeasonNumber = 1,
                        Number       = 2,
                        Title        = "title 2",
                        Ids          = new TraktEpisodeIds
                        {
                            Trakt  = 123456,
                            Tvdb   = 234567,
                            Imdb   = "345678",
                            Tmdb   = 456789,
                            TvRage = 567890
                        },
                        NumberAbsolute = 2,
                        Overview       = "overview 2",
                        Runtime        = 60,
                        Rating         = 8.45672f,
                        Votes          = 8925,
                        FirstAired     = FIRST_AIRED,
                        UpdatedAt      = UPDATED_AT,
                        AvailableTranslationLanguageCodes = new List <string>
                        {
                            "en",
                            "de"
                        },
                        Translations = new List <TraktEpisodeTranslation>
                        {
                            new TraktEpisodeTranslation
                            {
                                Title        = "german title 2",
                                Overview     = "german overview 2",
                                LanguageCode = "de"
                            },
                            new TraktEpisodeTranslation
                            {
                                Title        = "english title 2",
                                Overview     = "english overview 2",
                                LanguageCode = "en"
                            }
                        }
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new SeasonObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason);

                    stringWriter.ToString().Should().Be(@"{""episodes"":[" +
                                                        @"{""season"":1,""number"":1,""title"":""title 1""," +
                                                        @"""ids"":{""trakt"":123456,""tvdb"":234567,""imdb"":""345678"",""tmdb"":456789,""tvrage"":567890}," +
                                                        @"""number_abs"":1,""overview"":""overview 1""," +
                                                        @"""runtime"":60,""rating"":8.45672,""votes"":8925," +
                                                        $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," +
                                                        $"\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""available_translations"":[""en"",""de""]," +
                                                        @"""translations"":[{""title"":""german title 1"",""overview"":""german overview 1"",""language"":""de""}," +
                                                        @"{""title"":""english title 1"",""overview"":""english overview 1"",""language"":""en""}]}," +
                                                        @"{""season"":1,""number"":2,""title"":""title 2""," +
                                                        @"""ids"":{""trakt"":123456,""tvdb"":234567,""imdb"":""345678"",""tmdb"":456789,""tvrage"":567890}," +
                                                        @"""number_abs"":2,""overview"":""overview 2""," +
                                                        @"""runtime"":60,""rating"":8.45672,""votes"":8925," +
                                                        $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," +
                                                        $"\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""available_translations"":[""en"",""de""]," +
                                                        @"""translations"":[{""title"":""german title 2"",""overview"":""german overview 2"",""language"":""de""}," +
                                                        @"{""title"":""english title 2"",""overview"":""english overview 2"",""language"":""en""}]}" +
                                                        "]}");
                }
        }
Exemplo n.º 30
0
        public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Complete()
        {
            ITraktSeason traktSeason = new TraktSeason
            {
                Number = 1,
                Title  = "Season 1",
                Ids    = new TraktSeasonIds
                {
                    Trakt  = 123,
                    Tvdb   = 456,
                    Tmdb   = 789,
                    TvRage = 101
                },
                Rating             = 8.7654f,
                Votes              = 9765,
                TotalEpisodesCount = 24,
                AiredEpisodesCount = 12,
                Overview           = "Season 1 Overview",
                FirstAired         = FIRST_AIRED,
                Network            = "Season 1 Network",
                Episodes           = new List <ITraktEpisode>
                {
                    new TraktEpisode
                    {
                        SeasonNumber = 1,
                        Number       = 1,
                        Title        = "title 1",
                        Ids          = new TraktEpisodeIds
                        {
                            Trakt  = 123456,
                            Tvdb   = 234567,
                            Imdb   = "345678",
                            Tmdb   = 456789,
                            TvRage = 567890
                        },
                        NumberAbsolute = 1,
                        Overview       = "overview 1",
                        Runtime        = 60,
                        Rating         = 8.45672f,
                        Votes          = 8925,
                        FirstAired     = FIRST_AIRED,
                        UpdatedAt      = UPDATED_AT,
                        AvailableTranslationLanguageCodes = new List <string>
                        {
                            "en",
                            "de"
                        },
                        Translations = new List <TraktEpisodeTranslation>
                        {
                            new TraktEpisodeTranslation
                            {
                                Title        = "german title 1",
                                Overview     = "german overview 1",
                                LanguageCode = "de"
                            },
                            new TraktEpisodeTranslation
                            {
                                Title        = "english title 1",
                                Overview     = "english overview 1",
                                LanguageCode = "en"
                            }
                        }
                    },
                    new TraktEpisode
                    {
                        SeasonNumber = 1,
                        Number       = 2,
                        Title        = "title 2",
                        Ids          = new TraktEpisodeIds
                        {
                            Trakt  = 123456,
                            Tvdb   = 234567,
                            Imdb   = "345678",
                            Tmdb   = 456789,
                            TvRage = 567890
                        },
                        NumberAbsolute = 2,
                        Overview       = "overview 2",
                        Runtime        = 60,
                        Rating         = 8.45672f,
                        Votes          = 8925,
                        FirstAired     = FIRST_AIRED,
                        UpdatedAt      = UPDATED_AT,
                        AvailableTranslationLanguageCodes = new List <string>
                        {
                            "en",
                            "de"
                        },
                        Translations = new List <TraktEpisodeTranslation>
                        {
                            new TraktEpisodeTranslation
                            {
                                Title        = "german title 2",
                                Overview     = "german overview 2",
                                LanguageCode = "de"
                            },
                            new TraktEpisodeTranslation
                            {
                                Title        = "english title 2",
                                Overview     = "english overview 2",
                                LanguageCode = "en"
                            }
                        }
                    }
                }
            };

            var    traktJsonWriter = new SeasonObjectJsonWriter();
            string json            = await traktJsonWriter.WriteObjectAsync(traktSeason);

            json.Should().Be(@"{""number"":1,""title"":""Season 1""," +
                             @"""ids"":{""trakt"":123,""tvdb"":456,""tmdb"":789,""tvrage"":101}," +
                             @"""rating"":8.7654,""votes"":9765,""episode_count"":24,""aired_episodes"":12," +
                             @"""overview"":""Season 1 Overview""," +
                             $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," +
                             @"""network"":""Season 1 Network""," +
                             @"""episodes"":[" +
                             @"{""season"":1,""number"":1,""title"":""title 1""," +
                             @"""ids"":{""trakt"":123456,""tvdb"":234567,""imdb"":""345678"",""tmdb"":456789,""tvrage"":567890}," +
                             @"""number_abs"":1,""overview"":""overview 1""," +
                             @"""runtime"":60,""rating"":8.45672,""votes"":8925," +
                             $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," +
                             $"\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                             @"""available_translations"":[""en"",""de""]," +
                             @"""translations"":[{""title"":""german title 1"",""overview"":""german overview 1"",""language"":""de""}," +
                             @"{""title"":""english title 1"",""overview"":""english overview 1"",""language"":""en""}]}," +
                             @"{""season"":1,""number"":2,""title"":""title 2""," +
                             @"""ids"":{""trakt"":123456,""tvdb"":234567,""imdb"":""345678"",""tmdb"":456789,""tvrage"":567890}," +
                             @"""number_abs"":2,""overview"":""overview 2""," +
                             @"""runtime"":60,""rating"":8.45672,""votes"":8925," +
                             $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," +
                             $"\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                             @"""available_translations"":[""en"",""de""]," +
                             @"""translations"":[{""title"":""german title 2"",""overview"":""german overview 2"",""language"":""de""}," +
                             @"{""title"":""english title 2"",""overview"":""english overview 2"",""language"":""en""}]}" +
                             "]}");
        }