public override async Task <ITraktListCommentPost> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { if (jsonReader == null) { return(await Task.FromResult(default(ITraktListCommentPost))); } if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var sharingReader = new SharingObjectJsonReader(); var listReader = new ListObjectJsonReader(); ITraktListCommentPost listCommentPost = new TraktListCommentPost(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.COMMENT_POST_PROPERTY_NAME_COMMENT: listCommentPost.Comment = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.COMMENT_POST_PROPERTY_NAME_SPOILER: { bool?value = await jsonReader.ReadAsBooleanAsync(cancellationToken); if (value.HasValue) { listCommentPost.Spoiler = value.Value; } break; } case JsonProperties.COMMENT_POST_PROPERTY_NAME_SHARING: listCommentPost.Sharing = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken); break; case JsonProperties.LIST_COMMENT_POST_PROPERTY_NAME_LIST: listCommentPost.List = await listReader.ReadObjectAsync(jsonReader, cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return(listCommentPost); } return(await Task.FromResult(default(ITraktListCommentPost))); }
public void TestTraktListCommentPostDefaultConstructor() { var listComment = new TraktListCommentPost(); listComment.Comment.Should().BeNullOrEmpty(); listComment.Spoiler.Should().NotHaveValue(); listComment.Sharing.Should().BeNull(); listComment.List.Should().BeNull(); }
public async Task Test_TraktCommentsModule_PostListComment_ArgumentExceptions() { ITraktList list = new TraktList { Ids = new TraktListIds { Trakt = 2228577, Slug = "oscars-2016" } }; ITraktListCommentPost listCommentPost = new TraktListCommentPost { List = list, Comment = COMMENT_TEXT }; string postJson = await TestUtility.SerializeObject(listCommentPost); postJson.Should().NotBeNullOrEmpty(); TraktClient client = TestUtility.GetOAuthMockClient(POST_LIST_COMMENT_URI, postJson, COMMENT_POST_RESPONSE_JSON); Func <Task <TraktResponse <ITraktCommentPostResponse> > > act = () => client.Comments.PostListCommentAsync(null, COMMENT_TEXT); act.Should().Throw <ArgumentNullException>(); list.Ids = null; act = () => client.Comments.PostListCommentAsync(list, COMMENT_TEXT); act.Should().Throw <ArgumentNullException>(); list.Ids = new TraktListIds(); act = () => client.Comments.PostListCommentAsync(list, COMMENT_TEXT); act.Should().Throw <ArgumentException>(); list.Ids = new TraktListIds { Trakt = 2228577, Slug = "oscars-2016" }; act = () => client.Comments.PostListCommentAsync(list, null); act.Should().Throw <ArgumentException>(); act = () => client.Comments.PostListCommentAsync(list, string.Empty); act.Should().Throw <ArgumentException>(); const string comment = "one two three four"; act = () => client.Comments.PostListCommentAsync(list, comment); act.Should().Throw <ArgumentOutOfRangeException>(); }
public async Task Test_TraktCommentsModule_PostListComment_Complete() { ITraktListCommentPost listCommentPost = new TraktListCommentPost { List = List, Comment = COMMENT_TEXT, Spoiler = SPOILER, Sharing = SHARING }; string postJson = await TestUtility.SerializeObject(listCommentPost); postJson.Should().NotBeNullOrEmpty(); TraktClient client = TestUtility.GetOAuthMockClient(POST_LIST_COMMENT_URI, postJson, COMMENT_POST_RESPONSE_JSON); TraktResponse <ITraktCommentPostResponse> response = await client.Comments.PostListCommentAsync(List, 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(); }
public void TestTraktListCommentPostWriteJson() { var comment = "this is a comment"; var spoiler = false; var sharing = new TraktSharing { Facebook = false, Twitter = true, Tumblr = false }; var listTraktId = 16U; var list = new TraktList { Ids = new TraktListIds { Trakt = listTraktId } }; var listComment = new TraktListCommentPost { Comment = comment, Spoiler = spoiler, Sharing = sharing, List = list }; var strJson = JsonConvert.SerializeObject(listComment); strJson.Should().NotBeNullOrEmpty(); var listCommentFromJson = JsonConvert.DeserializeObject <TraktListCommentPost>(strJson); listCommentFromJson.Should().NotBeNull(); listCommentFromJson.Comment.Should().Be(comment); listCommentFromJson.Spoiler.Should().Be(spoiler); listCommentFromJson.Sharing.Should().NotBeNull(); listCommentFromJson.Sharing.Facebook.Should().BeFalse(); listCommentFromJson.Sharing.Twitter.Should().BeTrue(); listCommentFromJson.Sharing.Tumblr.Should().BeFalse(); listCommentFromJson.List.Should().NotBeNull(); listCommentFromJson.List.Ids.Should().NotBeNull(); listCommentFromJson.List.Ids.Trakt.Should().Be(listTraktId); }