示例#1
0
        public async Task <ActionResult <Movie> > GetAsync([FromHeader(Name = "apikey")][Required] string apiKey, [FromQuery(Name = "title")][Required] string title, [FromQuery(Name = "year")] int year, [FromQuery(Name = "plotsize")] PlotSize plotSize)
        {
            MovieInput movieInput = new MovieInput(title, year, plotSize);

            try
            {
                var movieRequest = await _movieRequest.GetMovieAsync(apiKey, movieInput);

                return(movieRequest);
            }
            catch (HttpRequestException)
            {
                return(new ContentResult
                {
                    Content = "Unable to connect to OMDB",
                    ContentType = "text/plain",
                    StatusCode = 400
                });
            }
            catch (Exception e)
            {
                return(new ContentResult
                {
                    Content = e.Message,
                    ContentType = "text/plain",
                    StatusCode = 500
                });
            }
        }
示例#2
0
 public void Test1()
 {
     //arrange
     MovieInput movieInput = new MovieInput();
     //act
     //assert
 }
示例#3
0
        public async Task <IReadOnlyList <MovieDto> > DeleteMovie(MovieInput movie)
        {
            // var authorized = AuthCheck(user.Role);
            // if (!authorized) return "Unauthorized!";

            var deletedMovie = await _movieService.MovieDelete(movie);

            return(_mapper.Map <IReadOnlyList <Movies>, IReadOnlyList <MovieDto> >(deletedMovie));
        }
示例#4
0
 public Form1()
 {
     //Assign memory to obkects that form interacts with.
     InitializeComponent();
     movieDataBase = new BestMovieDataBase();
     InputWorker = new MovieInput();
     OutputWorker = new MoviePrinter();
     ErrorFeedBackWorker = new FormInputErrorFeedback();
 }
示例#5
0
        public async Task <ActionResult <Movie> > GetMovieAsync(string apiKey, MovieInput movieInput)
        {
            var    client = _clientFactory.CreateClient();
            string url    = UriCreator.GetOmdbUri(movieInput, apiKey);

            var response = await client.GetAsync(url);

            var   responseData = response.Content.ReadAsStringAsync().Result;
            Movie movie        = JsonConvert.DeserializeObject <Movie>(responseData);

            return(new OkObjectResult(movie));
        }
示例#6
0
 public MovieRequestTest()
 {
     _mockClientFactory = new Mock <IHttpClientFactory>(); //create mocks
     _movieRequest      = new MovieRequest(_mockClientFactory.Object);
     _mockHandler       = new Mock <HttpMessageHandler>();
     _movie             = new Movie()
     {
         Title = "Joker",
         Year  = "2000",
         Plot  = "Royal Circus, owned by Govindan, is on rocks. With the help of his manager Khader, Govindan just manages to run the company, though not in a satisfactory manner. All the members of the ..."
     };
     json        = JsonConvert.SerializeObject(_movie);
     _movieInput = new MovieInput("Joker", 2000, PlotSize.Short);
 }
示例#7
0
        public static string GetOmdbUri(MovieInput movieInput, string apiKey)
        {
            string     url        = "https://www.omdbapi.com";
            UriBuilder uriBuilder = new UriBuilder(url);

            uriBuilder.Port = -1; //to delete port number
            var query = HttpUtility.ParseQueryString(uriBuilder.Query);

            query["t"]       = movieInput.Title;
            query["y"]       = movieInput.Year.ToString();
            query["plot"]    = movieInput.PlotSize.ToString();
            query["apikey"]  = apiKey; //fix this
            uriBuilder.Query = query.ToString();
            url = uriBuilder.ToString();
            return(url);
        }
示例#8
0
        public async Task <IReadOnlyList <Movies> > MovieDelete(MovieInput movies)
        {
            if (movies == null)
            {
                return(null);
            }

            var movieEdit = new Movies
            {
                Id    = movies.Id,
                Genre = movies.Genre,
                Price = movies.Price,
                Title = movies.Title
            };

            _context.Movies.Remove(movieEdit);
            await _context.SaveChangesAsync();

            return(await _context.Movies.ToListAsync());
        }
示例#9
0
        public async Task <IReadOnlyList <MovieDto> > EditMovie(MovieInput movie)
        {
            var editedMovie = await _movieService.MovieUpdate(movie);

            return(_mapper.Map <IReadOnlyList <Movies>, IReadOnlyList <MovieDto> >(editedMovie));
        }
示例#10
0
 public UrlBuilderTest()
 {
     _movieInput = new MovieInput("Joker", 2000, PlotSize.Short);
 }