public async Task <ActionResult <WishlistBook> > PostWishlistBook(WishlistBook wishlistBook) { int user_id = wishlistBook.wishlist_id; Wishlist tmp = await _context.Wishlists .Where(w => w.user_id == user_id && w.primary == true ) .FirstOrDefaultAsync(); if (tmp != null) { wishlistBook.wishlist_id = tmp.id; _context.WishlistsBooks.Add(wishlistBook); } try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (WishlistBookExists(wishlistBook.wishlist_id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetWishlistBook", new { id = wishlistBook.wishlist_id }, wishlistBook)); }
public async Task AddBookToWishlistAsyncTest_NullWishlistBook_ThrowsNullReferenceException() { //arrange _wishlistRepositoryMock.WithValidInsert(); WishlistBook wishlistBook = null; //act var result = await _sut.AddBookToWishlistAsync(wishlistBook); //assert _wishlistRepositoryMock.Verify(x => x.InsertAsync(It.IsAny <WishlistBook>()), Times.Never); Assert.IsFalse(result); }
public async Task <bool> RemoveWishlistBookAsync(WishlistBook item) { if (item == null) { throw new NullReferenceException("Wishlist book cannot be null"); } if (item.Id < 0) { throw new Exception("Wishlist book id cannot be invalid"); } return(await _repository.DeleteAsync(item)); }
public async Task <bool> UpdateWishlistBookAsync(WishlistBook item) { if (item == null) { throw new NullReferenceException("Wishlist book cannot be null"); } if (item.Id < 0) { throw new Exception("Wishlist book Id cannot be less than 0"); } return(await _repository.UpdateAsync(item)); }
public async Task <bool> InsertOrUpdateAsync(WishlistBook item) { if (item == null) { throw new NullReferenceException("WishlistBook cannot be null"); } var wishlistBookMap = _mapper.Map(item); if (wishlistBookMap == null) { throw new NullReferenceException("WishlistBookMap cannot be null"); } return(await _access.InsertOrUpdateAsync(wishlistBookMap)); }
public async Task <bool> InsertAsync(WishlistBook item) { if (item == null) { throw new NullReferenceException("WishlistBook cannot be null"); } if (item.Id < 0) { throw new Exception("WishlistBook id cannot be negative"); } var wishlistBookMap = _mapper.Map(item); if (item == null) { throw new NullReferenceException("WishlistBookMap cannot be null"); } return(await _access.InsertOneAsync(wishlistBookMap as IWishlistMap)); }
public async Task <IActionResult> PutWishlistBook(int id, WishlistBook wishlistBook) { _context.Entry(wishlistBook).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WishlistBookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public static Mock <IMapper <WishlistBook> > WithUnmap(this Mock <IMapper <WishlistBook> > mock, WishlistBook wishlistBook) { mock.Setup(m => m.Unmap(It.IsAny <WishlistMap>())).Returns(wishlistBook); return(mock); }