public void TestTvEpisodeAccountStateRatingSet()
        {
            Config.Client.SetSessionInformation(Config.UserSessionId, SessionType.UserSession);
            TvEpisodeAccountState accountState = Config.Client.GetTvEpisodeAccountStateAsync(IdHelper.BreakingBad, 1, 1).Result;

            // Remove the rating
            if (accountState.Rating.HasValue)
            {
                Assert.True(Config.Client.TvEpisodeRemoveRatingAsync(IdHelper.BreakingBad, 1, 1).Result);

                // Allow TMDb to cache our changes
                Thread.Sleep(2000);
            }

            // Test that the episode is NOT rated
            accountState = Config.Client.GetTvEpisodeAccountStateAsync(IdHelper.BreakingBad, 1, 1).Result;

            Assert.Equal(IdHelper.BreakingBadSeason1Episode1Id, accountState.Id);
            Assert.False(accountState.Rating.HasValue);

            // Rate the episode
            Assert.True(Config.Client.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 5).Result);

            // Allow TMDb to cache our changes
            Thread.Sleep(2000);

            // Test that the episode IS rated
            accountState = Config.Client.GetTvEpisodeAccountStateAsync(IdHelper.BreakingBad, 1, 1).Result;
            Assert.Equal(IdHelper.BreakingBadSeason1Episode1Id, accountState.Id);
            Assert.True(accountState.Rating.HasValue);

            // Remove the rating
            Assert.True(Config.Client.TvEpisodeRemoveRatingAsync(IdHelper.BreakingBad, 1, 1).Result);
        }
Esempio n. 2
0
        public void TestTvEpisodeAccountStateRatingSet()
        {
            _config.Client.SetSessionInformation(_config.UserSessionId, SessionType.UserSession);
            TvEpisodeAccountState accountState = _config.Client.GetTvEpisodeAccountState(BreakingBad, 1, 1);

            int id = accountState.Id;

            // Remove the rating
            _config.Client.TvEpisodeSetRating(BreakingBad, 1, 1, 2);

            // Allow TMDb to cache our changes
            Thread.Sleep(2000);

            // Test that the movie is rated correctly
            accountState = _config.Client.GetTvEpisodeAccountState(BreakingBad, 1, 1);

            Assert.AreEqual(id, accountState.Id);
            Assert.IsTrue(accountState.Rating.HasValue);
            Assert.IsTrue(Math.Abs(2 - accountState.Rating.Value) < double.Epsilon);

            // Rate the movie
            _config.Client.TvEpisodeSetRating(BreakingBad, 1, 1, 7);

            // Allow TMDb to cache our changes
            Thread.Sleep(2000);

            // Test that the movie is rated correctly
            accountState = _config.Client.GetTvEpisodeAccountState(BreakingBad, 1, 1);
            Assert.IsTrue(accountState.Rating.HasValue);
            Assert.IsTrue(Math.Abs(7 - accountState.Rating.Value) < double.Epsilon);
        }
Esempio n. 3
0
        internal static void DeserializeAccountStatesRating(TvEpisodeAccountState accountState, string responseContent)
        {
            const string selector = @"""rated"":{""value"":(?<value>\d+(?:\.\d{1,2}))}";
            Regex        regex    = new Regex(selector, RegexOptions.IgnoreCase);
            Match        match    = regex.Match(responseContent);

            if (match.Success)
            {
                accountState.Rating = Double.Parse(match.Groups["value"].Value,
                                                   CultureInfo.InvariantCulture.NumberFormat);
            }
        }
Esempio n. 4
0
        public async Task <TvEpisodeAccountState> GetTvEpisodeAccountStateAsync(int tvShowId, int seasonNumber, int episodeNumber)
        {
            RequireSessionId(SessionType.UserSession);

            RestRequest req = _client.Create("tv/{id}/season/{season_number}/episode/{episode_number}/account_states");

            req.AddUrlSegment("id", tvShowId.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("season_number", seasonNumber.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("episode_number", episodeNumber.ToString(CultureInfo.InvariantCulture));
            req.AddUrlSegment("method", TvEpisodeMethods.AccountStates.GetDescription());
            AddSessionId(req, SessionType.UserSession);

            RestResponse <TvEpisodeAccountState> response = await req.ExecuteGet <TvEpisodeAccountState>().ConfigureAwait(false);

            TvEpisodeAccountState item = await response.GetDataObject().ConfigureAwait(false);

            // Do some custom deserialization, since TMDb uses a property that changes type we can't use automatic deserialization
            if (item != null)
            {
                CustomDeserialization.DeserializeAccountStatesRating(item, await response.GetContent().ConfigureAwait(false));
            }

            return(item);
        }
Esempio n. 5
0
        public async Task TestTvEpisodeAccountStateRatingSetAsync()
        {
            await TMDbClient.SetSessionInformationAsync(TestConfig.UserSessionId, SessionType.UserSession);

            TvEpisodeAccountState accountState = await TMDbClient.GetTvEpisodeAccountStateAsync(IdHelper.BreakingBad, 1, 1);

            // Remove the rating
            if (accountState.Rating.HasValue)
            {
                Assert.True(await TMDbClient.TvEpisodeRemoveRatingAsync(IdHelper.BreakingBad, 1, 1));

                // Allow TMDb to cache our changes
                await Task.Delay(2000);
            }

            // Test that the episode is NOT rated
            accountState = await TMDbClient.GetTvEpisodeAccountStateAsync(IdHelper.BreakingBad, 1, 1);

            Assert.Equal(IdHelper.BreakingBadSeason1Episode1Id, accountState.Id);
            Assert.False(accountState.Rating.HasValue);

            // Rate the episode
            Assert.True(await TMDbClient.TvEpisodeSetRatingAsync(IdHelper.BreakingBad, 1, 1, 5));

            // Allow TMDb to cache our changes
            await Task.Delay(2000);

            // Test that the episode IS rated
            accountState = await TMDbClient.GetTvEpisodeAccountStateAsync(IdHelper.BreakingBad, 1, 1);

            Assert.Equal(IdHelper.BreakingBadSeason1Episode1Id, accountState.Id);
            Assert.True(accountState.Rating.HasValue);

            // Remove the rating
            Assert.True(await TMDbClient.TvEpisodeRemoveRatingAsync(IdHelper.BreakingBad, 1, 1));
        }