public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Only_Movie_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Movie = new TraktMovie
                {
                    Title = "Star Wars: The Force Awakens",
                    Year  = 2015,
                    Ids   = new TraktMovieIds
                    {
                        Trakt = 94024,
                        Slug  = "star-wars-the-force-awakens-2015",
                        Imdb  = "tt2488496",
                        Tmdb  = 140607
                    }
                }
            };

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

                json.Should().Be(@"{""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_SearchResultObjectJsonWriter_WriteObject_StringWriter_Only_Episode_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Episode = new TraktEpisode
                {
                    SeasonNumber = 1,
                    Number       = 1,
                    Title        = "Winter Is Coming",
                    Ids          = new TraktEpisodeIds
                    {
                        Trakt  = 73640,
                        Tvdb   = 3254641,
                        Imdb   = "tt1480055",
                        Tmdb   = 63056,
                        TvRage = 1065008299
                    }
                }
            };

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

                json.Should().Be(@"{""episode"":{""season"":1,""number"":1," +
                                 @"""title"":""Winter Is Coming"",""ids"":{" +
                                 @"""trakt"":73640,""tvdb"":3254641,""imdb"":""tt1480055""," +
                                 @"""tmdb"":63056,""tvrage"":1065008299}}}");
            }
        }
Exemplo n.º 3
0
 public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Exceptions()
 {
     var traktJsonWriter = new SearchResultObjectJsonWriter();
     ITraktSearchResult    traktSearchResult = new TraktSearchResult();
     Func <Task <string> > action            = () => traktJsonWriter.WriteObjectAsync(default(StringWriter), traktSearchResult);
     await action.Should().ThrowAsync <ArgumentNullException>();
 }
Exemplo n.º 4
0
 public TraktItem(TraktSearchResult searchResult)
 {
     if (searchResult.Type == TraktSearchResultType.Movie)
     {
         Type  = TraktItemType.Movie;
         Movie = searchResult.Movie;
     }
     else if (searchResult.Type == TraktSearchResultType.Show)
     {
         Type = TraktItemType.Show;
         Show = searchResult.Show;
     }
     else if (searchResult.Type == TraktSearchResultType.Episode)
     {
         Type    = TraktItemType.Episode;
         Show    = searchResult.Show;
         Episode = searchResult.Episode;
     }
     else if (searchResult.Type == TraktSearchResultType.List)
     {
         Type = TraktItemType.List;
         Show = searchResult.Show;
         List = searchResult.List;
     }
 }
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Only_Show_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Show = new TraktShow
                {
                    Title = "Game of Thrones",
                    Year  = 2011,
                    Ids   = new TraktShowIds
                    {
                        Trakt  = 1390,
                        Slug   = "game-of-thrones",
                        Tvdb   = 121361,
                        Imdb   = "tt0944947",
                        Tmdb   = 1399,
                        TvRage = 24493
                    }
                }
            };

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

                json.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_SearchResultObjectJsonWriter_WriteObject_StringWriter_Only_Person_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Person = new TraktPerson
                {
                    Name = "Bryan Cranston",
                    Ids  = new TraktPersonIds
                    {
                        Trakt  = 297737U,
                        Slug   = "bryan-cranston",
                        Imdb   = "nm0186505",
                        Tmdb   = 17419U,
                        TvRage = 1797U
                    }
                }
            };

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

                json.Should().Be(@"{""person"":{""name"":""Bryan Cranston""," +
                                 @"""ids"":{""trakt"":297737,""slug"":""bryan-cranston""," +
                                 @"""imdb"":""nm0186505"",""tmdb"":17419,""tvrage"":1797}}}");
            }
        }
Exemplo n.º 7
0
        private void SendSearchResultsToFacade(TraktSearchResult searchResults)
        {
            // clear facade
            GUIControl.ClearControl(GetID, Facade.GetID);

            if (searchResults == null || searchResults.Count == 0)
            {
                GUIUtils.ShowNotifyDialog(GUIUtils.PluginName(), Translation.NoSearchResultsFound);
                return;
            }

            // jump directly to results
            if (!TraktSettings.ShowSearchResultsBreakdown && SearchTypes.Count == 1)
            {
                // set the selected search type as we have not clicked on a facade item
                SelectedSearchType = (SearchType)GetSearchTypesID();
                SendSearchResultsToWindow(SearchResults);

                // clear the search term so when we return (press back) we don't go in a loop.
                SearchTerm = null;
                return;
            }

            int itemId = 0;

            // Add each search type to the list
            foreach (var type in SearchTypes)
            {
                GUIListItem item = new GUIListItem(GetSearchListName(type));

                item.Label2          = GetSearchResultCount(searchResults, type).ToString();
                item.ItemId          = Int32.MaxValue - itemId;
                item.TVTag           = type;
                item.IconImage       = "defaultFolder.png";
                item.IconImageBig    = "defaultFolderBig.png";
                item.ThumbnailImage  = "defaultFolderBig.png";
                item.OnItemSelected += OnItemSelected;
                Utils.SetDefaultIcons(item);
                Facade.Add(item);
                itemId++;
            }

            // Set Facade Layout
            Facade.SetCurrentLayout("List");
            GUIControl.FocusControl(GetID, Facade.GetID);

            if (PreviousSelectedIndex >= SearchTypes.Count)
            {
                Facade.SelectIndex(PreviousSelectedIndex - 1);
            }
            else
            {
                Facade.SelectIndex(PreviousSelectedIndex);
            }

            // set facade properties
            GUIUtils.SetProperty("#itemcount", SearchTypes.Count().ToString());
            GUIUtils.SetProperty("#Trakt.Items", string.Format("{0} {1}", SearchTypes.Count.ToString(), Translation.SearchTypes));
        }
        public void Test_SearchResultObjectJsonWriter_WriteObject_JsonWriter_Exceptions()
        {
            var traktJsonWriter = new SearchResultObjectJsonWriter();
            ITraktSearchResult traktSearchResult = new TraktSearchResult();
            Func <Task>        action            = () => traktJsonWriter.WriteObjectAsync(default(JsonTextWriter), traktSearchResult);

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 9
0
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_JsonWriter_Only_List_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                List = new TraktList
                {
                    Name           = "Star Wars in machete order",
                    Description    = "Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.",
                    Privacy        = TraktAccessScope.Public,
                    DisplayNumbers = true,
                    AllowComments  = true,
                    SortBy         = "rank",
                    SortHow        = "asc",
                    CreatedAt      = CREATED_UPDATED_AT,
                    UpdatedAt      = CREATED_UPDATED_AT,
                    ItemCount      = 5,
                    CommentCount   = 1,
                    Likes          = 2,
                    Ids            = new TraktListIds
                    {
                        Trakt = 55,
                        Slug  = "star-wars-in-machete-order"
                    },
                    User = new TraktUser
                    {
                        Username  = "******",
                        IsPrivate = false,
                        Name      = "Sean Rudford",
                        IsVIP     = true,
                        IsVIP_EP  = true,
                        Ids       = new TraktUserIds
                        {
                            Slug = "sean"
                        }
                    }
                }
            };

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

                    stringWriter.ToString().Should().Be(@"{""list"":{""name"":""Star Wars in machete order""," +
                                                        @"""description"":""Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.""," +
                                                        @"""privacy"":""public"",""display_numbers"":true,""allow_comments"":true," +
                                                        @"""sort_by"":""rank"",""sort_how"":""asc""," +
                                                        $"\"created_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        $"\"updated_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                                        @"""item_count"":5,""comment_count"":1,""likes"":2," +
                                                        @"""ids"":{""trakt"":55,""slug"":""star-wars-in-machete-order""}," +
                                                        @"""user"":{""username"":""sean"",""private"":false," +
                                                        @"""ids"":{""slug"":""sean""},""name"":""Sean Rudford""," +
                                                        @"""vip"":true,""vip_ep"":true}}}");
                }
        }
Exemplo n.º 10
0
        private void SendSearchResultsToWindow(TraktSearchResult searchResults)
        {
            switch (SelectedSearchType)
            {
            case SearchType.movies:
                if (SearchResults.Movies.Count() == 0)
                {
                    break;
                }
                GUISearchMovies.SearchTerm = SearchTerm;
                GUISearchMovies.Movies     = SearchResults.Movies;
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.SearchMovies);
                break;

            case SearchType.shows:
                if (SearchResults.Shows.Count() == 0)
                {
                    break;
                }
                GUISearchShows.SearchTerm = SearchTerm;
                GUISearchShows.Shows      = SearchResults.Shows;
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.SearchShows);
                break;

            case SearchType.episodes:
                if (SearchResults.Episodes.Count() == 0)
                {
                    break;
                }
                GUISearchEpisodes.SearchTerm = SearchTerm;
                GUISearchEpisodes.Episodes   = SearchResults.Episodes;
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.SearchEpisodes);
                break;

            case SearchType.people:
                if (SearchResults.People.Count() == 0)
                {
                    break;
                }
                GUISearchPeople.SearchTerm = SearchTerm;
                GUISearchPeople.People     = SearchResults.People;
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.SearchPeople);
                break;

            case SearchType.users:
                if (SearchResults.Users.Count() == 0)
                {
                    break;
                }
                GUISearchUsers.SearchTerm = SearchTerm;
                GUISearchUsers.Users      = SearchResults.Users;
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.SearchUsers);
                break;
            }
        }
Exemplo n.º 11
0
        public void Test_TraktSearchResult_Default_Constructor()
        {
            var traktSearchResultItem = new TraktSearchResult();

            traktSearchResultItem.Type.Should().BeNull();
            traktSearchResultItem.Score.Should().NotHaveValue();
            traktSearchResultItem.Movie.Should().BeNull();
            traktSearchResultItem.Show.Should().BeNull();
            traktSearchResultItem.Episode.Should().BeNull();
            traktSearchResultItem.Person.Should().BeNull();
            traktSearchResultItem.List.Should().BeNull();
        }
Exemplo n.º 12
0
        public void TestTraktSearchResultDefaultConstructor()
        {
            var searchResult = new TraktSearchResult();

            searchResult.Type.Should().BeNull();
            searchResult.Score.Should().NotHaveValue();
            searchResult.Movie.Should().BeNull();
            searchResult.Show.Should().BeNull();
            searchResult.Episode.Should().BeNull();
            searchResult.Person.Should().BeNull();
            searchResult.List.Should().BeNull();
        }
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Empty()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult();

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

                json.Should().Be(@"{}");
            }
        }
Exemplo n.º 14
0
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_JsonWriter_Empty()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult();

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

                    stringWriter.ToString().Should().Be(@"{}");
                }
        }
Exemplo n.º 15
0
        private int GetSearchResultCount(TraktSearchResult searchResults, SearchType type)
        {
            if (searchResults == null)
            {
                return(0);
            }

            int retValue = 0;

            switch (type)
            {
            case SearchType.movies:
                if (searchResults.Movies != null)
                {
                    retValue = searchResults.Movies.Count();
                }
                break;

            case SearchType.shows:
                if (searchResults.Shows != null)
                {
                    retValue = searchResults.Shows.Count();
                }
                break;

            case SearchType.episodes:
                if (searchResults.Episodes != null)
                {
                    retValue = searchResults.Episodes.Count();
                }
                break;

            case SearchType.people:
                if (searchResults.People != null)
                {
                    retValue = searchResults.People.Count();
                }
                break;

            case SearchType.users:
                if (searchResults.Users != null)
                {
                    retValue = searchResults.Users.Count();
                }
                break;
            }

            return(retValue);
        }
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Only_Score_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Score = 7.3f
            };

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

                json.Should().Be(@"{""score"":7.3}");
            }
        }
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Only_Type_Property()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Type = TraktSearchResultType.Movie
            };

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

                json.Should().Be(@"{""type"":""movie""}");
            }
        }
        public override async Task <ITraktSearchResult> 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 episodeObjectReader = new EpisodeObjectJsonReader();
                var personObjectReader  = new PersonObjectJsonReader();
                var listObjectReader    = new ListObjectJsonReader();
                ITraktSearchResult traktSearchResult = new TraktSearchResult();

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

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_TYPE:
                        traktSearchResult.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktSearchResultType>(jsonReader, cancellationToken);

                        break;

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

                        if (value.First)
                        {
                            traktSearchResult.Score = value.Second;
                        }

                        break;
                    }

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

                        break;

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

                        break;

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

                        break;

                    case JsonProperties.PROPERTY_NAME_PERSON:
                        traktSearchResult.Person = await personObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_LIST:
                        traktSearchResult.List = await listObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

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

                        break;
                    }
                }

                return(traktSearchResult);
            }

            return(await Task.FromResult(default(ITraktSearchResult)));
        }
        public async Task Test_SearchResultObjectJsonWriter_WriteObject_StringWriter_Complete()
        {
            ITraktSearchResult traktSearchResult = new TraktSearchResult
            {
                Type  = TraktSearchResultType.Movie,
                Score = 7.3f,
                Movie = new TraktMovie
                {
                    Title = "Star Wars: The Force Awakens",
                    Year  = 2015,
                    Ids   = new TraktMovieIds
                    {
                        Trakt = 94024,
                        Slug  = "star-wars-the-force-awakens-2015",
                        Imdb  = "tt2488496",
                        Tmdb  = 140607
                    }
                },
                Show = new TraktShow
                {
                    Title = "Game of Thrones",
                    Year  = 2011,
                    Ids   = new TraktShowIds
                    {
                        Trakt  = 1390,
                        Slug   = "game-of-thrones",
                        Tvdb   = 121361,
                        Imdb   = "tt0944947",
                        Tmdb   = 1399,
                        TvRage = 24493
                    }
                },
                Episode = new TraktEpisode
                {
                    SeasonNumber = 1,
                    Number       = 1,
                    Title        = "Winter Is Coming",
                    Ids          = new TraktEpisodeIds
                    {
                        Trakt  = 73640,
                        Tvdb   = 3254641,
                        Imdb   = "tt1480055",
                        Tmdb   = 63056,
                        TvRage = 1065008299
                    }
                },
                Person = new TraktPerson
                {
                    Name = "Bryan Cranston",
                    Ids  = new TraktPersonIds
                    {
                        Trakt  = 297737U,
                        Slug   = "bryan-cranston",
                        Imdb   = "nm0186505",
                        Tmdb   = 17419U,
                        TvRage = 1797U
                    }
                },
                List = new TraktList
                {
                    Name           = "Star Wars in machete order",
                    Description    = "Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.",
                    Privacy        = TraktAccessScope.Public,
                    DisplayNumbers = true,
                    AllowComments  = true,
                    SortBy         = "rank",
                    SortHow        = "asc",
                    CreatedAt      = CREATED_UPDATED_AT,
                    UpdatedAt      = CREATED_UPDATED_AT,
                    ItemCount      = 5,
                    CommentCount   = 1,
                    Likes          = 2,
                    Ids            = new TraktListIds
                    {
                        Trakt = 55,
                        Slug  = "star-wars-in-machete-order"
                    },
                    User = new TraktUser
                    {
                        Username  = "******",
                        IsPrivate = false,
                        Name      = "Sean Rudford",
                        IsVIP     = true,
                        IsVIP_EP  = true,
                        Ids       = new TraktUserIds
                        {
                            Slug = "sean"
                        }
                    }
                }
            };

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

                json.Should().Be(@"{""type"":""movie"",""score"":7.3," +
                                 @"""movie"":{""title"":""Star Wars: The Force Awakens"",""year"":2015," +
                                 @"""ids"":{""trakt"":94024,""slug"":""star-wars-the-force-awakens-2015""," +
                                 @"""imdb"":""tt2488496"",""tmdb"":140607}}," +
                                 @"""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}}," +
                                 @"""person"":{""name"":""Bryan Cranston""," +
                                 @"""ids"":{""trakt"":297737,""slug"":""bryan-cranston""," +
                                 @"""imdb"":""nm0186505"",""tmdb"":17419,""tvrage"":1797}}," +
                                 @"""list"":{""name"":""Star Wars in machete order""," +
                                 @"""description"":""Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.""," +
                                 @"""privacy"":""public"",""display_numbers"":true,""allow_comments"":true," +
                                 @"""sort_by"":""rank"",""sort_how"":""asc""," +
                                 $"\"created_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                 $"\"updated_at\":\"{CREATED_UPDATED_AT.ToTraktLongDateTimeString()}\"," +
                                 @"""item_count"":5,""comment_count"":1,""likes"":2," +
                                 @"""ids"":{""trakt"":55,""slug"":""star-wars-in-machete-order""}," +
                                 @"""user"":{""username"":""sean"",""private"":false," +
                                 @"""ids"":{""slug"":""sean""},""name"":""Sean Rudford""," +
                                 @"""vip"":true,""vip_ep"":true}}}");
            }
        }