public void Setup() { _bookService = new Mock <IBookService>(); _bookController = new BookController(_bookService.Object); _bookModelDTO = new BookModelDTO { Id = 2, NameOfAuthor = "Volodya", SureNameOfAuthor = "Khydzik", Title = "Sea" }; _bookModelDTOs = new List <BookModelDTO> { new BookModelDTO { Id = 2, NameOfAuthor = "Volodya", SureNameOfAuthor = "Khydzik", Title = "Sea" }, new BookModelDTO { Id = 2, NameOfAuthor = "Ura", SureNameOfAuthor = "Dub", Title = "Black" } }; BookId = 1; }
public async Task <IActionResult> GetBookById([FromRoute] string id) { var myBook = await _repository.GetByIdAsync <Book>( book => book.Id == id ); return(Ok(BookModelDTO.FromBook(myBook))); }
public async Task <BookModelDTO> UpdateBook([FromBody] BookModelDTO input) { var book = await _bookService.UpdateBookAsync(input); if (book == null) { throw new Exception("Book is not change!"); } return(book); }
public async Task <IActionResult> AddBook([FromBody] BookModelDTO model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var addedBook = await _repository.AddAsync <Book>(BookModelDTO.FromBookDTO(model)); return(Ok(BookModelDTO.FromBook(addedBook))); }
public async Task <IActionResult> GetBookByName([FromRoute] string name) { var myBook = await _repository.GetByIdAsync <Book>( book => book.Reviews, book => book.Name == name ); if (myBook == null) { return(BadRequest($"Book: {name} not found")); } return(Ok(BookModelDTO.FromBook(myBook))); }
public void Setup() { _bookRepository = new Mock <IBookRepository>(); _bookService = new BookService(_bookRepository.Object); _book = new Book { Id = 1, AuthorId = 1, Title = "Sea", Author = new Author { Id = 1, Name = "Volodya", SureName = "Khydzik" } }; _bookModelDTO = new BookModelDTO { Id = 1, NameOfAuthor = "Volodya", SureNameOfAuthor = "Khydzik", Title = "Sea1" }; _bookModelDTOs = new List <BookModelDTO> { new BookModelDTO { Id = 2, NameOfAuthor = "Volodya", SureNameOfAuthor = "Khydzik", Title = "Sea" }, new BookModelDTO { Id = 2, NameOfAuthor = "Ura", SureNameOfAuthor = "Dub", Title = "Black" } }; BookId = 1; }
public async Task <BookModelDTO> UpdateBookAsync(BookModelDTO input) { var book = await _bookRepository.GetAsync(u => u.Id == input.Id); if (book == null) { throw new Exception("Book is not found."); } book.Title = input.Title ?? book.Title; book.Author.Name = input.NameOfAuthor ?? book.Author.Name; book.Author.SureName = input.SureNameOfAuthor ?? book.Author.SureName; await _bookRepository.UpdateAsync(book); return(input); }
public async Task CreateAsync(BookModelDTO bookModel) { var book = await _bookRepository.GetAsync(u => u.Title == bookModel.Title); if (book != null) { throw new Exception("Such book exist!"); } var newBook = new Book { Title = bookModel.Title, Author = new Author { Name = bookModel.NameOfAuthor, SureName = bookModel.SureNameOfAuthor } }; await _bookRepository.InsertAsync(newBook); }
public async Task CanAddNewBook() { // arrange await SetToken(); var author = await Repository.AddAuthor(); var category = await Repository.GetCategory(); var model = new BookModelDTO() { Name = $"MyBook-{Guid.NewGuid().ToString()}", AuthorId = author.Id, CategoryId = category.Id }; // act var response = await Client.PostAsync($"/books/add?TenantKey={Constants.TENANT_KEY}", ContentHelper.GetStringContent(model)); // assert Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public async Task <IActionResult> CreateBook([FromBody] BookModelDTO input) { await _bookService.CreateAsync(input); return(Ok()); }