public async Task <ActionResult <AddBookResponse> > AddBook(AddBookRequest request) { var validator = new AddBookRequestValidator(); var validationResult = await validator.ValidateAsync(request); if (!validationResult.IsValid) { return(BadRequest(new BadRequestMessage(validationResult.Errors))); } var book = _mapper.Map <AddBookRequest, Book>(request); book.Id = Guid.NewGuid().ToString(); await _bookRepository.SaveBook(book); return(CreatedAtAction(nameof(GetBook), new GetBookRequest { Id = Guid.Parse(book.Id) }, new AddBookResponse(Guid.Parse(book.Id), StatusCodes.Status201Created))); }
public async Task add_book_validation_failed( string authorId, string genreId, string title, int year ) { var request = new AddBookRequest { AuthorId = authorId, BookTitle = title, GenreId = genreId, Year = year, }; var validator = new AddBookRequestValidator(); var validationResult = await validator.ValidateAsync(request); Assert.False(validationResult.IsValid); }