public async Task Test_CommentLikeObjectJsonWriter_WriteObject_JsonWriter_Complete() { ITraktCommentLike traktCommentLike = new TraktCommentLike { LikedAt = LIKED_AT, 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 CommentLikeObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCommentLike); stringWriter.ToString().Should().Be($"{{\"liked_at\":\"{LIKED_AT.ToTraktLongDateTimeString()}\"," + @"""user"":{""username"":""sean"",""private"":false,""ids"":{""slug"":""sean""}," + @"""name"":""Sean Rudford"",""vip"":true,""vip_ep"":true}}"); } }
public async Task Test_CommentLikeObjectJsonWriter_WriteObject_StringWriter_Exceptions() { var traktJsonWriter = new CommentLikeObjectJsonWriter(); ITraktCommentLike traktCommentLike = new TraktCommentLike(); Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCommentLike); await action.Should().ThrowAsync <ArgumentNullException>(); }
public async Task Test_CommentLikeObjectJsonWriter_WriteObject_JsonWriter_Only_User_Property() { ITraktCommentLike traktCommentLike = new TraktCommentLike { 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 CommentLikeObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCommentLike); stringWriter.ToString().Should().Be(@"{""user"":{""username"":""sean"",""private"":false,""ids"":{""slug"":""sean""}," + @"""name"":""Sean Rudford"",""vip"":true,""vip_ep"":true}}"); } }
public void Test_TraktCommentLike_Default_Constructor() { var traktCommentLike = new TraktCommentLike(); traktCommentLike.LikedAt.Should().BeNull(); traktCommentLike.User.Should().BeNull(); }
public void Test_CommentLikeObjectJsonWriter_WriteObject_JsonWriter_Exceptions() { var traktJsonWriter = new CommentLikeObjectJsonWriter(); ITraktCommentLike traktCommentLike = new TraktCommentLike(); Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCommentLike); action.Should().Throw <ArgumentNullException>(); }
public async Task Test_CommentLikeObjectJsonWriter_WriteObject_StringWriter_Empty() { ITraktCommentLike traktCommentLike = new TraktCommentLike(); using (var stringWriter = new StringWriter()) { var traktJsonWriter = new CommentLikeObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktCommentLike); json.Should().Be(@"{}"); } }
public async Task Test_CommentLikeObjectJsonWriter_WriteObject_JsonWriter_Empty() { ITraktCommentLike traktCommentLike = new TraktCommentLike(); using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new CommentLikeObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCommentLike); stringWriter.ToString().Should().Be(@"{}"); } }
public async Task Test_CommentLikeObjectJsonWriter_WriteObject_StringWriter_Only_LikedAt_Property() { ITraktCommentLike traktCommentLike = new TraktCommentLike { LikedAt = LIKED_AT }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new CommentLikeObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktCommentLike); json.Should().Be($"{{\"liked_at\":\"{LIKED_AT.ToTraktLongDateTimeString()}\"}}"); } }
public override async Task <ITraktCommentLike> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { if (jsonReader == null) { return(await Task.FromResult(default(ITraktCommentLike))); } if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { ITraktCommentLike traktCommentLike = new TraktCommentLike(); var userObjectJsonReader = new UserObjectJsonReader(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.COMMENT_LIKE_PROPERTY_NAME_LIKED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken).ConfigureAwait(false); if (value.First) { traktCommentLike.LikedAt = value.Second; } break; } case JsonProperties.COMMENT_LIKE_PROPERTY_NAME_USER: traktCommentLike.User = await userObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken).ConfigureAwait(false); break; } } return(traktCommentLike); } return(await Task.FromResult(default(ITraktCommentLike))); }