public void Should_return_movie_translated_to_a_movies_response_when_movie_is_found( IWebApiMovieRestContext context, GetMovieRequestHandler getMovieRequestHandler, Movie newMovie, GetMovieRequest getMovieRequest, MoviesResponse moviesResponse ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a GetMovieRequestHandler constructed with the context" .And(() => getMovieRequestHandler = new GetMovieRequestHandler(context)); "And a new Movie that has been inserted into the database" .And(() => newMovie = Db.InsertMovie(new MovieBuilder())); "And a GetMovieRequest containing the id of the newly inserted Movie". And(() => getMovieRequest = new GetMovieRequest() { MovieId = newMovie.Id }); "After handling the GetMovieRequest" .When(() => moviesResponse = getMovieRequestHandler.Handle(getMovieRequest)); "The MovieResponse should be the newly inserted Movie translated" .Then(() => moviesResponse.ShouldBeEquivalentTo(newMovie.Yield().ToResponse())); }
public void Should_return_all_movie_translated_to_a_movies_response_when_no_genre_specified_in_request( IWebApiMovieRestContext context, GetMoviesRequestHandler getMoviesRequestHandler, GetMoviesRequest getMovieRequest, MoviesResponse moviesResponse ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a GetMoviesRequestHandler constructed with the context" .And(() => getMoviesRequestHandler = new GetMoviesRequestHandler(context)); "And a GetMoviesRequest with no genre specified". And(() => getMovieRequest = new GetMoviesRequest()); "After handling the GetMoviesRequest" .When(() => moviesResponse = getMoviesRequestHandler.Handle(getMovieRequest)); "The MovieResponse should be all existing Movies in the database translated".Then(() => { var existingMoviesTranslated = new WebApiMovieRestInitializer() .SeedMovies() .ToResponse(); moviesResponse.ShouldBeEquivalentTo( existingMoviesTranslated, // do not compare ids or links (as ids will be different) o => o.Excluding(x => x.PropertyInfo.Name == "Id" || x.PropertyInfo.Name == "Links") ); }); }
/// <summary> /// GET /Movies /// GET /Movies?Id={Id} /// </summary> /// <param name="request"></param> /// <returns></returns> public object Get(Movies request) { //Alternatively you can infer the HTTP method by inspecting the RequestContext attributes Log.InfoFormat("Using RequestContext to inspect Endpoint attributes: {0}", this.RequestContext.EndpointAttributes); var response = new MoviesResponse(); using (var dbConn = ConnectionFactory.OpenDbConnection()) using (var dbCmd = dbConn.CreateCommand()) { if (request.Id != null) { // GET /Movies?Id={request.Id} var movie = dbCmd.GetByIdOrDefault <Movie>(request.Id); if (movie != null) { response.Movies.Add(movie); } } else { // GET /Movies response.Movies = dbCmd.Select <Movie>(); } } return(response); }
public async Task <IEnumerable <Listing> > GetMoviesByCinema(Cinema cinema, int dayRange) { var lFactory = new ListingFactory(); var movies = new List <Listing>(); using (var client = new HttpClient()) { for (var d = 0; d < dayRange; d++) { string strResponse; MoviesResponse movResponse = null; try { InformationalMessage("cinema [" + cinema.id + "] day [" + d + "]"); strResponse = await client.GetStringAsync("http://api.cinelist.co.uk/get/times/cinema/" + cinema.id + "?day=" + d); movResponse = JsonConvert.DeserializeObject <MoviesResponse>(strResponse); } catch (HttpRequestException e) { HandleTrivialError(e.Message); } if (movResponse != null) { movies.AddRange(lFactory.Convert(movResponse.listings, d)); } } } return(movies); }
/// <summary> /// GET /Movies /// GET /Movies?Id={Id} /// </summary> /// <param name="request"></param> /// <returns></returns> public object Get(Movies request) { //Alternatively you can infer the HTTP method by inspecting the RequestContext attributes Log.InfoFormat("Using RequestContext to inspect Endpoint attributes: {0}", this.Request.RequestAttributes); var response = new MoviesResponse(); if (request.Id != null) { // GET /Movies?Id={request.Id} var movie = Db.SingleById <Movie>(request.Id); if (movie != null) { response.Movies.Add(movie); } } else { // GET /Movies response.Movies = Db.Select <Movie>(); } return(response); }
public override Task <MoviesResponse> GetMovies(MovieRequest request, ServerCallContext context) { var result = new MoviesResponse(); result.Movies.AddRange(Enumerable.Range(200, 200) .Select(index => new MovieResponse { Id = 1, ImdbId = "2", Budget = 1000, Revenue = 100000, Popularity = 10, TagLine = "test", VoteAverage = 5, VoteCount = 1000, OriginalLanguage = "ua", OriginalTitle = "Test", Title = "Test Cool", Overview = "Cool", ReleaseDateTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), State = "Released" })); return(Task.FromResult(result)); }
public async Task <MoviesResponse> GetList(string q, int page_limit, int page) { MoviesResponse movies = new MoviesResponse(); movies = await projectAAL.GetList(q, page_limit, page); return(movies); }
public async Task <MoviesResponse> GetListBySearch(string q) { MoviesResponse movies = new MoviesResponse(); movies = await projectAAL.GetListBySearch(q); return(movies); }
public async Task <List <Movie> > GetPopularMovies() { MoviesResponse popularMoviesResponse = new MoviesResponse(); string url = "https://api.themoviedb.org/3/movie/popular?api_key=580bda8a5ab6a951e45ea4385de5bdd8"; popularMoviesResponse = await client.GetFromJsonAsync <MoviesResponse>(url); return(popularMoviesResponse.results.OrderByDescending(m => m.vote_average).ToList()); }
public async Task <List <Movie> > GetNowPlayingMovies() { MoviesResponse nowPlayingMovies = new MoviesResponse(); string url = "https://api.themoviedb.org/3/movie/now_playing?api_key=580bda8a5ab6a951e45ea4385de5bdd8"; nowPlayingMovies = await client.GetFromJsonAsync <MoviesResponse>(url); return(nowPlayingMovies.results.OrderByDescending(m => m.release_date).ToList()); }
public async Task <MoviesResponse> GetMovies() { string RequestUrl = $"{Properties.Settings.Default.MoviesAPIPath}/api/{MovieProviderEnum.filmworld}/movies"; string result = await _providerHelper.RestAPICall(RequestUrl); FilmWorldMoviesResponse filmMovies = JsonConvert.DeserializeObject <FilmWorldMoviesResponse>(result); MoviesResponse movies = _mapper.Map <MoviesResponse>(filmMovies); return(movies); }
private async void GetFilms() { var swapi = new SwapiService(); MoviesResponse result = await swapi.GetFilms(); if (result != null) { Films = result.Results.ToList(); } }
public void Can_Serialize_MoviesResponse_Dto() { var request = new MoviesResponse { Movies = ResetMoviesService.Top5Movies }; var csv = CsvSerializer.SerializeToString(request); var csvRows = csv.Split('\n').Where(x => !x.IsNullOrEmpty()).ToArray(); Assert.That(csvRows.Length, Is.EqualTo(HeaderRowCount + ResetMoviesService.Top5Movies.Count)); }
public void Should_create_movie_and_use_existing_genre_if_genre_exists( IWebApiMovieRestContext context, CreateMovieRequestHandler createMovieRequestHandler, Genre alreadyExistingGenre, Movie newMovie, CreateMovieRequest createMovieRequest, MoviesResponse moviesResponse, Movie createdMovie ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a CreateMovieRequestHandler constructed with the context" .And(() => createMovieRequestHandler = new CreateMovieRequestHandler(context)); "And a Genre that already exists in the database".And(() => { var alreadyExistingGenreName = new WebApiMovieRestInitializer() .SeedMovies().First() .Genres.First() .Name; alreadyExistingGenre = Db.GetGenreByName(alreadyExistingGenreName); }); "And a CreateMovieRequest containing a genre that exists in the database". And(() => createMovieRequest = new CreateMovieRequestBuilder().WithGenres(new[] { alreadyExistingGenre.Name })); "After handling the CreateMovieRequest" .When(() => moviesResponse = createMovieRequestHandler.Handle(createMovieRequest)); "And commiting the WebApiMovieRestContext" .When(() => context.Commit()); "Then a Movie should have be created in the database".Then(() => { var createdMovieId = moviesResponse.Movies.First().Id; createdMovie = Db.GetMovieById(createdMovieId); createdMovie.Should().NotBeNull(); }); "And the already existing Genre should have be used".Then(() => createdMovie.Genres.Single().ShouldBeEquivalentTo(alreadyExistingGenre)); "And the new movie should have the same values as the request" .Then(() => createdMovie.ShouldBeEquivalentTo(createMovieRequest, o => o.ExcludingMissingProperties())); "And the new movie should have the same genre as the request" .Then(() => createdMovie.Genres.Single().Name.Should().Be(createMovieRequest.Genres[0])); "And the MovieResponse should be the newly created Movie translated" .Then(() => moviesResponse.ShouldBeEquivalentTo(createdMovie.Yield().ToResponse())); }
public HttpResponseMessage Process(CreateMovieRequest request) { MoviesResponse moviesResponse = _handler.Handle(request); var createdMovieId = moviesResponse.Movies.First().Id; var response = Request.CreateResponse(HttpStatusCode.Created, moviesResponse); response.Headers.Location = Url.GetMovieById(createdMovieId); return(response); }
public List <WeekResponse> uniteResponses(List <WeekResponse> weekResponse, List <MoviesResponse> moviesResponse, List <HallsResponse> hallsResponse) { foreach (WeekResponse wr in weekResponse) { MoviesResponse mr = moviesResponse.First(item => item.id == wr.movieId); wr.movie = mr; HallsResponse hr = hallsResponse.First(item => item.id == wr.hallId); wr.hall = hr; wr.dateTime = DateTime.ParseExact(wr.date + " " + wr.time, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture); } return(weekResponse); }
public async Task <IActionResult> Index(string q = "", int page_limit = 10, int page = 1) { MoviesResponse list = new MoviesResponse(); list = await project.GetList(q, page_limit, page); list.pagecount = (int)Math.Ceiling((double)(list.total / (double)page_limit)); list.pagelimit = page_limit; list.page = page; return(View(list)); }
public void Should_be_able_to_map_from_an_enumerable_of_Movies_to_MoviesResponse( IEnumerable <Movie> movies, MoviesResponse response ) { var crime = new Genre("Crime"); var drama = new Genre("Drama"); var animation = new Genre("Animation"); var adventure = new Genre("Adventure"); var shawshank = new MovieBuilder() .WithDirector("Frank Darabont") .WithGenres(new[] { crime, drama }) .WithImdbId("tt0111161") .WithPlot("Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.") .WithRating(9.3m) .WithReleaseDate(new DateTime(1994, 10, 14)) .WithTitle("The Shawshank Redemption") .Build(); var wallE = new MovieBuilder() .WithDirector("Andrew Stanton") .WithGenres(new[] { animation, adventure, drama }) .WithImdbId("tt0910970") .WithPlot("In the distant future, a small waste collecting robot inadvertently embarks on a space journey that will ultimately decide the fate of mankind.") .WithRating(8.5m) .WithReleaseDate(new DateTime(2008, 06, 27)) .WithTitle("WALL·E") .Build(); "Given a enumerable of Movies in reverse title order" .Given(() => movies = new[] { wallE, shawshank }); "When mapping to a MoviesResponse" .When(() => response = movies.ToResponse()); "Should map the movies as dtos ordered by title" .Then(() => response.Movies.ShouldAllBeEquivalentTo(new[] { shawshank.ToDto(), wallE.ToDto() })); "Should map the movies distinct genres as dtos ordered by name" .Then(() => response.Genres.ShouldAllBeEquivalentTo(new[] { adventure.ToDto(), animation.ToDto(), crime.ToDto(), drama.ToDto(), })); }
public void Can_call_GetAsync_on_Movies_using_RestClientAsync() { var asyncClient = CreateAsyncRestClient(); MoviesResponse response = null; asyncClient.GetAsync <MoviesResponse>("movies", r => response = r, FailOnAsyncError); Thread.Sleep(1000); Assert.That(response, Is.Not.Null, "No response received"); Assert.That(response.Movies.EquivalentTo(ResetMoviesService.Top5Movies)); }
public IActionResult Get() { var movies = Movies.OrderByDescending(a => a.AverageRating).ThenBy(t => t.Title).Take(5); if (movies != null) { var moviesResponse = MoviesResponse.CreateResponse(movies); return(Ok(moviesResponse)); } return(NotFound()); }
public void Can_download_movies_in_Csv() { var asyncClient = new AsyncServiceClient { ContentType = MimeTypes.Csv, StreamSerializer = (r, o, s) => CsvSerializer.SerializeToStream(o, s), StreamDeserializer = CsvSerializer.DeserializeFromStream, }; MoviesResponse response = null; asyncClient.SendAsync <MoviesResponse>(HttpMethods.Get, ServiceClientBaseUri + "/movies", null, r => response = r, FailOnAsyncError); Thread.Sleep(1000); Assert.That(response, Is.Not.Null, "No response received"); }
public async Task <MoviesResponse> GetFilms() { MoviesResponse response = new MoviesResponse(); try { Debug.WriteLine("Get films"); var requestUrl = string.Format("{0}films/", _baseUrl); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var resultString = await client.GetStringAsync(requestUrl); response = JsonConvert.DeserializeObject <MoviesResponse>(resultString); return(response); } } catch { return(null); } return(response); }
public IActionResult Get(int userId) { var user = Users.Where(i => i.ID == userId).SingleOrDefault(); if (user == null) { return(NotFound("No user has been found for this id")); } var movies = Movies.OrderByDescending(a => a.UserRatings.Where(u => u.User.ID == userId).SingleOrDefault().Rating).ThenBy(t => t.Title).Take(5); if (movies != null) { var moviesResponse = MoviesResponse.CreateResponse(movies); return(Ok(moviesResponse)); } return(NotFound("No matching movie ratings were able to be found for this user")); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { AddApplicationBar(); if (!App.Context.DownloadThumbnails) { LstMovies.ItemTemplate = Application.Current.Resources["MovieItemTemplateFlat"] as DataTemplate; LstMovies.Style = Application.Current.Resources["ListLongListSelectorStyle"] as Style; } IsLoading = true; try { MoviesResponse movies = await App.Context.Connection.Xbmc.VideoLibrary.GetMoviesAsync(); if (movies.Movies == null || !movies.Movies.Any()) { MessageBox.Show(AppResources.Page_Movies_Message_No_Movie, AppResources.ApplicationTitle, MessageBoxButton.OK); if (NavigationService.CanGoBack) { NavigationService.GoBack(); } return; } Movies = movies.Movies.Select(s => new ExtendedVideoDetailsMovie(s, false)).OrderBy(m => m.Movie.Title).ToList(); } catch (Exception ex) { App.TrackException(ex); MessageBox.Show(AppResources.Global_Error_Message, AppResources.ApplicationTitle, MessageBoxButton.OK); } finally { IsLoading = false; } }
public IActionResult Get(string title = null, string yearOfRelease = null, string[] genres = null) { var movies = MathHelpers.RoundRatings(Movies); if (title == null && yearOfRelease == null && genres.Length == 0) { return(BadRequest("You must submit at least 1 search critera")); } IEnumerable <Movie> filteredMovies = null; if (title != null) { filteredMovies = movies.Where(x => x.Title.ToLower().Contains(title.ToLower())); } if (yearOfRelease != null) { filteredMovies = filteredMovies == null? movies.Where(x => x.YearOfRelease == yearOfRelease) : filteredMovies.Where(x => x.YearOfRelease == yearOfRelease); } if (genres.Length > 0) { filteredMovies = filteredMovies == null? movies.Where(x => !genres.Except(x.Genres).Any()) : filteredMovies.Where(x => !genres.Except(x.Genres).Any()); } if (filteredMovies != null) { var moviesResponse = MoviesResponse.CreateResponse(filteredMovies); return(Ok(moviesResponse)); } return(NotFound()); }
public async Task <MoviesResponse> FetchMovies(string movie) { try { using (HttpClient client = new HttpClient()) using (HttpResponseMessage response = await client.GetAsync( "https://api.themoviedb.org/3/search/company?api_key=319bb88e8f2caefe1a7e362f8e5d3445&query=" + movie + "&page=1").ConfigureAwait(true)) using (HttpContent content = response.Content) { string result = await content.ReadAsStringAsync().ConfigureAwait(true); MoviesResponse movies = JsonConvert.DeserializeObject <MoviesResponse>(result); return(movies); } } catch (Exception e) { Console.WriteLine(e); } return(null); }
public async Task <MoviesResponse> GetList(string q, int page_limit, int page) { q.Replace(" ", "%20"); MoviesResponse movies = new MoviesResponse(); var request = new HttpRequestMessage(HttpMethod.Get, //"https: //www.rottentomatoes.com/api/private/v1.0/movies/box_office"); "https://www.rottentomatoes.com/api/private/v1.0/movies.json?q='" + q + "'&page_limit=" + page_limit + "&page=" + page); request.Headers.Add("Accept", "application/vnd.github.v3+json"); request.Headers.Add("User-Agent", "HttpClientFactory-Sample"); //request.Headers.Add("User-Agent", "HttpClientFactory-Sample"); //request.Headers.Add("Accept", "*/*"); //request.Headers.Add("Accept-Encoding", "gzip, deflate, br"); //request.Headers.Add("Connection", "keep-alive"); var client = clientFactory.CreateClient(); var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { //using var responseStream = await response.Content.ReadAsStreamAsync(); using var responseStream = await response.Content.ReadAsStreamAsync(); movies = await JsonSerializer.DeserializeAsync <MoviesResponse>(responseStream); } else { //GetBranchesError = true; //movies = Array.Empty<List<Movie>>(); } return(movies); }
/// <summary> /// GET /movies /// GET /movies/genres/{Genre} /// </summary> public object Get(Movies request) { var response = new MoviesResponse { Movies = request.Genre.IsNullOrEmpty() ? Db.Select<Movie>() : Db.Select<Movie>("Genres LIKE {0}", "%" + request.Genre + "%") }; return response; }
public void Should_update_movie_and_use_existing_genre_if_genre_exists( IWebApiMovieRestContext context, UpdateMovieRequestHandler updateMovieRequestHandler, Genre alreadyExistingGenre, Movie newMovie, UpdateMovieRequest updateMovieRequest, MoviesResponse moviesResponse, Movie updatedMovie ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a UpdateMovieRequestHandler constructed with the context" .And(() => updateMovieRequestHandler = new UpdateMovieRequestHandler(context)); "And a new Movie that has been inserted into the database".And(() => { newMovie = new MovieBuilder().WithGenres(new[] { new Genre("new genre") }); using (var dbContext = new WebApiMovieRestContext()) { dbContext.Movies.Add(newMovie); dbContext.SaveChanges(); } }); "And a Genre that already exists in the database".And(() => { var alreadyExistingGenreName = new WebApiMovieRestInitializer() .SeedMovies().First() .Genres.First() .Name; using (var dbContext = new WebApiMovieRestContext()) { alreadyExistingGenre = dbContext.Genres.Single(genre => genre.Name == alreadyExistingGenreName); } }); "And a UpdateMovieRequest containing the id of the newly inserted Movie and genre that exists in the database". And(() => updateMovieRequest = new UpdateMovieRequestBuilder() .WithMovieId(newMovie.Id) .WithDirector("new director") .WithGenres(new[] { alreadyExistingGenre.Name }) .WithImdbId("newimdbid") .WithPlot("new plot") .WithRating(0.1m) .WithReleaseDate(new DateTime(2000, 01, 01)) .WithTitle("new title")); "After handling the UpdateMovieRequest" .When(() => moviesResponse = updateMovieRequestHandler.Handle(updateMovieRequest)); "And commiting the WebApiMovieRestContext" .When(() => context.Commit()); "And retrieving the updated Movie".When(() => { using (var dbContext = new WebApiMovieRestContext()) { updatedMovie = dbContext.Movies .Include(movie => movie.Genres) .SingleOrDefault(movie => movie.Id == newMovie.Id); } }); "Then the already existing Genre should have be used".Then(() => updatedMovie.Genres.Single().ShouldBeEquivalentTo(alreadyExistingGenre)); "And the new movie should have the same values as the request" .Then(() => updatedMovie.ShouldBeEquivalentTo(updateMovieRequest, o => o.ExcludingMissingProperties())); "And the new movie should have the same genre as the request" .Then(() => updatedMovie.Genres.Single().Name.Should().Be(updateMovieRequest.Genres[0])); "And the MovieResponse should be the newly updated Movie translated" .Then(() => moviesResponse.ShouldBeEquivalentTo(updatedMovie.Yield().ToResponse())); }
public async Task <MoviesResponse> GetListBySearch(string q) { MoviesResponse movies = new MoviesResponse(); return(movies); }