public override async Task <ITraktShowCommentPost> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktShowCommentPost)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var sharingReader = new SharingObjectJsonReader();
                var showReader    = new ShowObjectJsonReader();
                ITraktShowCommentPost showCommentPost = new TraktShowCommentPost();

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

                    switch (propertyName)
                    {
                    case JsonProperties.COMMENT_POST_PROPERTY_NAME_COMMENT:
                        showCommentPost.Comment = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_POST_PROPERTY_NAME_SPOILER:
                    {
                        bool?value = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        if (value.HasValue)
                        {
                            showCommentPost.Spoiler = value.Value;
                        }

                        break;
                    }

                    case JsonProperties.COMMENT_POST_PROPERTY_NAME_SHARING:
                        showCommentPost.Sharing = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.SHOW_COMMENT_POST_PROPERTY_NAME_SHOW:
                        showCommentPost.Show = await showReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(showCommentPost);
            }

            return(await Task.FromResult(default(ITraktShowCommentPost)));
        }
        public void TestTraktShowCommentPostDefaultConstructor()
        {
            var showComment = new TraktShowCommentPost();

            showComment.Comment.Should().BeNullOrEmpty();
            showComment.Spoiler.Should().NotHaveValue();
            showComment.Sharing.Should().BeNull();
            showComment.Show.Should().BeNull();
        }
        public void TestTraktShowCommentPostWriteJson()
        {
            var comment = "this is a comment";
            var spoiler = true;
            var sharing = new TraktSharing {
                Facebook = false, Twitter = false, Tumblr = true
            };

            var showTitle   = "Breaking Bad";
            var showTraktId = 1U;
            var showSlug    = "breaking-bad";

            var show = new TraktShow
            {
                Title = showTitle,
                Ids   = new TraktShowIds {
                    Trakt = showTraktId, Slug = showSlug
                }
            };

            var showComment = new TraktShowCommentPost
            {
                Comment = comment,
                Spoiler = spoiler,
                Sharing = sharing,
                Show    = show
            };

            var strJson = JsonConvert.SerializeObject(showComment);

            strJson.Should().NotBeNullOrEmpty();

            var showCommentFromJson = JsonConvert.DeserializeObject <TraktShowCommentPost>(strJson);

            showCommentFromJson.Should().NotBeNull();
            showCommentFromJson.Comment.Should().Be(comment);
            showCommentFromJson.Spoiler.Should().Be(spoiler);
            showCommentFromJson.Sharing.Should().NotBeNull();
            showCommentFromJson.Sharing.Facebook.Should().BeFalse();
            showCommentFromJson.Sharing.Twitter.Should().BeFalse();
            showCommentFromJson.Sharing.Tumblr.Should().BeTrue();

            showCommentFromJson.Show.Should().NotBeNull();
            showCommentFromJson.Show.Title.Should().Be(showTitle);
            showCommentFromJson.Show.Ids.Should().NotBeNull();
            showCommentFromJson.Show.Ids.Trakt.Should().Be(showTraktId);
            showCommentFromJson.Show.Ids.Slug.Should().Be(showSlug);
        }
        public async Task Test_TraktCommentsModule_PostShowComment_Complete()
        {
            ITraktShowCommentPost showCommentPost = new TraktShowCommentPost
            {
                Show    = Show,
                Comment = COMMENT_TEXT,
                Spoiler = SPOILER,
                Sharing = SHARING
            };

            string postJson = await TestUtility.SerializeObject(showCommentPost);

            postJson.Should().NotBeNullOrEmpty();

            TraktClient client = TestUtility.GetOAuthMockClient(POST_SHOW_COMMENT_URI, postJson, COMMENT_POST_RESPONSE_JSON);
            TraktResponse <ITraktCommentPostResponse> response = await client.Comments.PostShowCommentAsync(Show, COMMENT_TEXT, SPOILER, SHARING);

            response.Should().NotBeNull();
            response.IsSuccess.Should().BeTrue();
            response.HasValue.Should().BeTrue();
            response.Value.Should().NotBeNull();

            ITraktCommentPostResponse responseValue = response.Value;

            responseValue.Id.Should().Be(COMMENT_ID);
            responseValue.ParentId.Should().Be(0U);
            responseValue.CreatedAt.Should().Be(DateTime.Parse("2014-08-04T06:46:01.996Z").ToUniversalTime());
            responseValue.Comment.Should().Be("Oh, I wasn't really listening.");
            responseValue.Spoiler.Should().BeFalse();
            responseValue.Review.Should().BeFalse();
            responseValue.Replies.Should().Be(0);
            responseValue.Likes.Should().Be(0);
            responseValue.UserRating.Should().NotHaveValue();
            responseValue.User.Should().NotBeNull();
            responseValue.User.Username.Should().Be("sean");
            responseValue.User.IsPrivate.Should().BeFalse();
            responseValue.User.Name.Should().Be("Sean Rudford");
            responseValue.User.IsVIP.Should().BeTrue();
            responseValue.User.IsVIP_EP.Should().BeFalse();
            responseValue.Sharing.Should().NotBeNull();
            responseValue.Sharing.Facebook.Should().BeTrue();
            responseValue.Sharing.Twitter.Should().BeTrue();
            responseValue.Sharing.Tumblr.Should().BeFalse();
            responseValue.Sharing.Medium.Should().BeTrue();
        }
Exemplo n.º 5
0
        public async Task Test_TraktCommentsModule_PostShowComment_ArgumentExceptions()
        {
            ITraktShow show = new TraktShow
            {
                Title = "Breaking Bad",
                Ids   = new TraktShowIds
                {
                    Trakt  = 1388,
                    Slug   = "breaking bad",
                    Tvdb   = 81189,
                    Imdb   = "tt0903747",
                    Tmdb   = 1396,
                    TvRage = 18164
                }
            };

            ITraktShowCommentPost showCommentPost = new TraktShowCommentPost
            {
                Show    = show,
                Comment = COMMENT_TEXT
            };

            string postJson = await TestUtility.SerializeObject(showCommentPost);

            postJson.Should().NotBeNullOrEmpty();

            TraktClient client = TestUtility.GetOAuthMockClient(POST_SHOW_COMMENT_URI, postJson, COMMENT_POST_RESPONSE_JSON);

            Func <Task <TraktResponse <ITraktCommentPostResponse> > > act = () => client.Comments.PostShowCommentAsync(null, COMMENT_TEXT);
            await act.Should().ThrowAsync <ArgumentNullException>();

            show.Title = string.Empty;

            act = () => client.Comments.PostShowCommentAsync(show, COMMENT_TEXT);
            await act.Should().ThrowAsync <ArgumentException>();

            show.Title = "Breaking Bad";
            show.Ids   = null;

            act = () => client.Comments.PostShowCommentAsync(show, COMMENT_TEXT);
            await act.Should().ThrowAsync <ArgumentNullException>();

            show.Ids = new TraktShowIds();

            act = () => client.Comments.PostShowCommentAsync(show, COMMENT_TEXT);
            await act.Should().ThrowAsync <ArgumentException>();

            show.Ids = new TraktShowIds
            {
                Trakt  = 1388,
                Slug   = "breaking bad",
                Tvdb   = 81189,
                Imdb   = "tt0903747",
                Tmdb   = 1396,
                TvRage = 18164
            };

            act = () => client.Comments.PostShowCommentAsync(show, null);
            await act.Should().ThrowAsync <ArgumentException>();

            act = () => client.Comments.PostShowCommentAsync(show, string.Empty);
            await act.Should().ThrowAsync <ArgumentException>();

            const string comment = "one two three four";

            act = () => client.Comments.PostShowCommentAsync(show, comment);
            await act.Should().ThrowAsync <ArgumentOutOfRangeException>();
        }