Ejemplo n.º 1
0
        //TODO : Make sort option to enum
        public async Task <GetMovieWatchlistResult> GetMovieWatchlist(string sessionId, int?accountId = null, string language = null, string sortBy = null, int?page = null, int retryCount = 0, int delayMilliseconds = 1000)
        {
            //TODO : Recheck this!
            // no mistake here: missing "account_id" parameter add the string literal "{account_id}" as paths segment
            string baseUrl = BASE_Address + BASE_Path + ACCOUNT_DETAILS_Path + "/" + (accountId.HasValue ? accountId.Value.ToString() : "{account_id}") + WATCHLIST_Path + MOVIES_Path;

            var query = new Dictionary <string, string>();

            query.Add(API_KEY_Key, ApiKey);

            if (!string.IsNullOrEmpty(language))
            {
                query.Add(LANGUAGE_Key, language);
            }

            if (page > 0)
            {
                query.Add(PAGE_Key, page.Value.ToString());
            }

            if (!string.IsNullOrEmpty(sortBy))
            {
                query.Add(SORTBY_Key, sortBy);
            }

            query.Add(SESSION_ID_Key, sessionId);

            string requestUri = QueryHelpers.AddQueryString(baseUrl, query);

            GetMovieWatchlistResult result = await GetResponse <GetMovieWatchlistResult>(retryCount, delayMilliseconds, requestUri);

            return(result);
        }
        // failure path
        public async Task WhenCalledWithInvalidSessionId_ReturnsUnauthorized401()
        {
            _settings.SessionId = "invalidSessionId";

            GetMovieWatchlistResult result = await _client.GetMovieWatchlist(_settings.SessionId, accountId : null, language : null, sortBy : null, page : null, retryCount : 0);

            _output.WriteLine($"Server returned {result.HttpStatusCode}");

            Assert.True(result.HttpStatusCode == System.Net.HttpStatusCode.Unauthorized);
        }
Ejemplo n.º 3
0
        // empty the watchlist if not yet empty
        public async Task InitializeAsync()
        {
            GetMovieWatchlistResult getWatchlist = await _client.GetMovieWatchlist(_settings.SessionId);

            SearchResult moviesOnWatchlist = JsonConvert.DeserializeObject <SearchResult>(getWatchlist.Json);

            foreach (var movie in moviesOnWatchlist.MovieDetailModels)
            {
                await _client.UpdateWatchlist(_settings.SessionId, "movie", false, movie.Id);
            }
        }
        // happy path
        public async Task WhenCalledOnEmptyList_ReturnsEmptyCollection()
        {
            GetMovieWatchlistResult result = await _client.GetMovieWatchlist(_settings.SessionId, accountId : null, language : null, sortBy : null, page : null, retryCount : 0);

            _output.WriteLine($"Server returned {result.HttpStatusCode}");
            _output.WriteLine($"Json: {result.Json}");

            var watchlist = JsonConvert.DeserializeObject <SearchResult>(result.Json);

            PrintWatchlist(watchlist);

            Assert.True(watchlist.MovieDetailModels.Count == 0);
        }
        // happy path
        public async Task WhenCalledOnNonemptyList_GivesBackList()
        {
            await _client.UpdateWatchlist(_settings.SessionId, "movie", true, _movie1);

            await _client.UpdateWatchlist(_settings.SessionId, "movie", true, _movie2);

            GetMovieWatchlistResult result = await _client.GetMovieWatchlist(_settings.SessionId, accountId : null, language : null, sortBy : null, page : null, retryCount : 0);

            _output.WriteLine($"Server returned {result.HttpStatusCode}");
            _output.WriteLine($"Json: {result.Json}");

            var watchlist = JsonConvert.DeserializeObject <SearchResult>(result.Json);

            PrintWatchlist(watchlist);

            Assert.True(watchlist.MovieDetailModels.Count > 0);
            Assert.Contains(watchlist.MovieDetailModels, movie => movie.Id == _movie1);
            Assert.Contains(watchlist.MovieDetailModels, movie => movie.Id == _movie2);
        }
        // happy path
        public async Task WhenCalledWithSortOption_RespectsSortRequest()
        {
            await _client.UpdateWatchlist(_settings.SessionId, "movie", true, _movie1);

            await _client.UpdateWatchlist(_settings.SessionId, "movie", true, _movie2);


            GetMovieWatchlistResult resultAsc = await _client.GetMovieWatchlist(_settings.SessionId, accountId : null, language : null, sortBy : "created_at.asc", page : null, retryCount : 0);

            var watchlistAsc = JsonConvert.DeserializeObject <SearchResult>(resultAsc.Json);
            var movieIdsAsc  = watchlistAsc.MovieDetailModels.Select(movie => movie.Id);

            GetMovieWatchlistResult resultDesc = await _client.GetMovieWatchlist(_settings.SessionId, accountId : null, language : null, sortBy : "created_at.desc", page : null, retryCount : 0);

            var watchlistDesc = JsonConvert.DeserializeObject <SearchResult>(resultDesc.Json);
            var movieIdsDesc  = watchlistDesc.MovieDetailModels.Select(movie => movie.Id);

            PrintWatchlist(watchlistAsc);
            PrintWatchlist(watchlistDesc);

            Assert.True(movieIdsAsc.Reverse().SequenceEqual(movieIdsDesc));
        }