public void Should_throw_exception_when_genre_is_not_found( IWebApiMovieRestContext context, GetGenreRequestHandler getGenreRequestHandler, GetGenreRequest getGenreRequest, Exception exception ) { "Given a WebApiMovieRestContext" .Given(() => context = new WebApiMovieRestContext().AutoRollback()); "And a GetGenreRequestHandler constructed with the context" .And(() => getGenreRequestHandler = new GetGenreRequestHandler(context)); "And a GetGenreRequest containing the id of a Genre that does not exist". And(() => getGenreRequest = new GetGenreRequest() { GenreId = Guid.Empty }); "When handling the GetGenreRequest" .When(() => exception = Record.Exception(() => getGenreRequestHandler.Handle(getGenreRequest))); "A ResourceNotFoundException should be thrown" .Then(() => exception.Should().BeOfType <ResourceNotFoundException>()); "With a message indicating the id of the Genre that was not found" .Then(() => exception.Message.Should().Be("Genre[Id=00000000-0000-0000-0000-000000000000] could not be found")); }
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 async Task <IEnumerable <ItemResponse> > GetItemByGenreIdAsync(GetGenreRequest request) { if (request?.Id == null) { throw new ArgumentNullException(); } var result = await _itemRepository.GetItemByGenreIdAsync(request.Id); return(result.Select(_itemMapper.Map)); }
public GetGenreResponse GetGenre(GetGenreRequest request) { var response = new GetGenreResponse(); var genre = _genreRepository.FindBy(request.Id); response.Genre = genre.ConvertToGenreView(); return(response); }
public async Task <GenreResponse> GetGenreAsync(GetGenreRequest request) { if (request?.Id == null) { throw new ArgumentNullException(); } var result = await _genreRepository.GetAsync(request.Id); return(result == null ? null : _genreMapper.Map(result)); }
public async Task <IEnumerable <VideoResponse> > GetVideosByGenreIdAsync(GetGenreRequest request) { if (request?.Id == null) { throw new ArgumentNullException(); } IEnumerable <Video> result = await _videoRepository.GetVideosByGenreIdAsync(request.Id); return(_mapper.Map <IEnumerable <VideoResponse> >(result)); }
public IHttpActionResult Get(int id) { var loggedUserId = HttpContext.Current.GetOwinContext().GetUserId(); var request = new GetGenreRequest() { RequestToken = Guid.NewGuid(), UserId = loggedUserId, Id = id }; var genreResponse = _genreService.GetGenre(request); if (!genreResponse.Success) { return(BadRequest(genreResponse.Message)); } return(Ok(genreResponse.Genre.MapToViewModel())); }
/// <summary> /// Handling get request and response /// </summary> /// <param name="request">Messaging.Genres</param> /// <returns>Messaging.Genres</returns> public GetGenreResponse GetGenre(GetGenreRequest request) { var response = new GetGenreResponse() { Request = request, ResponseToken = Guid.NewGuid() }; try { response.Genre = _repository.FindAll(request.Id).MapToView(); response.Success = true; } catch (Exception ex) { response.Message = ex.Message; response.Success = false; } return(response); }
public async Task <IEnumerable <ItemResponse> > GetItemsByGenreIdAsync(GetGenreRequest request) { var result = await _itemRepository.GetItemsByArtistIdAsync(request.Id); return(result.Select(_itemMapper.Map)); }
public async Task <GenreResponse> GetGenreAsync(GetGenreRequest request) { var result = await _genreRepository.GetAsync(request.Id); return(result == null ? null : _genreMapper.Map(result)); }