public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_StringWriter_Only_Show_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Show = new TraktShow { Title = "The Walking Dead", Year = 2010, Ids = new TraktShowIds { Trakt = 2U, Slug = "the-walking-dead", Tvdb = 153021U, Imdb = "tt1520211", Tmdb = 1402U } } }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""show"":{""title"":""The Walking Dead"",""year"":2010," + @"""ids"":{""trakt"":2,""slug"":""the-walking-dead""," + @"""tvdb"":153021,""imdb"":""tt1520211"",""tmdb"":1402}}}"); }
public async Task Test_RecommendationObjectJsonWriter_Movie_WriteObject_StringWriter_Complete() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Rank = 1, ListedAt = LISTED_AT, Type = TraktRecommendationObjectType.Movie, Notes = "Daft Punk really knocks it out of the park on the soundtrack.", Movie = new TraktMovie { Title = "TRON: Legacy", Year = 2010, Ids = new TraktMovieIds { Trakt = 1U, Slug = "tron-legacy-2010", Imdb = "tt1104001", Tmdb = 20526U } } }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""rank"":1," + $"\"listed_at\":\"{LISTED_AT.ToTraktLongDateTimeString()}\"," + @"""type"":""movie""," + @"""notes"":""Daft Punk really knocks it out of the park on the soundtrack.""," + @"""movie"":{""title"":""TRON: Legacy"",""year"":2010," + @"""ids"":{""trakt"":1,""slug"":""tron-legacy-2010""," + @"""imdb"":""tt1104001"",""tmdb"":20526}}}"); }
public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_StringWriter_Exceptions() { var traktJsonWriter = new RecommendationObjectJsonWriter(); ITraktRecommendation traktRecommendation = new TraktRecommendation(); Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktRecommendation); await action.Should().ThrowAsync <ArgumentNullException>(); }
public async Task Test_RecommendationObjectJsonWriter_Movie_WriteObject_StringWriter_Only_Movie_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Movie = new TraktMovie { Title = "TRON: Legacy", Year = 2010, Ids = new TraktMovieIds { Trakt = 1U, Slug = "tron-legacy-2010", Imdb = "tt1104001", Tmdb = 20526U } } }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""movie"":{""title"":""TRON: Legacy"",""year"":2010," + @"""ids"":{""trakt"":1,""slug"":""tron-legacy-2010""," + @"""imdb"":""tt1104001"",""tmdb"":20526}}}"); }
public void Test_RecommendationObjectJsonWriter_Movie_WriteObject_JsonWriter_Exceptions() { var traktJsonWriter = new RecommendationObjectJsonWriter(); ITraktRecommendation traktRecommendation = new TraktRecommendation(); Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktRecommendation); action.Should().Throw <ArgumentNullException>(); }
public void Test_TraktRecommendation_Default_Constructor() { var recommendation = new TraktRecommendation(); recommendation.Rank.Should().BeNull(); recommendation.ListedAt.Should().BeNull(); recommendation.Type.Should().BeNull(); recommendation.Notes.Should().BeNull(); recommendation.Movie.Should().BeNull(); recommendation.Show.Should().BeNull(); }
public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_StringWriter_Only_Notes_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Notes = "Atmospheric for days." }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""notes"":""Atmospheric for days.""}"); }
public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_StringWriter_Only_Type_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Type = TraktRecommendationObjectType.Show }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""type"":""show""}"); }
public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_StringWriter_Only_ListedAt_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { ListedAt = LISTED_AT }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be($"{{\"listed_at\":\"{LISTED_AT.ToTraktLongDateTimeString()}\"}}"); }
public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_StringWriter_Only_Rank_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Rank = 1 }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""rank"":1}"); }
public async Task Test_RecommendationObjectJsonWriter_Movie_WriteObject_StringWriter_Only_Notes_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Notes = "Daft Punk really knocks it out of the park on the soundtrack." }; using var stringWriter = new StringWriter(); var traktJsonWriter = new RecommendationObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktRecommendation); json.Should().Be(@"{""notes"":""Daft Punk really knocks it out of the park on the soundtrack.""}"); }
public async Task Test_RecommendationObjectJsonWriter_Movie_WriteObject_JsonWriter_Only_Type_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Type = TraktRecommendationObjectType.Movie }; using var stringWriter = new StringWriter(); using var jsonWriter = new JsonTextWriter(stringWriter); var traktJsonWriter = new RecommendationObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktRecommendation); stringWriter.ToString().Should().Be(@"{""type"":""movie""}"); }
public async Task Test_RecommendationObjectJsonWriter_Movie_WriteObject_JsonWriter_Only_Rank_Property() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Rank = 1 }; using var stringWriter = new StringWriter(); using var jsonWriter = new JsonTextWriter(stringWriter); var traktJsonWriter = new RecommendationObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktRecommendation); stringWriter.ToString().Should().Be(@"{""rank"":1}"); }
public async Task Test_RecommendationObjectJsonWriter_Show_WriteObject_JsonWriter_Complete() { ITraktRecommendation traktRecommendation = new TraktRecommendation { Rank = 1, ListedAt = LISTED_AT, Type = TraktRecommendationObjectType.Show, Notes = "Atmospheric for days.", Show = new TraktShow { Title = "The Walking Dead", Year = 2010, Ids = new TraktShowIds { Trakt = 2U, Slug = "the-walking-dead", Tvdb = 153021U, Imdb = "tt1520211", Tmdb = 1402U } } }; using var stringWriter = new StringWriter(); using var jsonWriter = new JsonTextWriter(stringWriter); var traktJsonWriter = new RecommendationObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktRecommendation); stringWriter.ToString().Should().Be(@"{""rank"":1," + $"\"listed_at\":\"{LISTED_AT.ToTraktLongDateTimeString()}\"," + @"""type"":""show""," + @"""notes"":""Atmospheric for days.""," + @"""show"":{""title"":""The Walking Dead"",""year"":2010," + @"""ids"":{""trakt"":2,""slug"":""the-walking-dead""," + @"""tvdb"":153021,""imdb"":""tt1520211"",""tmdb"":1402}}}"); }
public override async Task <ITraktRecommendation> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { CheckJsonTextReader(jsonReader); if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var movieObjectReader = new MovieObjectJsonReader(); var showObjectReader = new ShowObjectJsonReader(); ITraktRecommendation traktRecommendation = new TraktRecommendation(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.PROPERTY_NAME_RANK: traktRecommendation.Rank = await jsonReader.ReadAsInt32Async(cancellationToken).ConfigureAwait(false); break; case JsonProperties.PROPERTY_NAME_LISTED_AT: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken).ConfigureAwait(false); if (value.First) { traktRecommendation.ListedAt = value.Second; } break; } case JsonProperties.PROPERTY_NAME_TYPE: traktRecommendation.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktRecommendationObjectType>(jsonReader, cancellationToken).ConfigureAwait(false); break; case JsonProperties.PROPERTY_NAME_NOTES: traktRecommendation.Notes = await jsonReader.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); break; case JsonProperties.PROPERTY_NAME_MOVIE: traktRecommendation.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false); break; case JsonProperties.PROPERTY_NAME_SHOW: traktRecommendation.Show = await showObjectReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken).ConfigureAwait(false); break; } } return(traktRecommendation); } return(await Task.FromResult(default(ITraktRecommendation))); }