public async Task Test_CollectionShowEpisodeObjectJsonWriter_WriteObject_StringWriter_Complete() { ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode { Number = 1, CollectedAt = COLLECTED_AT, Metadata = new TraktMetadata { MediaType = TraktMediaType.Digital, MediaResolution = TraktMediaResolution.HD_720p, Audio = TraktMediaAudio.AAC, AudioChannels = TraktMediaAudioChannel.Channels_5_1, ThreeDimensional = true } }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new CollectionShowEpisodeObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktCollectionShowEpisode); json.Should().Be(@"{""number"":1," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital""," + @"""resolution"":""hd_720p"",""audio"":""aac""," + @"""audio_channels"":""5.1"",""3d"":true}}"); } }
public async Task Test_CollectionShowEpisodeObjectJsonWriter_WriteObject_JsonWriter_Only_Metadata_Property() { ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode { Metadata = new TraktMetadata { MediaType = TraktMediaType.Digital, MediaResolution = TraktMediaResolution.HD_720p, Audio = TraktMediaAudio.AAC, AudioChannels = TraktMediaAudioChannel.Channels_5_1, ThreeDimensional = true } }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new CollectionShowEpisodeObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCollectionShowEpisode); stringWriter.ToString().Should().Be(@"{""metadata"":{""media_type"":""digital""," + @"""resolution"":""hd_720p"",""audio"":""aac""," + @"""audio_channels"":""5.1"",""3d"":true}}"); } }
public async Task Test_CollectionShowEpisodeObjectJsonWriter_WriteObject_JsonWriter_Exceptions() { var traktJsonWriter = new CollectionShowEpisodeObjectJsonWriter(); ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode(); Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCollectionShowEpisode); await action.Should().ThrowAsync <ArgumentNullException>(); }
public void Test_TraktCollectionShowEpisode_Default_Constructor() { var collectionShowEpisode = new TraktCollectionShowEpisode(); collectionShowEpisode.Number.Should().BeNull(); collectionShowEpisode.CollectedAt.Should().BeNull(); collectionShowEpisode.Metadata.Should().BeNull(); }
public void Test_CollectionShowEpisodeObjectJsonWriter_WriteObject_StringWriter_Exceptions() { var traktJsonWriter = new CollectionShowEpisodeObjectJsonWriter(); ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode(); Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCollectionShowEpisode); action.Should().Throw <ArgumentNullException>(); }
public override async Task <ITraktCollectionShowEpisode> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { if (jsonReader == null) { return(await Task.FromResult(default(ITraktCollectionShowEpisode))); } if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var metadataObjectReader = new MetadataObjectJsonReader(); ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.COLLECTION_SHOW_EPISODE_PROPERTY_NAME_NUMBER: traktCollectionShowEpisode.Number = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.COLLECTION_SHOW_EPISODE_PROPERTY_NAME_COLLECTED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) { traktCollectionShowEpisode.CollectedAt = value.Second; } break; } case JsonProperties.COLLECTION_SHOW_EPISODE_PROPERTY_NAME_METADATA: traktCollectionShowEpisode.Metadata = await metadataObjectReader.ReadObjectAsync(jsonReader, cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return(traktCollectionShowEpisode); } return(await Task.FromResult(default(ITraktCollectionShowEpisode))); }
public async Task Test_CollectionShowEpisodeObjectJsonWriter_WriteObject_StringWriter_Only_CollectedAt_Property() { ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode { CollectedAt = COLLECTED_AT }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new CollectionShowEpisodeObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktCollectionShowEpisode); json.Should().Be($"{{\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"}}"); } }
public async Task Test_CollectionShowEpisodeObjectJsonWriter_WriteObject_StringWriter_Only_Number_Property() { ITraktCollectionShowEpisode traktCollectionShowEpisode = new TraktCollectionShowEpisode { Number = 1 }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new CollectionShowEpisodeObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktCollectionShowEpisode); json.Should().Be(@"{""number"":1}"); } }