public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Number_Property() { ITraktSeason traktSeason = new TraktSeason { Number = 1 }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""number"":1}"); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Title_Property() { ITraktSeason traktSeason = new TraktSeason { Title = "Season 1" }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""title"":""Season 1""}"); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Network_Property() { ITraktSeason traktSeason = new TraktSeason { Network = "Season 1 Network" }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""network"":""Season 1 Network""}"); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_FirstAired_Property() { ITraktSeason traktSeason = new TraktSeason { FirstAired = FIRST_AIRED }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be($"{{\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"}}"); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Overview_Property() { ITraktSeason traktSeason = new TraktSeason { Overview = "Season 1 Overview" }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""overview"":""Season 1 Overview""}"); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_AiredEpisodesCount_Property() { ITraktSeason traktSeason = new TraktSeason { AiredEpisodesCount = 12 }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""aired_episodes"":12}"); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_TotalEpisodesCount_Property() { ITraktSeason traktSeason = new TraktSeason { TotalEpisodesCount = 24 }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""episode_count"":24}"); }
public void TestTraktSeasonDefaultConstructor() { var season = new TraktSeason(); season.Number.Should().NotHaveValue(); season.Ids.Should().BeNull(); season.Images.Should().BeNull(); season.Rating.Should().NotHaveValue(); season.Votes.Should().NotHaveValue(); season.TotalEpisodesCount.Should().NotHaveValue(); season.AiredEpisodesCount.Should().NotHaveValue(); season.Overview.Should().BeNullOrEmpty(); season.FirstAired.Should().NotHaveValue(); season.Episodes.Should().BeNull(); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_StringWriter_Only_Rating_Property() { ITraktSeason traktSeason = new TraktSeason { Rating = 8.7654f }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktSeason); json.Should().Be(@"{""rating"":8.7654}"); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_StringWriter_Only_Votes_Property() { ITraktSeason traktSeason = new TraktSeason { Votes = 9765 }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktSeason); json.Should().Be(@"{""votes"":9765}"); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_StringWriter_Only_UpdatedAt_Property() { ITraktSeason traktSeason = new TraktSeason { UpdatedAt = UPDATED_AT }; using (var stringWriter = new StringWriter()) { var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktSeason); json.Should().Be($"{{\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"}}"); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Title_Property() { ITraktSeason traktSeason = new TraktSeason { Title = "Season 1" }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason); stringWriter.ToString().Should().Be(@"{""title"":""Season 1""}"); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_AiredEpisodesCount_Property() { ITraktSeason traktSeason = new TraktSeason { AiredEpisodesCount = 12 }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason); stringWriter.ToString().Should().Be(@"{""aired_episodes"":12}"); } }
private TraktUserHiddenItemsPostBuilder AddSeasonOrIgnore(TraktSeason season) { if (ContainsSeason(season)) { return(this); } var hiddenItemSeason = new TraktUserHiddenItemsPostSeason() { Ids = season.Ids }; (_seasons as List <TraktUserHiddenItemsPostSeason>).Add(hiddenItemSeason); return(this); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Number_Property() { ITraktSeason traktSeason = new TraktSeason { Number = 1 }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason); stringWriter.ToString().Should().Be(@"{""number"":1}"); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_FirstAired_Property() { ITraktSeason traktSeason = new TraktSeason { FirstAired = FIRST_AIRED }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason); stringWriter.ToString().Should().Be($"{{\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"}}"); } }
private void ValidateSeason(TraktSeason season) { if (season == null) { throw new ArgumentNullException(nameof(season)); } if (season.Ids == null) { throw new ArgumentNullException(nameof(season.Ids)); } if (!season.Ids.HasAnyId) { throw new ArgumentException("no season ids set or valid", nameof(season.Ids)); } }
public void Test_TraktSeason_Default_Constructor() { var season = new TraktSeason(); season.Number.Should().NotHaveValue(); season.Title.Should().BeNullOrEmpty(); season.Ids.Should().BeNull(); season.Rating.Should().NotHaveValue(); season.Votes.Should().NotHaveValue(); season.TotalEpisodesCount.Should().NotHaveValue(); season.AiredEpisodesCount.Should().NotHaveValue(); season.Overview.Should().BeNullOrEmpty(); season.FirstAired.Should().NotHaveValue(); season.UpdatedAt.Should().NotHaveValue(); season.Network.Should().BeNull(); season.Episodes.Should().BeNull(); }
private void ValidateSeason(TraktSeason season) { if (season == null) { throw new ArgumentNullException(nameof(season), "season must not be null"); } if (season.Ids == null) { throw new ArgumentNullException(nameof(season.Ids), "season ids must not be null"); } if (!season.Ids.HasAnyId) { throw new ArgumentException("season ids have no valid id", nameof(season.Ids)); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Only_Ids_Property() { ITraktSeason traktSeason = new TraktSeason { Ids = new TraktSeasonIds { Trakt = 123, Tvdb = 456, Tmdb = 789, TvRage = 101 } }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""ids"":{""trakt"":123,""tvdb"":456,""tmdb"":789,""tvrage"":101}}"); }
public async Task <TraktEpisode[]> getAllUnwatchedEpisodesOfShow(TraktShow show) { if (show != null) { try { for (Int16 season = 1; season <= show.Seasons.Count; season++) { TraktEpisode[] episodes = null; TraktSeason currentSeason = showDao.getSeasonFromShow(show, season); if (currentSeason.SeasonEpisodes.Count == 0) { episodes = await showDao.getSeasonFromTrakt(show, season); showDao.AddEpisodesToShowSeason(show, episodes, season); } else { if (NetworkInterface.GetIsNetworkAvailable()) { TraktEpisode lastEpisode = currentSeason.SeasonEpisodes[currentSeason.SeasonEpisodes.Count - 1]; if (lastEpisode.FirstAiredAsDate >= DateTime.UtcNow) { showDao.deleteSeasonEpisodes(currentSeason); episodes = await showDao.getSeasonFromTrakt(show, season); showDao.AddEpisodesToShowSeason(show, episodes, season); } } } } return(showDao.getUnwatchedEpisodesForShow(show.tvdb_id)); } catch (NullReferenceException) { return(new TraktEpisode[0]); } } else { return(new TraktEpisode[0]); } }
public async Task <TraktCommentPostResponse> PostSeasonCommentAsync([NotNull] TraktSeason season, [NotNull] string comment, bool?containsSpoiler = null, TraktSharing sharing = null) { ValidateSeason(season); ValidateComment(comment); return(await QueryAsync(new TraktCommentPostRequest <TraktSeasonCommentPost>(Client) { RequestBody = new TraktSeasonCommentPost { Season = new TraktSeason { Ids = season.Ids }, Comment = comment, Spoiler = containsSpoiler, Sharing = sharing } })); }
public void TestTraktSeasonCommentPostWriteJson() { var comment = "this is a comment"; var spoiler = false; var sharing = new TraktSharing { Facebook = true, Twitter = false, Tumblr = false }; var seasonTraktId = 16U; var season = new TraktSeason { Ids = new TraktSeasonIds { Trakt = seasonTraktId } }; var seasonComment = new TraktSeasonCommentPost { Comment = comment, Spoiler = spoiler, Sharing = sharing, Season = season }; var strJson = JsonConvert.SerializeObject(seasonComment); strJson.Should().NotBeNullOrEmpty(); var seasonCommentFromJson = JsonConvert.DeserializeObject <TraktSeasonCommentPost>(strJson); seasonCommentFromJson.Should().NotBeNull(); seasonCommentFromJson.Comment.Should().Be(comment); seasonCommentFromJson.Spoiler.Should().Be(spoiler); seasonCommentFromJson.Sharing.Should().NotBeNull(); seasonCommentFromJson.Sharing.Facebook.Should().BeTrue(); seasonCommentFromJson.Sharing.Twitter.Should().BeFalse(); seasonCommentFromJson.Sharing.Tumblr.Should().BeFalse(); seasonCommentFromJson.Season.Should().NotBeNull(); seasonCommentFromJson.Season.Ids.Should().NotBeNull(); seasonCommentFromJson.Season.Ids.Trakt.Should().Be(seasonTraktId); }
public override async void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary <string, object> viewModelState) { dynamic parameters = navigationParameter; var seasonNumber = (int)parameters.season; showId = (int)parameters.showId; var traktSeasons = await traktService.GetSeasonsAsync(showId, extended : TraktExtendEnum.FULL_IMAGES); Season = (from traktseason in traktSeasons where traktseason.Number == seasonNumber select traktseason).Single(); Number = Season.Number; Poster = Season.Images.Poster.Full; Overview = Season.Overview; Episodes = new ObservableCollection <TraktEpisode>(from episode in await traktService.GetSeasonEpisodesAsync(showId, seasonNumber, extended: TraktExtendEnum.IMAGES) orderby episode.Number select episode); }
public async Task <TraktEpisode[]> getEpisodesOfSeason(TraktShow show, Int16 season) { if (show != null) { TraktEpisode[] episodes = null; TraktSeason currentSeason = showDao.getSeasonFromShow(show, season); if (currentSeason != null && currentSeason.SeasonEpisodes.Count > 0) { TraktEpisode lastEpisode = currentSeason.SeasonEpisodes[currentSeason.SeasonEpisodes.Count - 1]; if (lastEpisode.FirstAiredAsDate >= DateTime.UtcNow && NetworkInterface.GetIsNetworkAvailable()) { showDao.deleteSeasonEpisodes(currentSeason); episodes = await showDao.getSeasonFromTrakt(show, season); showDao.AddEpisodesToShowSeason(show, episodes, season); } else { episodes = new TraktEpisode[currentSeason.SeasonEpisodes.Count]; Debug.WriteLine("Fetched season " + season + " of show " + show.Title + " from the DB."); int i = 0; foreach (TraktEpisode episode in currentSeason.SeasonEpisodes) { episodes[i++] = episode; } } } else { episodes = await showDao.getSeasonFromTrakt(show, season); } return(episodes.OrderBy(b => b.NumberAsInt).ToArray()); } else { return(new TraktEpisode[0]); } }
public async Task Test_SeasonObjectJsonWriter_WriteObject_JsonWriter_Only_Ids_Property() { ITraktSeason traktSeason = new TraktSeason { Ids = new TraktSeasonIds { Trakt = 123, Tvdb = 456, Tmdb = 789, TvRage = 101 } }; using (var stringWriter = new StringWriter()) using (var jsonWriter = new JsonTextWriter(stringWriter)) { var traktJsonWriter = new SeasonObjectJsonWriter(); await traktJsonWriter.WriteObjectAsync(jsonWriter, traktSeason); stringWriter.ToString().Should().Be(@"{""ids"":{""trakt"":123,""tvdb"":456,""tmdb"":789,""tvrage"":101}}"); } }
public override async Task <ITraktSeason> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) { if (jsonReader == null) { return(await Task.FromResult(default(ITraktSeason))); } if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) { var idsObjectReader = new SeasonIdsObjectJsonReader(); var episodesArrayReader = new EpisodeArrayJsonReader(); ITraktSeason traktSeason = new TraktSeason(); while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) { var propertyName = jsonReader.Value.ToString(); switch (propertyName) { case JsonProperties.SEASON_PROPERTY_NAME_NUMBER: traktSeason.Number = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_TITLE: traktSeason.Title = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_IDS: traktSeason.Ids = await idsObjectReader.ReadObjectAsync(jsonReader, cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_RATING: traktSeason.Rating = (float?)await jsonReader.ReadAsDoubleAsync(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_VOTES: traktSeason.Votes = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_EPISODE_COUNT: traktSeason.TotalEpisodesCount = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_AIRED_EPISODES: traktSeason.AiredEpisodesCount = await jsonReader.ReadAsInt32Async(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_OVERVIEW: traktSeason.Overview = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_FIRST_AIRED: { var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken); if (value.First) { traktSeason.FirstAired = value.Second; } break; } case JsonProperties.SEASON_PROPERTY_NAME_NETWORK: traktSeason.Network = await jsonReader.ReadAsStringAsync(cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_EPISODES: traktSeason.Episodes = await episodesArrayReader.ReadArrayAsync(jsonReader, cancellationToken); break; case JsonProperties.SEASON_PROPERTY_NAME_COMMENT_COUNT: traktSeason.CommentCount = await jsonReader.ReadAsInt32Async(cancellationToken); break; default: await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken); break; } } return(traktSeason); } return(await Task.FromResult(default(ITraktSeason))); }
private TraktSyncAll GetSyncItems(TraktListItem listItem) { var syncItems = new TraktSyncAll(); switch (listItem.Type) { case "movie": var movie = new TraktMovie { Ids = new TraktMovieId { Trakt = listItem.Movie.Ids.Trakt } }; syncItems.Movies = new List <TraktMovie>(); syncItems.Movies.Add(movie); break; case "show": var show = new TraktShow { Ids = new TraktShowId { Trakt = listItem.Show.Ids.Trakt } }; syncItems.Shows = new List <TraktShow>(); syncItems.Shows.Add(show); break; case "season": var season = new TraktSeason { Ids = new TraktSeasonId { Trakt = listItem.Season.Ids.Trakt } }; syncItems.Seasons = new List <TraktSeason>(); syncItems.Seasons.Add(season); break; case "episode": var episode = new TraktEpisode { Ids = new TraktEpisodeId { Trakt = listItem.Episode.Ids.Trakt } }; syncItems.Episodes = new List <TraktEpisode>(); syncItems.Episodes.Add(episode); break; case "person": var person = new TraktPerson { Ids = new TraktPersonId { Trakt = listItem.Person.Ids.Trakt } }; syncItems.People = new List <TraktPerson>(); syncItems.People.Add(person); break; } return(syncItems); }
public async Task Test_SeasonObjectJsonWriter_WriteObject_Object_Complete() { ITraktSeason traktSeason = new TraktSeason { Number = 1, Title = "Season 1", Ids = new TraktSeasonIds { Trakt = 123, Tvdb = 456, Tmdb = 789, TvRage = 101 }, Rating = 8.7654f, Votes = 9765, TotalEpisodesCount = 24, AiredEpisodesCount = 12, Overview = "Season 1 Overview", FirstAired = FIRST_AIRED, Network = "Season 1 Network", Episodes = new List <ITraktEpisode> { new TraktEpisode { SeasonNumber = 1, Number = 1, Title = "title 1", Ids = new TraktEpisodeIds { Trakt = 123456, Tvdb = 234567, Imdb = "345678", Tmdb = 456789, TvRage = 567890 }, NumberAbsolute = 1, Overview = "overview 1", Runtime = 60, Rating = 8.45672f, Votes = 8925, FirstAired = FIRST_AIRED, UpdatedAt = UPDATED_AT, AvailableTranslationLanguageCodes = new List <string> { "en", "de" }, Translations = new List <TraktEpisodeTranslation> { new TraktEpisodeTranslation { Title = "german title 1", Overview = "german overview 1", LanguageCode = "de" }, new TraktEpisodeTranslation { Title = "english title 1", Overview = "english overview 1", LanguageCode = "en" } } }, new TraktEpisode { SeasonNumber = 1, Number = 2, Title = "title 2", Ids = new TraktEpisodeIds { Trakt = 123456, Tvdb = 234567, Imdb = "345678", Tmdb = 456789, TvRage = 567890 }, NumberAbsolute = 2, Overview = "overview 2", Runtime = 60, Rating = 8.45672f, Votes = 8925, FirstAired = FIRST_AIRED, UpdatedAt = UPDATED_AT, AvailableTranslationLanguageCodes = new List <string> { "en", "de" }, Translations = new List <TraktEpisodeTranslation> { new TraktEpisodeTranslation { Title = "german title 2", Overview = "german overview 2", LanguageCode = "de" }, new TraktEpisodeTranslation { Title = "english title 2", Overview = "english overview 2", LanguageCode = "en" } } } } }; var traktJsonWriter = new SeasonObjectJsonWriter(); string json = await traktJsonWriter.WriteObjectAsync(traktSeason); json.Should().Be(@"{""number"":1,""title"":""Season 1""," + @"""ids"":{""trakt"":123,""tvdb"":456,""tmdb"":789,""tvrage"":101}," + @"""rating"":8.7654,""votes"":9765,""episode_count"":24,""aired_episodes"":12," + @"""overview"":""Season 1 Overview""," + $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," + @"""network"":""Season 1 Network""," + @"""episodes"":[" + @"{""season"":1,""number"":1,""title"":""title 1""," + @"""ids"":{""trakt"":123456,""tvdb"":234567,""imdb"":""345678"",""tmdb"":456789,""tvrage"":567890}," + @"""number_abs"":1,""overview"":""overview 1""," + @"""runtime"":60,""rating"":8.45672,""votes"":8925," + $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," + $"\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"," + @"""available_translations"":[""en"",""de""]," + @"""translations"":[{""title"":""german title 1"",""overview"":""german overview 1"",""language"":""de""}," + @"{""title"":""english title 1"",""overview"":""english overview 1"",""language"":""en""}]}," + @"{""season"":1,""number"":2,""title"":""title 2""," + @"""ids"":{""trakt"":123456,""tvdb"":234567,""imdb"":""345678"",""tmdb"":456789,""tvrage"":567890}," + @"""number_abs"":2,""overview"":""overview 2""," + @"""runtime"":60,""rating"":8.45672,""votes"":8925," + $"\"first_aired\":\"{FIRST_AIRED.ToTraktLongDateTimeString()}\"," + $"\"updated_at\":\"{UPDATED_AT.ToTraktLongDateTimeString()}\"," + @"""available_translations"":[""en"",""de""]," + @"""translations"":[{""title"":""german title 2"",""overview"":""german overview 2"",""language"":""de""}," + @"{""title"":""english title 2"",""overview"":""english overview 2"",""language"":""en""}]}" + "]}"); }
/// <summary>Remove one or more items from a custom list</summary> /// <param name="listId">The list ID</param> /// <param name="season">The season</param> /// <returns>See summary</returns> public async Task <TraktRemoveResponse> RemoveFromListAsync(string listId, TraktSeason season) { return(await RemoveFromListAsync(listId, null, null, new List <TraktSeason> { season }, null, null)); }