Пример #1
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Not_Valid_5()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_NOT_VALID_5);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(76957U);
            traktComment.ParentId.Should().Be(1234U);
            traktComment.CreatedAt.Should().Be(DateTime.Parse("2016-04-01T12:44:40Z").ToUniversalTime());
            traktComment.UpdatedAt.Should().Be(DateTime.Parse("2016-04-03T08:23:38Z").ToUniversalTime());
            traktComment.Comment.Should().BeNull();
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().Be(1);
            traktComment.Likes.Should().Be(2);
            traktComment.UserRating.Should().Be(7.3f);
            traktComment.User.Should().NotBeNull();
            traktComment.User.Username.Should().Be("sean");
            traktComment.User.IsPrivate.Should().BeFalse();
            traktComment.User.Name.Should().Be("Sean Rudford");
            traktComment.User.IsVIP.Should().BeTrue();
            traktComment.User.IsVIP_EP.Should().BeTrue();
            traktComment.User.Ids.Should().NotBeNull();
            traktComment.User.Ids.Slug.Should().Be("sean");
        }
Пример #2
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Incomplete_3()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_INCOMPLETE_3);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(76957U);
            traktComment.ParentId.Should().Be(1234U);
            traktComment.CreatedAt.Should().Be(default(DateTime));
            traktComment.UpdatedAt.Should().Be(DateTime.Parse("2016-04-03T08:23:38Z").ToUniversalTime());
            traktComment.Comment.Should().Be("I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse.");
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().Be(1);
            traktComment.Likes.Should().Be(2);
            traktComment.UserRating.Should().Be(7.3f);
            traktComment.User.Should().NotBeNull();
            traktComment.User.Username.Should().Be("sean");
            traktComment.User.IsPrivate.Should().BeFalse();
            traktComment.User.Name.Should().Be("Sean Rudford");
            traktComment.User.IsVIP.Should().BeTrue();
            traktComment.User.IsVIP_EP.Should().BeTrue();
            traktComment.User.Ids.Should().NotBeNull();
            traktComment.User.Ids.Slug.Should().Be("sean");
        }
Пример #3
0
        public void Test_CommentObjectJsonReader_ReadObject_From_Json_String_Null()
        {
            var jsonReader = new CommentObjectJsonReader();
            Func <Task <ITraktComment> > traktComment = () => jsonReader.ReadObjectAsync(default(string));

            traktComment.Should().Throw <ArgumentNullException>();
        }
Пример #4
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Incomplete_22()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_INCOMPLETE_22);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(0U);
            traktComment.ParentId.Should().BeNull();
            traktComment.CreatedAt.Should().Be(default(DateTime));
            traktComment.UpdatedAt.Should().BeNull();
            traktComment.Comment.Should().BeNull();
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().BeNull();
            traktComment.Likes.Should().BeNull();
            traktComment.UserRating.Should().BeNull();
            traktComment.User.Should().NotBeNull();
            traktComment.User.Username.Should().Be("sean");
            traktComment.User.IsPrivate.Should().BeFalse();
            traktComment.User.Name.Should().Be("Sean Rudford");
            traktComment.User.IsVIP.Should().BeTrue();
            traktComment.User.IsVIP_EP.Should().BeTrue();
            traktComment.User.Ids.Should().NotBeNull();
            traktComment.User.Ids.Slug.Should().Be("sean");
        }
Пример #5
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Empty()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(string.Empty);

            traktComment.Should().BeNull();
        }
Пример #6
0
        public override async Task <ITraktUserLikeItem> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktUserLikeItem)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var commentReader = new CommentObjectJsonReader();
                var listReader    = new ListObjectJsonReader();
                ITraktUserLikeItem traktUserLikeItem = new TraktUserLikeItem();

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

                    switch (propertyName)
                    {
                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_LIKED_AT:
                    {
                        var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktUserLikeItem.LikedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_TYPE:
                        traktUserLikeItem.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktUserLikeType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_COMMENT:
                        traktUserLikeItem.Comment = await commentReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_LIST:
                        traktUserLikeItem.List = await listReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktUserLikeItem);
            }

            return(await Task.FromResult(default(ITraktUserLikeItem)));
        }
Пример #7
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Not_Valid_12()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_NOT_VALID_12);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(0U);
            traktComment.ParentId.Should().BeNull();
            traktComment.CreatedAt.Should().Be(default(DateTime));
            traktComment.UpdatedAt.Should().BeNull();
            traktComment.Comment.Should().BeNull();
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().BeNull();
            traktComment.Likes.Should().BeNull();
            traktComment.UserRating.Should().BeNull();
            traktComment.User.Should().BeNull();
        }
Пример #8
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Not_Valid_11()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_NOT_VALID_11);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(76957U);
            traktComment.ParentId.Should().Be(1234U);
            traktComment.CreatedAt.Should().Be(DateTime.Parse("2016-04-01T12:44:40Z").ToUniversalTime());
            traktComment.UpdatedAt.Should().Be(DateTime.Parse("2016-04-03T08:23:38Z").ToUniversalTime());
            traktComment.Comment.Should().Be("I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse.");
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().Be(1);
            traktComment.Likes.Should().Be(2);
            traktComment.UserRating.Should().Be(7.3f);
            traktComment.User.Should().BeNull();
        }
Пример #9
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Incomplete_21()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_INCOMPLETE_21);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(0U);
            traktComment.ParentId.Should().BeNull();
            traktComment.CreatedAt.Should().Be(default(DateTime));
            traktComment.UpdatedAt.Should().BeNull();
            traktComment.Comment.Should().BeNull();
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().BeNull();
            traktComment.Likes.Should().BeNull();
            traktComment.UserRating.Should().Be(7.3f);
            traktComment.User.Should().BeNull();
        }
Пример #10
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Incomplete_16()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_INCOMPLETE_16);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(0U);
            traktComment.ParentId.Should().BeNull();
            traktComment.CreatedAt.Should().Be(default(DateTime));
            traktComment.UpdatedAt.Should().BeNull();
            traktComment.Comment.Should().Be("I hate they made The flash a kids show. Could else be much better. And with a better flash offcourse.");
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().BeNull();
            traktComment.Likes.Should().BeNull();
            traktComment.UserRating.Should().BeNull();
            traktComment.User.Should().BeNull();
        }
Пример #11
0
        public async Task Test_CommentObjectJsonReader_ReadObject_From_Json_String_Incomplete_15()
        {
            var jsonReader = new CommentObjectJsonReader();

            var traktComment = await jsonReader.ReadObjectAsync(JSON_INCOMPLETE_15);

            traktComment.Should().NotBeNull();
            traktComment.Id.Should().Be(0U);
            traktComment.ParentId.Should().BeNull();
            traktComment.CreatedAt.Should().Be(default(DateTime));
            traktComment.UpdatedAt.Should().Be(DateTime.Parse("2016-04-03T08:23:38Z").ToUniversalTime());
            traktComment.Comment.Should().BeNull();
            traktComment.Spoiler.Should().BeFalse();
            traktComment.Review.Should().BeFalse();
            traktComment.Replies.Should().BeNull();
            traktComment.Likes.Should().BeNull();
            traktComment.UserRating.Should().BeNull();
            traktComment.User.Should().BeNull();
        }
Пример #12
0
        public override async Task <ITraktUserComment> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktUserComment)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var commentReader = new CommentObjectJsonReader();
                var movieReader   = new MovieObjectJsonReader();
                var showReader    = new ShowObjectJsonReader();
                var seasonReader  = new SeasonObjectJsonReader();
                var episodeReader = new EpisodeObjectJsonReader();
                var listReader    = new ListObjectJsonReader();
                ITraktUserComment traktUserComment = new TraktUserComment();

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

                    switch (propertyName)
                    {
                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_TYPE:
                        traktUserComment.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktObjectType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_COMMENT:
                        traktUserComment.Comment = await commentReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_MOVIE:
                        traktUserComment.Movie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_SHOW:
                        traktUserComment.Show = await showReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_SEASON:
                        traktUserComment.Season = await seasonReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_EPISODE:
                        traktUserComment.Episode = await episodeReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_LIST:
                        traktUserComment.List = await listReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktUserComment);
            }

            return(await Task.FromResult(default(ITraktUserComment)));
        }