예제 #1
0
        public void TestTraktCommentPostResponseDefaultConstructor()
        {
            var commentPostResponse = new TraktCommentPostResponse();

            commentPostResponse.Id.Should().Be(0);
            commentPostResponse.ParentId.Should().BeNull();
            commentPostResponse.CreatedAt.Should().Be(DateTime.MinValue);
            commentPostResponse.Comment.Should().BeNullOrEmpty();
            commentPostResponse.Spoiler.Should().BeFalse();
            commentPostResponse.Review.Should().BeFalse();
            commentPostResponse.Replies.Should().NotHaveValue();
            commentPostResponse.Likes.Should().NotHaveValue();
            commentPostResponse.UserRating.Should().NotHaveValue();
            commentPostResponse.User.Should().BeNull();
            commentPostResponse.Sharing.Should().BeNull();
        }
        public void Test_TraktCommentPostResponse_Default_Constructor()
        {
            var traktCommentPostResponse = new TraktCommentPostResponse();

            traktCommentPostResponse.Id.Should().Be(0U);
            traktCommentPostResponse.ParentId.Should().BeNull();
            traktCommentPostResponse.CreatedAt.Should().Be(default(DateTime));
            traktCommentPostResponse.UpdatedAt.Should().BeNull();
            traktCommentPostResponse.Comment.Should().BeNull();
            traktCommentPostResponse.Spoiler.Should().BeFalse();
            traktCommentPostResponse.Review.Should().BeFalse();
            traktCommentPostResponse.Replies.Should().BeNull();
            traktCommentPostResponse.Likes.Should().BeNull();
            traktCommentPostResponse.UserRating.Should().BeNull();
            traktCommentPostResponse.User.Should().BeNull();
            traktCommentPostResponse.Sharing.Should().BeNull();
        }
예제 #3
0
        public override async Task <ITraktCommentPostResponse> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktCommentPostResponse)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var userReader    = new UserObjectJsonReader();
                var sharingReader = new SharingObjectJsonReader();
                ITraktCommentPostResponse traktCommentPostResponse = new TraktCommentPostResponse();

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

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

                        if (value.First)
                        {
                            traktCommentPostResponse.Id = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.COMMENT_PROPERTY_NAME_PARENT_ID:
                    {
                        var value = await JsonReaderHelper.ReadUnsignedIntegerValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktCommentPostResponse.ParentId = value.Second;
                        }

                        break;
                    }

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

                        if (value.First)
                        {
                            traktCommentPostResponse.CreatedAt = value.Second;
                        }

                        break;
                    }

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

                        if (value.First)
                        {
                            traktCommentPostResponse.UpdatedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.COMMENT_PROPERTY_NAME_COMMENT:
                        traktCommentPostResponse.Comment = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_PROPERTY_NAME_SPOILER:
                        traktCommentPostResponse.Spoiler = (bool)await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_PROPERTY_NAME_REVIEW:
                        traktCommentPostResponse.Review = (bool)await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_PROPERTY_NAME_REPLIES:
                        traktCommentPostResponse.Replies = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_PROPERTY_NAME_LIKES:
                        traktCommentPostResponse.Likes = await jsonReader.ReadAsInt32Async(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_PROPERTY_NAME_USER_RATING:
                    {
                        var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktCommentPostResponse.UserRating = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.COMMENT_PROPERTY_NAME_USER:
                        traktCommentPostResponse.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.COMMENT_POST_RESPONSE_PROPERTY_NAME_SHARING:
                        traktCommentPostResponse.Sharing = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktCommentPostResponse);
            }

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