public async Task Test_CommentObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var                   traktJsonWriter = new CommentObjectJsonWriter();
     ITraktComment         traktComment    = new TraktComment();
     Func <Task <string> > action          = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktComment);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public async Task Test_CommentObjectJsonWriter_WriteObject_StringWriter_Only_User_Property()
        {
            ITraktComment traktComment = new TraktComment
            {
                User = new TraktUser
                {
                    Username  = "******",
                    IsPrivate = false,
                    Name      = "Sean Rudford",
                    IsVIP     = true,
                    IsVIP_EP  = true,
                    Ids       = new TraktUserIds
                    {
                        Slug = "sean"
                    }
                }
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new CommentObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktComment);

                json.Should().Be(@"{""id"":0,""created_at"":""0001-01-01T00:00:00.000Z""," +
                                 @"""spoiler"":false,""review"":false," +
                                 @"""user"":{""username"":""sean"",""private"":false,""ids"":{""slug"":""sean""}," +
                                 @"""name"":""Sean Rudford"",""vip"":true,""vip_ep"":true}}");
            }
        }
Exemplo n.º 3
0
        public void Test_CommentObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var           traktJsonWriter = new CommentObjectJsonWriter();
            ITraktComment traktComment    = new TraktComment();
            Func <Task>   action          = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktComment);

            action.Should().Throw <ArgumentNullException>();
        }
        public async Task Test_CommentObjectJsonWriter_WriteObject_StringWriter_Empty()
        {
            ITraktComment traktComment = new TraktComment();

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new CommentObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktComment);

                json.Should().Be(@"{""id"":0,""created_at"":""0001-01-01T00:00:00.000Z""," +
                                 @"""spoiler"":false,""review"":false}");
            }
        }
        public async Task Test_CommentObjectJsonWriter_WriteObject_StringWriter_Only_UpdatedAt_Property()
        {
            ITraktComment traktComment = new TraktComment
            {
                UpdatedAt = CREATED_UPDATED_AT
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new CommentObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktComment);

                json.Should().Be(@"{""id"":0,""created_at"":""0001-01-01T00:00:00.000Z""," +
                                 $"\"updated_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                 @"""spoiler"":false,""review"":false}");
            }
        }
        public async Task Test_CommentObjectJsonWriter_WriteObject_StringWriter_Only_Comment_Property()
        {
            ITraktComment traktComment = new TraktComment
            {
                Comment = "I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse."
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new CommentObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktComment);

                json.Should().Be(@"{""id"":0,""created_at"":""0001-01-01T00:00:00.000Z""," +
                                 @"""comment"":""I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse.""," +
                                 @"""spoiler"":false,""review"":false}");
            }
        }
Exemplo n.º 7
0
        public async Task Test_CommentObjectJsonWriter_WriteObject_JsonWriter_Only_ParentId_Property()
        {
            ITraktComment traktComment = new TraktComment
            {
                ParentId = 1234U
            };

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

                    stringWriter.ToString().Should().Be(@"{""id"":0,""parent_id"":1234,""created_at"":""0001-01-01T00:00:00.000Z""," +
                                                        @"""spoiler"":false,""review"":false}");
                }
        }
Exemplo n.º 8
0
        public async Task Test_CommentObjectJsonWriter_WriteObject_JsonWriter_Only_CreatedAt_Property()
        {
            ITraktComment traktComment = new TraktComment
            {
                CreatedAt = CREATED_UPDATED_AT
            };

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

                    stringWriter.ToString().Should().Be(@"{""id"":0," +
                                                        $"\"created_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""spoiler"":false,""review"":false}");
                }
        }
Exemplo n.º 9
0
        public async Task Test_CommentObjectJsonWriter_WriteObject_JsonWriter_Complete()
        {
            ITraktComment traktComment = 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 CommentObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktComment);

                    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}}");
                }
        }
Exemplo n.º 10
0
        public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktUserLikeItem obj, CancellationToken cancellationToken = default)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

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

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

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

            if (obj.Type != null)
            {
                await jsonWriter.WritePropertyNameAsync(JsonProperties.USER_LIKE_ITEM_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.USER_LIKE_ITEM_PROPERTY_NAME_COMMENT, cancellationToken).ConfigureAwait(false);

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

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

                await listObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.List, 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);
        }