public void Should_return_all_genres_translated_to_a_genres_response( IWebApiMovieRestContext context, GetGenresRequestHandler getGenresRequestHandler, GetGenresRequest getGenreRequest, GenresResponse genresResponse ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a GetGenresRequestHandler constructed with the context" .And(() => getGenresRequestHandler = new GetGenresRequestHandler(context)); "And a GetGenresRequest". And(() => getGenreRequest = new GetGenresRequest()); "After handling the GetGenresRequest" .When(() => genresResponse = getGenresRequestHandler.Handle(getGenreRequest)); "The GenresResponse should be all existing Genres in the database translated".Then(() => { var existingGenresTranslated = new WebApiMovieRestInitializer() .SeedMovies() .SelectMany(movie => movie.Genres) .Distinct() .ToResponse(); genresResponse.ShouldBeEquivalentTo( existingGenresTranslated, // do not compare ids o => o.Excluding(x => x.PropertyInfo.Name == "Id") ); }); }
public void Should_return_genre_translated_to_a_genres_response_when_genre_is_found( IWebApiMovieRestContext context, GetGenreRequestHandler getGenreRequestHandler, Genre newGenre, GetGenreRequest getGenreRequest, GenresResponse genresResponse ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a GetGenreRequestHandler constructed with the context" .And(() => getGenreRequestHandler = new GetGenreRequestHandler(context)); "And a new Genre that has been inserted into the database" .And(() => newGenre = Db.InsertGenre(new Genre("a new genre"))); "And a GetGenreRequest containing the id of the newly inserted Genre". And(() => getGenreRequest = new GetGenreRequest() { GenreId = newGenre.Id }); "After handling the GetGenreRequest" .When(() => genresResponse = getGenreRequestHandler.Handle(getGenreRequest)); "The GenresResponse should be the newly inserted Genre translated" .Then(() => genresResponse.ShouldBeEquivalentTo(newGenre.Yield().ToResponse())); }
public void Should_be_able_to_map_from_an_enumerable_of_Genres_to_GenresResponse( IEnumerable <Genre> genres, GenresResponse response ) { var drama = new Genre("Drama"); var crime = new Genre("Crime"); "Given a enumerable of Genres in reverse name order" .Given(() => genres = new[] { drama, crime }); "When mapping to a GenresResponse" .When(() => response = genres.ToResponse()); "Should map the genres as dtos ordered by name" .Then(() => response.Genres.ShouldAllBeEquivalentTo(new[] { crime.ToDto(), drama.ToDto() })); }
public GenresResponse Get() { var genresResponse = new GenresResponse { Genres = new List <Genre>() }; try { genresResponse.Genres = _genreService.GetGenres(); genresResponse.ResponseStatusCode = HttpStatusCode.OK; return(genresResponse); } catch (ServiceApiException saex) { LogError(saex); genresResponse.ResponseStatusCode = saex.StatusCode; return(genresResponse); } catch (Exception ex) { LogError(ex); genresResponse.ResponseStatusCode = HttpStatusCode.InternalServerError; return(genresResponse); } }
private List <string> Map(GenresResponse GenresResponse) => GenresResponse?.Genres.ToList() ?? new List <string>();