public async Task Test_UserObjectJsonReader_ReadObject_From_Json_String_Not_Valid_1() { var jsonReader = new UserObjectJsonReader(); var user = await jsonReader.ReadObjectAsync(JSON_NOT_VALID_1); user.Should().NotBeNull(); user.Username.Should().BeNull(); user.IsPrivate.Should().BeFalse(); user.Name.Should().Be("Sean Rudford"); user.IsVIP.Should().BeTrue(); user.IsVIP_EP.Should().BeTrue(); user.Ids.Should().NotBeNull(); user.Ids.Slug.Should().Be("sean"); user.JoinedAt.Should().HaveValue().And.Be(DateTime.Parse("2010-09-25T17:49:25.000Z").ToUniversalTime()); user.Location.Should().Be("SF"); user.About.Should().Be("I have all your cassette tapes."); user.Gender.Should().Be("male"); user.Age.Should().Be(35); user.Images.Should().NotBeNull(); user.Images.Avatar.Should().NotBeNull(); user.Images.Avatar.Full.Should().Be("https://walter-dev.trakt.tv/images/users/000/000/001/avatars/large/0ba3f72910.jpg"); }
public async Task Test_UserObjectJsonReader_ReadObject_From_Json_String_Incomplete_7() { var jsonReader = new UserObjectJsonReader(); var user = await jsonReader.ReadObjectAsync(JSON_INCOMPLETE_7); user.Should().NotBeNull(); user.Username.Should().Be("sean"); user.IsPrivate.Should().BeFalse(); user.Name.Should().Be("Sean Rudford"); user.IsVIP.Should().BeTrue(); user.IsVIP_EP.Should().BeTrue(); user.Ids.Should().NotBeNull(); user.Ids.Slug.Should().Be("sean"); user.JoinedAt.Should().BeNull(); user.Location.Should().Be("SF"); user.About.Should().Be("I have all your cassette tapes."); user.Gender.Should().Be("male"); user.Age.Should().Be(35); user.Images.Should().NotBeNull(); user.Images.Avatar.Should().NotBeNull(); user.Images.Avatar.Full.Should().Be("https://walter-dev.trakt.tv/images/users/000/000/001/avatars/large/0ba3f72910.jpg"); }
public async Task Test_UserObjectJsonReader_ReadObject_From_Stream_Not_Valid_12() { var jsonReader = new UserObjectJsonReader(); using (var stream = JSON_NOT_VALID_12.ToStream()) { var user = await jsonReader.ReadObjectAsync(stream); user.Should().NotBeNull(); user.Username.Should().Be("sean"); user.IsPrivate.Should().BeFalse(); user.Name.Should().Be("Sean Rudford"); user.IsVIP.Should().BeTrue(); user.IsVIP_EP.Should().BeTrue(); user.Ids.Should().NotBeNull(); user.Ids.Slug.Should().Be("sean"); user.JoinedAt.Should().HaveValue().And.Be(DateTime.Parse("2010-09-25T17:49:25.000Z").ToUniversalTime()); user.Location.Should().Be("SF"); user.About.Should().Be("I have all your cassette tapes."); user.Gender.Should().Be("male"); user.Age.Should().Be(35); user.Images.Should().BeNull(); } }
public async Task Test_UserObjectJsonReader_ReadObject_From_Stream_Incomplete_18() { var jsonReader = new UserObjectJsonReader(); using (var stream = JSON_INCOMPLETE_18.ToStream()) { var user = await jsonReader.ReadObjectAsync(stream); user.Should().NotBeNull(); user.Username.Should().BeNull(); user.IsPrivate.Should().BeNull(); user.Name.Should().BeNull(); user.IsVIP.Should().BeNull(); user.IsVIP_EP.Should().BeNull(); user.Ids.Should().NotBeNull(); user.Ids.Slug.Should().Be("sean"); user.JoinedAt.Should().BeNull(); user.Location.Should().BeNull(); user.About.Should().BeNull(); user.Gender.Should().BeNull(); user.Age.Should().BeNull(); user.Images.Should().BeNull(); } }
public async Task Test_UserObjectJsonReader_ReadObject_From_Json_String_Null() { var jsonReader = new UserObjectJsonReader(); Func <Task <ITraktUser> > user = () => jsonReader.ReadObjectAsync(default(string)); await user.Should().ThrowAsync <ArgumentNullException>(); }
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)); }
public override async Task <ITraktList> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { CheckJsonTextReader(jsonReader); if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var idsReader = new ListIdsObjectJsonReader(); var userReader = new UserObjectJsonReader(); ITraktList traktList = new TraktList(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.PROPERTY_NAME_NAME: traktList.Name = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_DESCRIPTION: traktList.Description = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_PRIVACY: traktList.Privacy = await JsonReaderHelper.ReadEnumerationValueAsync <TraktAccessScope>(jsonReader, cancellationToken); break; case JsonProperties.PROPERTY_NAME_DISPLAY_NUMBERS: traktList.DisplayNumbers = await jsonReader.ReadAsBooleanAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_ALLOW_COMMENTS: traktList.AllowComments = await jsonReader.ReadAsBooleanAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_SORT_BY: traktList.SortBy = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_SORT_HOW: traktList.SortHow = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.PROPERTY_NAME_CREATED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) { traktList.CreatedAt = value.Second; } break; } case JsonProperties.PROPERTY_NAME_UPDATED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) { traktList.UpdatedAt = value.Second; } break; } case JsonProperties.PROPERTY_NAME_ITEM_COUNT: traktList.ItemCount = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.PROPERTY_NAME_COMMENT_COUNT: traktList.CommentCount = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.PROPERTY_NAME_LIKES: traktList.Likes = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.PROPERTY_NAME_IDS: traktList.Ids = await idsReader.ReadObjectAsync(jsonReader, cancellationToken); break; case JsonProperties.PROPERTY_NAME_USER: traktList.User = await userReader.ReadObjectAsync(jsonReader, cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return(traktList); } return(await Task.FromResult(default(ITraktList))); }