public async Task Test_HistoryItemObjectJsonWriter_Movie_WriteObject_JsonWriter_Complete()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Id        = 1982347UL,
                WatchedAt = WATCHED_AT,
                Action    = TraktHistoryActionType.Checkin,
                Type      = TraktSyncItemType.Movie,
                Movie     = new TraktMovie
                {
                    Title = "Star Wars: The Force Awakens",
                    Year  = 2015,
                    Ids   = new TraktMovieIds
                    {
                        Trakt = 94024U,
                        Slug  = "star-wars-the-force-awakens-2015",
                        Imdb  = "tt2488496",
                        Tmdb  = 140607U
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":1982347," +
                                                        $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""action"":""checkin"",""type"":""movie""," +
                                                        @"""movie"":{""title"":""Star Wars: The Force Awakens"",""year"":2015," +
                                                        @"""ids"":{""trakt"":94024,""slug"":""star-wars-the-force-awakens-2015"",""imdb"":""tt2488496"",""tmdb"":140607}}}");
                }
        }
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Only_Episode_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Episode = new TraktEpisode
                {
                    SeasonNumber = 1,
                    Number       = 1,
                    Title        = "Winter Is Coming",
                    Ids          = new TraktEpisodeIds
                    {
                        Trakt  = 73640U,
                        Tvdb   = 3254641U,
                        Imdb   = "tt1480055",
                        Tmdb   = 63056U,
                        TvRage = 1065008299U
                    }
                }
            };

            using (var stringWriter = new StringWriter())
            {
                var    traktJsonWriter = new HistoryItemObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktHistoryItem);

                json.Should().Be(@"{""id"":0,""episode"":{""season"":1,""number"":1,""title"":""Winter Is Coming""," +
                                 @"""ids"":{""trakt"":73640,""tvdb"":3254641,""imdb"":""tt1480055"",""tmdb"":63056,""tvrage"":1065008299}}}");
            }
        }
Example #3
0
        public async Task Test_HistoryItemObjectJsonWriter_Season_WriteObject_JsonWriter_Complete()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Id        = 1982347UL,
                WatchedAt = WATCHED_AT,
                Action    = TraktHistoryActionType.Checkin,
                Type      = TraktSyncItemType.Season,
                Season    = new TraktSeason
                {
                    Number = 1,
                    Ids    = new TraktSeasonIds
                    {
                        Trakt  = 61430U,
                        Tvdb   = 279121U,
                        Tmdb   = 60523U,
                        TvRage = 36939U
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":1982347," +
                                                        $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""action"":""checkin"",""type"":""season""," +
                                                        @"""season"":{""number"":1," +
                                                        @"""ids"":{""trakt"":61430,""tvdb"":279121,""tmdb"":60523,""tvrage"":36939}}}");
                }
        }
        public async Task Test_HistoryItemObjectJsonWriter_Movie_WriteObject_JsonWriter_Only_Movie_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Movie = new TraktMovie
                {
                    Title = "Star Wars: The Force Awakens",
                    Year  = 2015,
                    Ids   = new TraktMovieIds
                    {
                        Trakt = 94024U,
                        Slug  = "star-wars-the-force-awakens-2015",
                        Imdb  = "tt2488496",
                        Tmdb  = 140607U
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":0,""movie"":{""title"":""Star Wars: The Force Awakens"",""year"":2015," +
                                                        @"""ids"":{""trakt"":94024,""slug"":""star-wars-the-force-awakens-2015"",""imdb"":""tt2488496"",""tmdb"":140607}}}");
                }
        }
Example #5
0
        public async Task Test_HistoryItemObjectJsonWriter_Season_WriteObject_JsonWriter_Only_Season_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Season = new TraktSeason
                {
                    Number = 1,
                    Ids    = new TraktSeasonIds
                    {
                        Trakt  = 61430U,
                        Tvdb   = 279121U,
                        Tmdb   = 60523U,
                        TvRage = 36939U
                    }
                }
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":0,""season"":{""number"":1," +
                                                        @"""ids"":{""trakt"":61430,""tvdb"":279121,""tmdb"":60523,""tvrage"":36939}}}");
                }
        }
Example #6
0
 public TraktItem(TraktHistoryItem historyItem)
 {
     if (historyItem.Type == TraktSyncItemType.Movie)
     {
         Type  = TraktItemType.Movie;
         Movie = historyItem.Movie;
     }
     else if (historyItem.Type == TraktSyncItemType.Show)
     {
         Type = TraktItemType.Show;
         Show = historyItem.Show;
     }
     else if (historyItem.Type == TraktSyncItemType.Season)
     {
         Type   = TraktItemType.Season;
         Show   = historyItem.Show;
         Season = historyItem.Season;
     }
     else if (historyItem.Type == TraktSyncItemType.Episode)
     {
         Type    = TraktItemType.Episode;
         Show    = historyItem.Show;
         Episode = historyItem.Episode;
     }
 }
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Only_Show_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                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())
            {
                var    traktJsonWriter = new HistoryItemObjectJsonWriter();
                string json            = await traktJsonWriter.WriteObjectAsync(stringWriter, traktHistoryItem);

                json.Should().Be(@"{""id"":0,""show"":{""title"":""Game of Thrones"",""year"":2011," +
                                 @"""ids"":{""trakt"":1390,""slug"":""game-of-thrones"",""tvdb"":121361," +
                                 @"""imdb"":""tt0944947"",""tmdb"":1399,""tvrage"":24493}}}");
            }
        }
Example #8
0
 public async Task Test_HistoryItemObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
 {
     var traktJsonWriter = new HistoryItemObjectJsonWriter();
     ITraktHistoryItem traktHistoryItem = new TraktHistoryItem();
     Func <Task>       action           = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktHistoryItem);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
        public void Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Exceptions()
        {
            var traktJsonWriter = new HistoryItemObjectJsonWriter();
            ITraktHistoryItem     traktHistoryItem = new TraktHistoryItem();
            Func <Task <string> > action           = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktHistoryItem);

            action.Should().Throw <ArgumentNullException>();
        }
Example #10
0
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_JsonWriter_Complete()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Id        = 1982347UL,
                WatchedAt = WATCHED_AT,
                Action    = TraktHistoryActionType.Checkin,
                Type      = TraktSyncItemType.Episode,
                Episode   = new TraktEpisode
                {
                    SeasonNumber = 1,
                    Number       = 1,
                    Title        = "Winter Is Coming",
                    Ids          = new TraktEpisodeIds
                    {
                        Trakt  = 73640U,
                        Tvdb   = 3254641U,
                        Imdb   = "tt1480055",
                        Tmdb   = 63056U,
                        TvRage = 1065008299U
                    }
                },
                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 HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":1982347," +
                                                        $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""action"":""checkin"",""type"":""episode""," +
                                                        @"""show"":{""title"":""Game of Thrones"",""year"":2011," +
                                                        @"""ids"":{""trakt"":1390,""slug"":""game-of-thrones"",""tvdb"":121361," +
                                                        @"""imdb"":""tt0944947"",""tmdb"":1399,""tvrage"":24493}}," +
                                                        @"""episode"":{""season"":1,""number"":1,""title"":""Winter Is Coming""," +
                                                        @"""ids"":{""trakt"":73640,""tvdb"":3254641,""imdb"":""tt1480055"",""tmdb"":63056,""tvrage"":1065008299}}}");
                }
        }
Example #11
0
        public void TestTraktSyncHistoryItemDefaultConstructor()
        {
            var historyItem = new TraktHistoryItem();

            historyItem.Id.Should().Be(0);
            historyItem.WatchedAt.Should().NotHaveValue();
            historyItem.Action.Should().BeNull();
            historyItem.Type.Should().BeNull();
            historyItem.Movie.Should().BeNull();
            historyItem.Show.Should().BeNull();
            historyItem.Season.Should().BeNull();
            historyItem.Episode.Should().BeNull();
        }
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Only_Type_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Type = TraktSyncItemType.Episode
            };

            using (var stringWriter = new StringWriter())
            {
                var traktJsonWriter = new HistoryItemObjectJsonWriter();
                string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktHistoryItem);
                json.Should().Be(@"{""id"":0,""type"":""episode""}");
            }
        }
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Only_Action_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Action = TraktHistoryActionType.Checkin
            };

            using (var stringWriter = new StringWriter())
            {
                var traktJsonWriter = new HistoryItemObjectJsonWriter();
                string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktHistoryItem);
                json.Should().Be(@"{""id"":0,""action"":""checkin""}");
            }
        }
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Only_ID_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Id = 1982347UL
            };

            using (var stringWriter = new StringWriter())
            {
                var traktJsonWriter = new HistoryItemObjectJsonWriter();
                string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktHistoryItem);
                json.Should().Be(@"{""id"":1982347}");
            }
        }
        public async Task Test_HistoryItemObjectJsonWriter_Episode_WriteObject_StringWriter_Only_WatchedAt_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                WatchedAt = WATCHED_AT
            };

            using (var stringWriter = new StringWriter())
            {
                var traktJsonWriter = new HistoryItemObjectJsonWriter();
                string json = await traktJsonWriter.WriteObjectAsync(stringWriter, traktHistoryItem);
                json.Should().Be($"{{\"id\":0,\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"}}");
            }
        }
Example #16
0
        public async Task Test_HistoryItemObjectJsonWriter_Show_WriteObject_JsonWriter_Only_ID_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Id = 1982347UL
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":1982347}");
                }
        }
Example #17
0
        public async Task Test_HistoryItemObjectJsonWriter_Show_WriteObject_JsonWriter_Only_Type_Property()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Type = TraktSyncItemType.Show
            };

            using (var stringWriter = new StringWriter())
                using (var jsonWriter = new JsonTextWriter(stringWriter))
                {
                    var traktJsonWriter = new HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":0,""type"":""show""}");
                }
        }
Example #18
0
        public async Task Test_HistoryItemObjectJsonWriter_Show_WriteObject_JsonWriter_Complete()
        {
            ITraktHistoryItem traktHistoryItem = new TraktHistoryItem
            {
                Id        = 1982347UL,
                WatchedAt = WATCHED_AT,
                Action    = TraktHistoryActionType.Checkin,
                Type      = TraktSyncItemType.Show,
                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 HistoryItemObjectJsonWriter();
                    await traktJsonWriter.WriteObjectAsync(jsonWriter, traktHistoryItem);

                    stringWriter.ToString().Should().Be(@"{""id"":1982347," +
                                                        $"\"watched_at\":\"{WATCHED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""action"":""checkin"",""type"":""show""," +
                                                        @"""show"":{""title"":""Game of Thrones"",""year"":2011," +
                                                        @"""ids"":{""trakt"":1390,""slug"":""game-of-thrones"",""tvdb"":121361," +
                                                        @"""imdb"":""tt0944947"",""tmdb"":1399,""tvrage"":24493}}}");
                }
        }
        public override async Task <ITraktHistoryItem> 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();
                var seasonObjectReader  = new SeasonObjectJsonReader();
                var episodeObjectReader = new EpisodeObjectJsonReader();

                ITraktHistoryItem traktHistoryItem = new TraktHistoryItem();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_ID:
                    {
                        var value = await JsonReaderHelper.ReadUnsignedLongValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktHistoryItem.Id = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_WATCHED_AT:
                    {
                        var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktHistoryItem.WatchedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_ACTION:
                        traktHistoryItem.Action = await JsonReaderHelper.ReadEnumerationValueAsync <TraktHistoryActionType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_TYPE:
                        traktHistoryItem.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktSyncItemType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_MOVIE:
                        traktHistoryItem.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        traktHistoryItem.Show = await showObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SEASON:
                        traktHistoryItem.Season = await seasonObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        traktHistoryItem.Episode = await episodeObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktHistoryItem);
            }

            return(await Task.FromResult(default(ITraktHistoryItem)));
        }