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}}"); } }
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 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>(); }
private void PublishCommentSkinProperties(TraktComment comment) { if (comment == null) { return; } GUICommon.SetUserProperties(comment.User); GUICommon.SetCommentProperties(comment, IsWatched); }
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 void TestTraktCommentDefaultConstructor() { var comment = new TraktComment(); comment.Id.Should().Be(0); comment.ParentId.Should().BeNull(); comment.CreatedAt.Should().Be(DateTime.MinValue); comment.UpdatedAt.Should().NotHaveValue(); comment.Comment.Should().BeNullOrEmpty(); comment.Spoiler.Should().BeFalse(); comment.Review.Should().BeFalse(); comment.Replies.Should().NotHaveValue(); comment.Likes.Should().NotHaveValue(); comment.UserRating.Should().NotHaveValue(); comment.User.Should().BeNull(); }
public void Test_TraktComment_Default_Constructor() { var traktComment = new TraktComment(); 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(); }
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}"); } }
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}"); } }
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}"); } }
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}}"); } }
public override async Task<ITraktComment> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { CheckJsonTextReader(jsonReader); if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var userReader = new UserObjectJsonReader(); ITraktComment traktComment = new TraktComment(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.PROPERTY_NAME_ID: { var value = await JsonReaderHelper.ReadUnsignedIntegerValueAsync(jsonReader, cancellationToken); if (value.First) traktComment.Id = value.Second; break; } case JsonProperties.PROPERTY_NAME_PARENT_ID: { var value = await JsonReaderHelper.ReadUnsignedIntegerValueAsync(jsonReader, cancellationToken); if (value.First) traktComment.ParentId = value.Second; break; } case JsonProperties.PROPERTY_NAME_CREATED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) traktComment.CreatedAt = value.Second; break; } case JsonProperties.PROPERTY_NAME_UPDATED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) traktComment.UpdatedAt = value.Second; break; } case JsonProperties.PROPERTY_NAME_COMMENT: traktComment.Comment = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_SPOILER: traktComment.Spoiler = (bool)await jsonReader.ReadAsBooleanAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_REVIEW: traktComment.Review = (bool)await jsonReader.ReadAsBooleanAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_REPLIES: traktComment.Replies = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.PROPERTY_NAME_LIKES: traktComment.Likes = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.PROPERTY_NAME_USER_RATING: { var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken); if (value.First) traktComment.UserRating = value.Second; break; } case JsonProperties.PROPERTY_NAME_USER: traktComment.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return traktComment; } return await Task.FromResult(default(ITraktComment)); }
/// <summary>Remove a like on a comment</summary> /// <param name="comment">The comment</param> /// <returns>See summary</returns> public async Task UnlikeCommentAsync(TraktComment comment) { await UnlikeCommentAsync(comment.Id.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)); }
/// <summary>Votes help determine popular comments. Only one like is allowed per comment per user.</summary> /// <param name="comment">The comment</param> /// <returns>See summary</returns> public async Task <TraktComment> LikeCommentAsync(TraktComment comment) { return(await LikeCommentAsync(comment.Id.GetValueOrDefault().ToString(CultureInfo.InvariantCulture))); }
/// <summary>Update a single comment created within the last hour. The OAuth user must match the author of the comment in order to update it.</summary> /// <param name="comment">The comment</param> /// <returns>See summary</returns> public async Task <TraktComment> UpdateCommentAsync(TraktComment comment) { return(await UpdateCommentAsync(comment.Id.GetValueOrDefault().ToString(CultureInfo.InvariantCulture), comment.Comment, comment.Spoiler.GetValueOrDefault(false), comment.Review.GetValueOrDefault(false))); }