public async Task Test_CollectionShowObjectJsonWriter_WriteObject_JsonWriter_Only_Show_Property() { ITraktCollectionShow traktCollectionShow = new TraktCollectionShow { Show = new TraktShow { Title = "Game of Thrones", Year = 2011, Ids = new TraktShowIds { Trakt = 1390U, Slug = "game-of-thrones", Tvdb = 121361U, Imdb = "tt0944947", Tmdb = 1399U, TvRage = 24493U } } }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new CollectionShowObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCollectionShow); stringWriter.ToString().Should().Be(@"{""show"":{""title"":""Game of Thrones"",""year"":2011," + @"""ids"":{""trakt"":1390,""slug"":""game-of-thrones""," + @"""tvdb"":121361,""imdb"":""tt0944947""," + @"""tmdb"":1399,""tvrage"":24493}}}"); } }
public async Task Test_CollectionShowObjectJsonWriter_WriteObject_JsonWriter_Exceptions() { var traktJsonWriter = new CollectionShowObjectJsonWriter(); ITraktCollectionShow traktCollectionShow = new TraktCollectionShow(); Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktCollectionShow); await action.Should().ThrowAsync <ArgumentNullException>(); }
public void Test_TraktCollectionShow_Default_Constructor() { var collectionShow = new TraktCollectionShow(); collectionShow.LastCollectedAt.Should().NotHaveValue(); collectionShow.Show.Should().BeNull(); collectionShow.CollectionSeasons.Should().BeNull(); collectionShow.Title.Should().BeNullOrEmpty(); collectionShow.Year.Should().NotHaveValue(); collectionShow.Airs.Should().BeNull(); collectionShow.AvailableTranslationLanguageCodes.Should().BeNull(); collectionShow.Ids.Should().BeNull(); collectionShow.Genres.Should().BeNull(); collectionShow.Seasons.Should().BeNull(); collectionShow.Overview.Should().BeNullOrEmpty(); collectionShow.FirstAired.Should().NotHaveValue(); collectionShow.Runtime.Should().NotHaveValue(); collectionShow.Certification.Should().BeNullOrEmpty(); collectionShow.Network.Should().BeNullOrEmpty(); collectionShow.CountryCode.Should().BeNullOrEmpty(); collectionShow.UpdatedAt.Should().NotHaveValue(); collectionShow.Trailer.Should().BeNullOrEmpty(); collectionShow.Homepage.Should().BeNullOrEmpty(); collectionShow.Status.Should().BeNull(); collectionShow.Rating.Should().NotHaveValue(); collectionShow.Votes.Should().NotHaveValue(); collectionShow.LanguageCode.Should().BeNullOrEmpty(); collectionShow.AiredEpisodes.Should().NotHaveValue(); }
public void Test_CollectionShowObjectJsonWriter_WriteObject_StringWriter_Exceptions() { var traktJsonWriter = new CollectionShowObjectJsonWriter(); ITraktCollectionShow traktCollectionShow = new TraktCollectionShow(); Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktCollectionShow); action.Should().Throw <ArgumentNullException>(); }
public void TestTraktCollectionShowDefaultConstructor() { var collectionShow = new TraktCollectionShow(); collectionShow.LastCollectedAt.Should().NotHaveValue(); collectionShow.Show.Should().BeNull(); collectionShow.Seasons.Should().BeNull(); }
public override async Task <ITraktCollectionShow> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { if (jsonReader == null) { return(await Task.FromResult(default(ITraktCollectionShow))); } if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var showObjectReader = new ShowObjectJsonReader(); var showSeasonsArrayReader = new CollectionShowSeasonArrayJsonReader(); ITraktCollectionShow traktCollectionShow = new TraktCollectionShow(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.COLLECTION_SHOW_PROPERTY_NAME_LAST_COLLECTED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) { traktCollectionShow.LastCollectedAt = value.Second; } break; } case JsonProperties.COLLECTION_SHOW_PROPERTY_NAME_SHOW: traktCollectionShow.Show = await showObjectReader.ReadObjectAsync(jsonReader, cancellationToken); break; case JsonProperties.COLLECTION_SHOW_PROPERTY_NAME_SEASONS: traktCollectionShow.CollectionSeasons = await showSeasonsArrayReader.ReadArrayAsync(jsonReader, cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return(traktCollectionShow); } return(await Task.FromResult(default(ITraktCollectionShow))); }
public async Task Test_CollectionShowObjectJsonWriter_WriteObject_StringWriter_Only_LastUpdatedAt_Property() { ITraktCollectionShow traktCollectionShow = new TraktCollectionShow { LastUpdatedAt = LAST_UPDATED_AT }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new CollectionShowObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktCollectionShow); json.Should().Be($"{{\"last_updated_at\":\"{LAST_UPDATED_AT.ToTraktLongDateTimeString()}\"}}"); } }
public async Task Test_CollectionShowObjectJsonWriter_WriteObject_JsonWriter_Only_LastCollectedAt_Property() { ITraktCollectionShow traktCollectionShow = new TraktCollectionShow { LastCollectedAt = LAST_COLLECTED_AT }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new CollectionShowObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCollectionShow); stringWriter.ToString().Should().Be($"{{\"last_collected_at\":\"{LAST_COLLECTED_AT.ToTraktLongDateTimeString()}\"}}"); } }
public async Task Test_CollectionShowObjectJsonWriter_WriteObject_JsonWriter_Complete() { ITraktCollectionShow traktCollectionShow = new TraktCollectionShow { LastCollectedAt = LAST_COLLECTED_AT, LastUpdatedAt = LAST_UPDATED_AT, Show = new TraktShow { Title = "Game of Thrones", Year = 2011, Ids = new TraktShowIds { Trakt = 1390U, Slug = "game-of-thrones", Tvdb = 121361U, Imdb = "tt0944947", Tmdb = 1399U, TvRage = 24493U } }, CollectionSeasons = new List <ITraktCollectionShowSeason> { new TraktCollectionShowSeason { Number = 1, Episodes = new List <ITraktCollectionShowEpisode> { 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 } }, new TraktCollectionShowEpisode { Number = 2, CollectedAt = COLLECTED_AT, Metadata = new TraktMetadata { MediaType = TraktMediaType.Digital, MediaResolution = TraktMediaResolution.HD_720p, Audio = TraktMediaAudio.AAC, AudioChannels = TraktMediaAudioChannel.Channels_5_1, ThreeDimensional = true } } } }, new TraktCollectionShowSeason { Number = 2, Episodes = new List <ITraktCollectionShowEpisode> { 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 } }, new TraktCollectionShowEpisode { Number = 2, 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()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new CollectionShowObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCollectionShow); stringWriter.ToString().Should().Be($"{{\"last_collected_at\":\"{LAST_COLLECTED_AT.ToTraktLongDateTimeString()}\"," + $"\"last_updated_at\":\"{LAST_UPDATED_AT.ToTraktLongDateTimeString()}\"," + @"""show"":{""title"":""Game of Thrones"",""year"":2011," + @"""ids"":{""trakt"":1390,""slug"":""game-of-thrones""," + @"""tvdb"":121361,""imdb"":""tt0944947""," + @"""tmdb"":1399,""tvrage"":24493}}," + @"""seasons"":[{""number"":1,""episodes"":[{""number"":1," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}," + @"{""number"":2," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}]}," + @"{""number"":2,""episodes"":[{""number"":1," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}," + @"{""number"":2," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}]}]}"); } }
public async Task Test_CollectionShowObjectJsonWriter_WriteObject_JsonWriter_Only_CollectionSeasons_Property() { ITraktCollectionShow traktCollectionShow = new TraktCollectionShow { CollectionSeasons = new List <ITraktCollectionShowSeason> { new TraktCollectionShowSeason { Number = 1, Episodes = new List <ITraktCollectionShowEpisode> { 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 } }, new TraktCollectionShowEpisode { Number = 2, CollectedAt = COLLECTED_AT, Metadata = new TraktMetadata { MediaType = TraktMediaType.Digital, MediaResolution = TraktMediaResolution.HD_720p, Audio = TraktMediaAudio.AAC, AudioChannels = TraktMediaAudioChannel.Channels_5_1, ThreeDimensional = true } } } }, new TraktCollectionShowSeason { Number = 2, Episodes = new List <ITraktCollectionShowEpisode> { 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 } }, new TraktCollectionShowEpisode { Number = 2, 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()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new CollectionShowObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktCollectionShow); stringWriter.ToString().Should().Be(@"{""seasons"":[{""number"":1,""episodes"":[{""number"":1," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}," + @"{""number"":2," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}]}," + @"{""number"":2,""episodes"":[{""number"":1," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}," + @"{""number"":2," + $"\"collected_at\":\"{COLLECTED_AT.ToTraktLongDateTimeString()}\"," + @"""metadata"":{""media_type"":""digital"",""resolution"":""hd_720p""," + @"""audio"":""aac"",""audio_channels"":""5.1"",""3d"":true}}]}]}"); } }