public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_Object_Complete() { ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress { Number = 1, Aired = 24, Completed = 12, Episodes = new List <ITraktEpisodeWatchedProgress> { new TraktEpisodeWatchedProgress { Number = 1, Completed = true, LastWatchedAt = LAST_WATCHED_AT }, new TraktEpisodeWatchedProgress { Number = 2, Completed = true, LastWatchedAt = LAST_WATCHED_AT } } }; var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeasonWatchedProgress); json.Should().Be(@"{""number"":1,""aired"":24,""completed"":12," + @"""episodes"":[" + $"{{\"number\":1,\"completed\":true,\"last_watched_at\":\"{LAST_WATCHED_AT.ToTraktLongDateTimeString()}\"}}," + $"{{\"number\":2,\"completed\":true,\"last_watched_at\":\"{LAST_WATCHED_AT.ToTraktLongDateTimeString()}\"}}" + "]}"); }
public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_JsonWriter_Exceptions() { var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress(); Func <Task> action = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktSeasonWatchedProgress); await action.Should().ThrowAsync <ArgumentNullException>(); }
public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_JsonWriter_Only_Episodes_Property() { ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress { Episodes = new List <ITraktEpisodeWatchedProgress> { new TraktEpisodeWatchedProgress { Number = 1, Completed = true, LastWatchedAt = LAST_WATCHED_AT }, new TraktEpisodeWatchedProgress { Number = 2, Completed = true, LastWatchedAt = LAST_WATCHED_AT } } }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeasonWatchedProgress); stringWriter.ToString().Should().Be(@"{""episodes"":[" + $"{{\"number\":1,\"completed\":true,\"last_watched_at\":\"{LAST_WATCHED_AT.ToTraktLongDateTimeString()}\"}}," + $"{{\"number\":2,\"completed\":true,\"last_watched_at\":\"{LAST_WATCHED_AT.ToTraktLongDateTimeString()}\"}}" + "]}"); } }
public void Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_StringWriter_Exceptions() { var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress(); Func <Task <string> > action = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktSeasonWatchedProgress); action.Should().Throw <ArgumentNullException>(); }
public void Test_TraktSeasonWatchedProgress_Default_Constructor() { var seasonWatchedProgress = new TraktSeasonWatchedProgress(); seasonWatchedProgress.Number.Should().NotHaveValue(); seasonWatchedProgress.Aired.Should().NotHaveValue(); seasonWatchedProgress.Completed.Should().NotHaveValue(); seasonWatchedProgress.Episodes.Should().BeNull(); }
public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_Object_Only_Completed_Property() { ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress { Completed = 12 }; var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeasonWatchedProgress); json.Should().Be(@"{""completed"":12}"); }
public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_Object_Only_Number_Property() { ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress { Number = 1 }; var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeasonWatchedProgress); json.Should().Be(@"{""number"":1}"); }
public override async Task <ITraktSeasonWatchedProgress> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { if (jsonReader == null) { return(await Task.FromResult(default(ITraktSeasonWatchedProgress))); } if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var episodeWatchedProgressArrayReader = new EpisodeWatchedProgressArrayJsonReader(); ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.SEASON_WATCHED_PROGRESS_PROPERTY_NAME_NUMBER: traktSeasonWatchedProgress.Number = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_WATCHED_PROGRESS_PROPERTY_NAME_AIRED: traktSeasonWatchedProgress.Aired = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_WATCHED_PROGRESS_PROPERTY_NAME_COMPLETED: traktSeasonWatchedProgress.Completed = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_WATCHED_PROGRESS_PROPERTY_NAME_EPISODES: traktSeasonWatchedProgress.Episodes = await episodeWatchedProgressArrayReader.ReadArrayAsync(jsonReader, cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return(traktSeasonWatchedProgress); } return(await Task.FromResult(default(ITraktSeasonWatchedProgress))); }
public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_StringWriter_Only_Aired_Property() { ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress { Aired = 24 }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktSeasonWatchedProgress); json.Should().Be(@"{""aired"":24}"); } }
public async Task Test_SeasonWatchedProgressObjectJsonWriter_WriteObject_JsonWriter_Only_Completed_Property() { ITraktSeasonWatchedProgress traktSeasonWatchedProgress = new TraktSeasonWatchedProgress { Completed = 12 }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonWatchedProgressObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeasonWatchedProgress); stringWriter.ToString().Should().Be(@"{""completed"":12}"); } }