public async Task PutBookBorrows_200Ok() { var bookBorrow = new UpdateBookBorrowDto { IdBookBorrow = 1, IdBook = 1, IdUser = 1, DateFrom = DateTime.Now, DateTo = DateTime.Now.AddDays(2), Comments = "comment here" }; string json = JsonConvert.SerializeObject(bookBorrow); var buffer = System.Text.Encoding.UTF8.GetBytes(json); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/1", byteContent); httpResponse.EnsureSuccessStatusCode(); var content = await httpResponse.Content.ReadAsStringAsync(); var bookBorrowl = JsonConvert.DeserializeObject <IEnumerable <BookBorrow> >(content); Assert.True(bookBorrowl.ElementAt(0).IdBookBorrow == 1); }
public async Task UpdateBookBorrow_200Ok() { var updated = new UpdateBookBorrowDto { IdBookBorrow = 2, IdUser = 2, IdBook = 2, DateFrom = new DateTime(), DateTo = new DateTime(), Comments = "sample text" }; var serialized = JsonConvert.SerializeObject(updated); var content = new StringContent(serialized, Encoding.UTF8, "application/json"); var httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{updated.IdBook}", content); httpResponse.EnsureSuccessStatusCode(); var result = await httpResponse.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <UpdateBookBorrowDto>(result); Assert.True(response.IdUser == 2); Assert.True(response.IdBook == 2); }
public async Task <IActionResult> UpdateBookBorrow([FromBody] UpdateBookBorrowDto borrow) { RollbarLocator.RollbarInstance.Error(new Exception("Błąd z Rollbar")); await _bookBorrowRepository.ChangeBookBorrow(borrow); return(NoContent()); }
public async Task <IActionResult> UpdateBookBorrow([FromBody] UpdateBookBorrowDto borrow) { RollbarLocator.RollbarInstance.Error(new Exception("Błąd z Rollbar update bookborrow")); _logger.LogError("Wystąpił błąd przy updacie bookborrowsa"); await _bookBorrowRepository.ChangeBookBorrow(borrow); return(NoContent()); }
public async Task <bool> ChangeBookBorrow(UpdateBookBorrowDto borrow) { var borrowFromDb = await _context.BookBorrow.SingleOrDefaultAsync(x => x.IdBookBorrow == borrow.IdBookBorrow); if (borrowFromDb == null) { return(false); } borrowFromDb.IdBook = borrow.IdBook; borrowFromDb.IdUser = borrow.IdUser; borrowFromDb.Comments = borrow.Comments; borrowFromDb.BorrowDate = borrow.DateFrom; borrowFromDb.ReturnDate = borrow.DateTo; await _context.SaveChangesAsync(); return(true); }
public async Task PutBookBorrow_200Ok() { var toChangeBookBorrow = new UpdateBookBorrowDto { IdBookBorrow = 1, IdBook = 1, IdUser = 1, DateFrom = DateTime.Parse("10.10.2019"), DateTo = DateTime.Now }; string payload = JsonConvert.SerializeObject(toChangeBookBorrow); var content = new StringContent(payload, Encoding.UTF8, "application/json"); var httpResponse = await _client.PutAsync($"{_client.BaseAddress.AbsoluteUri}api/book-borrows/{toChangeBookBorrow.IdBookBorrow}", content); var responseContent = await httpResponse.Content.ReadAsStringAsync(); var response = JsonConvert.DeserializeObject <bool>(responseContent); Assert.True(response == true); }
public async Task <IActionResult> UpdateBookBorrow([FromBody] UpdateBookBorrowDto borrow) { await _bookBorrowRepository.ChangeBookBorrow(borrow); return(NoContent()); }
public async Task <IActionResult> UpdateBookBorrow([FromBody] UpdateBookBorrowDto borrow) { var res = await _bookBorrowRepository.ChangeBookBorrow(borrow); return(Ok(res)); }