public void GivenMovieParameter_ValidateString_ReturnsValidMethodName(string queryProperty, string queryValue, MovieQueryParameters parameterObject)
        {
            // Arrange
            var logger   = new Mock <ILogger <MoviesController> >();
            var mockIDAL = new Mock <IDAL>();

            var controller = new MoviesController(logger.Object, mockIDAL.Object)
            {
                ControllerContext = new ControllerContext()
            };

            var request = new Dictionary <string, StringValues>
            {
                { queryProperty, queryValue }
            };

            var queryCollection = new QueryCollection(request);
            var query           = new QueryFeature(queryCollection);
            var features        = new FeatureCollection();

            features.Set <IQueryFeature>(query);
            controller.ControllerContext.HttpContext = new DefaultHttpContext(features);

            // Act
            var expectedResult = $"GetMovies:{queryProperty}:{queryValue}";
            var actualResult   = parameterObject.GetMethodText(controller.HttpContext);

            // Assert
            Assert.Equal(expectedResult, actualResult);
        }
        public async Task <IActionResult> GetMoviesAsync([FromQuery] MovieQueryParameters movieQueryParameters)
        {
            _ = movieQueryParameters ?? throw new ArgumentNullException(nameof(movieQueryParameters));

            return(await ResultHandler.Handle(
                       dal.GetMoviesAsync(movieQueryParameters), movieQueryParameters.GetMethodText(HttpContext), Constants.MoviesControllerException, logger)
                   .ConfigureAwait(false));
        }
Exemple #3
0
        public async Task <IActionResult> GetMoviesAsync([FromQuery] MovieQueryParameters movieQueryParameters)
        {
            if (movieQueryParameters == null)
            {
                throw new ArgumentNullException(nameof(movieQueryParameters));
            }

            // get the result
            IActionResult res = await ResultHandler.Handle(dal.GetMoviesAsync(movieQueryParameters), movieQueryParameters.GetMethodText(HttpContext), Constants.MoviesControllerException, logger).ConfigureAwait(false);

            // use cache dal on Cosmos 429 errors
            if (res is JsonResult jres && jres.StatusCode == 429)
            {
                res = await ResultHandler.Handle(App.CacheDal.GetMoviesAsync(movieQueryParameters), movieQueryParameters.GetMethodText(HttpContext), Constants.MoviesControllerException, logger).ConfigureAwait(false);
            }

            return(res);
        }