Example #1
0
        // failure path
        public async Task WhenCalledWithInvalidMovieId_Returns404()
        {
            DeleteMovieRatingResult response = await _client.DeleteMovieRating(_settings.SessionId, mediaId : _invalidMovie, guestSessionId : null, retryCount : 0);

            _output.WriteLine($"TMDB server's response code {response.HttpStatusCode}");
            Assert.True(response.HttpStatusCode == System.Net.HttpStatusCode.NotFound);
        }
Example #2
0
        // happy path
        public async Task WhenCalledOnRatedMovie_DeletesRating()
        {
            DeleteMovieRatingResult response = await _client.DeleteMovieRating(_settings.SessionId, mediaId : _movie, guestSessionId : null, retryCount : 0);

            _output.WriteLine($"TMDB server's response code {response.HttpStatusCode}");
            _output.WriteLine($"TMDB server's response {response.Json}");
            Assert.True(response.HttpStatusCode == System.Net.HttpStatusCode.OK);
        }
        public async Task <DeleteMovieRatingResult> DeleteMovieRating(string sessionId, int mediaId, string guestSessionId = null, int retryCount = 0, int delayMilliseconds = 1000)
        {
            if (!string.IsNullOrEmpty(guestSessionId))
            {
                throw new NotImplementedException($"Deleting rating with guest session is not supported by the method: {nameof(DeleteMovieRating)}, parameter: {nameof(guestSessionId)}={guestSessionId}");
            }

            string baseUrl = BASE_Address + BASE_Path + MOVIE_DETAILS_Path + "/" + mediaId + RATING_Path;

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

            query.Add(API_KEY_Key, ApiKey);
            query.Add(SESSION_ID_Key, sessionId);

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

            HttpRequestMessage request = new HttpRequestMessage
            {
                Method     = HttpMethod.Delete,
                RequestUri = new Uri(requestUri)
            };

            HttpResponseMessage response = null;
            int counter = retryCount;

            try
            {
                response = await HttpClient.SendAsync(request);
            }
            catch { }
            while (response?.IsSuccessStatusCode != true && counter > 0)
            {
                await Task.Delay(delayMilliseconds);

                try
                {
                    --counter;
                    response = await HttpClient.SendAsync(request);
                }
                catch { }
            }
            DeleteMovieRatingResult result = new DeleteMovieRatingResult
            {
                HttpStatusCode = response?.StatusCode ?? HttpStatusCode.RequestTimeout
            };

            await ReadResponseAsStringIntoResultWhenSafe(result, response);

            return(result);
        }